#include<stdio.h>
#include<conio.h>
int main()
{
int i,num,search,flag,arr[10];
clrscr();
printf("Enter the total number of input: \n");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("Enter the number %d \n",i+1);
scanf("%d",&arr[i]);
}
printf("Enter the number to search \n");
scanf("%d",&search);
for(i=0;i<num;i++)
{
if(arr[i] == search)
{
printf("The given number %d is located at position %d \n",search, i+1);
flag = 1;
break;
}
}
if(flag == 0)
printf("Sorry, the given number %d is not present in the array \n",search);
getch();
return 0;
}
To Compile Press Alt+f9
To Run Press Ctrl+f9
Output:
#include<conio.h>
int main()
{
int i,num,search,flag,arr[10];
clrscr();
printf("Enter the total number of input: \n");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("Enter the number %d \n",i+1);
scanf("%d",&arr[i]);
}
printf("Enter the number to search \n");
scanf("%d",&search);
for(i=0;i<num;i++)
{
if(arr[i] == search)
{
printf("The given number %d is located at position %d \n",search, i+1);
flag = 1;
break;
}
}
if(flag == 0)
printf("Sorry, the given number %d is not present in the array \n",search);
getch();
return 0;
}
To Compile Press Alt+f9
To Run Press Ctrl+f9
Output:
No comments:
Post a Comment