Showing posts with label Exercise 9. Show all posts
Showing posts with label Exercise 9. Show all posts

Sunday, 23 April 2023

Exercise 9-To demonstrate use of 1-D arrays and functions.

SET A
1. Write a program to accept n numbers in the range of 1 to 25 and count the frequency of
occurrence of each number.

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10],n,cnt[25],c=0,i,j;
 clrscr();
 printf("\nEnter number:");
 scanf("%d",&n);
 printf("\n%d numbers between 1 t0 25:",n);
 for(i=0;i<n;i++)

     scanf("%d",&a[i]);
 for(i=0;i<25;i++)
     cnt[i]=0;
 for(i=0;i<n;i++)
    {
     for(j=0;j<25;j++)
{
if(a[i]==j)
    cnt[j]=cnt[j]+1;
}

    }
 for(i=0;i<25;i++)
    {
     if(cnt[i]>0)
       printf("\n %d occurenc is %d",i,cnt[i]);
    }
 getch();
}

OUTPUT:

Enter number:7                                                                 
                                                                               
7 numbers between 1 t0 25:                                                     
1                                                                             
2                                                                             
3                                                                             
3
2                                                                             
1                                                                             
5                                                                             
                                                                               
 1 occurenc is 2                                                               
 2 occurenc is 2                                                               
 3 occurenc is 2                                                               
 5 occurenc is 1                                                               

Questions

  Exercise 1 Set A . Apply all the three program development steps for the following examples.  1. Accept dimensions of a cylinder and p...