To get user input you must use the scanf() function. Here is an example, where it asks for three separate numbers.
#include <stdio.h>
int main(void) {
int one, two, three;
printf("Enter first number: ");
scanf("%d", &one);
printf("Enter second number: ");
scanf("%d", &two);
printf("Enter third number: ");
scanf("%d", &three);
printf("one: %d, two: %d, three: %d\n", one, two, three);
return 0;
}
Will produce the following:
Enter first number: 1
Enter second number: 2
Enter third number: 3
one: 1, two: 2, three: 3
Here is another way to use scanf, but the user must be more specific about how they answer the prompt.
#include <stdio.h>
int main(void) {
int one, two, three;
printf("Enter three numbers separated by a comma: ");
scanf("%d,%d,%d", &one, &two, &three);
printf("one: %d, two: %d, three: %d\n", one, two, three);
return 0;
}
Will produce the following:
Enter three numbers separated by a comma: 1,2,3
one: 1, two: 2, three: 3
UPDATE: Because you posted code that shows you know how scanf works.
To search through an array you must use a for loop.
#include <stdio.h>
int main(void) {
float n = 100;
int numbers[] = {5, 10, 20, 50, 100, 200, 500};
int i;
for (i = 0; i < 7; i++) {
if (n == numbers[i]) {
printf("Matching index for %f at %d\n", n, i);
}
}
return 0;
}
char.