Let Us C (Chapter 8 : Arrays) : Program-1
(a) Twenty-five numbers are entered from the keyboard into an array. The number to be searched is entered through the keyboard by the user. Write a program to find if the number to be searched is present in the array and if it is present, display the number of times it appears in the array.
// Let Us C (Chapter 8 : Arrays) : Program-1
/* Twenty-five numbers are entered from the keyboard into an array. The number to be searched is entered through
the keyboard by the user. Write a program to find if the number to be searched is present in the array and if it
is present, display the number of times it appears in the array */
#include<stdio.h>
int arr[25],i,num,j=0,count=0;
void main()
{
clrscr();
printf("Program to find a number out of an array\n");
printf("Enter 25 No.s separated by space\n");
for(i=0;i<25;i++)
scanf("%d",&arr[i]);
printf("Enter a No. : ");
scanf("%d",&num);
while(j<25)
{
if(arr[j]==num)
count++;
j++;
}
if(count==0)
printf("Number %d is not in the list",num);
else
printf("Number %d appears %d times in the list",num,count);
}
OUTPUT
Comments
Post a Comment