7-3 Find whole number fractions 10

This question requires finding a given X from the input N integers. If found, output the position of X (counting from 0); if not found, output "Not Found".

Input format:

The input is given in the first line as two positive integers N (≤20) and X, and in the second line as N integers. The numbers cannot exceed long integer types and are separated by spaces.

Output format:

Prints the position of the X, or "Not Found", on a line.

Input example 1:

5 7
3 5 7 1 9

Output sample 1:

2

Input example 2:

5 7
3 5 8 1 9

Output sample 2:

Not Found

Code length limit

16 KB

time limit

400 ms

memory limit

64 MB

#include<stdio.h>
int main() {
	int n,x,i=0;
	int arr[20];
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&arr[i]);
	}
	int flag=0;
	for(i=0;i<n;i++){
		if(arr[i]==x){
			printf("%d",i);
			flag=1;
		}
	}
	if(flag==0){
		printf("Not Found");
	} 
	return 0;
}

Guess you like

Origin blog.csdn.net/Androidandios/article/details/134539763