Credits

Saturday, February 21, 2009

Single Dimensional Array

Arrays are complex data structures in any programming language.

The program below searches a number from a given list and count its occurence.



[+/-] show/hide




#include stdio.h /* enclose this with <> */
main()
{
int number[10],x,search,occurence=0;

printf("Input 10 numbers :");
for (x=0;x<10;x++)
{ scanf("%d",&number[x]);}

printf("input a number to search:" );
scanf("%d",&search);

for (x=0;x<10;x++)
{ if (search==number[x])
occurence++;
}

if (occurence==0)
printf("YOur searched number is not in the input list.");
else
printf("There are %d of your searched number %d.",occurence,search);
getch();
}

You can rewrite this in C++.

AddThis