HI all, this is a prgram to search a number in an array.
Please point me out errors in this Program and help
me how to declare n number of arrays instead of a[40].
/* TO SEARCH A NUMBER IN AN ARRAY*/
#include<stdio.h>
main()
{
int a[40],m,n,j=0;
int i;
clrscr();
printf("Enter the Array size : ");
scanf("%d",&m);
for(i=0;i<m;i++)
{
printf("Enter the array element a[%d] :",i);
scanf("%d",&a[i]);
}
printf("\nEnter the number to be Searched in the Array : ");
scanf("%d",&n);
for(i=0;i<m;i++)
if(a[i]==n)
j=j+1;
printf("\nThe number %d is repeated %d times...",n,j);
getch();
}
[b]Output:[/b][u]
Enter the Array size : 5
Enter the array element a[0] :2
Enter the array element a[1] :4
Enter the array element a[2] :5
Enter the array element a[3] :2
Enter the array element a[4] :1
Enter the number to be Searched in the Array : 2
The number 2 is repeated 2 times...
This post has been edited by jokertin92: 14 May 2009 - 02:38 AM

New Topic/Question
Reply




MultiQuote




|