Thanks for looking at my thread. I have successfully made a code that with search for mutliplies.
But I am now trying to modify it so that I dont have to tell it which numbers to search for. I would like it to just output how many of each number there is.
Would changing the code so it says that it tries out every single number away, so would using a nested loop with a counter to add one to the value of the number searched for work?
Here is my code for the linear search for number to help anyone out. Really appreciate anyone who has even looked at my thread let alone replied. Thanks.
Code:
#include<stdio.h>
int main(void)
{
int array[100], search, c, n, count = 0;
printf("Enter the number of elements in array\n");
scanf("%d",&n);
printf("Enter %d numbers\n", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d",&array[c]);
printf("Enter the number to search\n");
scanf("%d",&search);
for ( c = 0 ; c < n ; c++ )
{
if ( array[c] == search )
{
printf("%d is present at location %d.\n", search, c+1);
count++;
}
}
if ( count == 0 )
printf("%d is not present in array.\n", search);
else
printf("%d is present %d times in array.\n", search, count);
return 0;
}