#include<stdio.h>
#include<conio.h>
int main()
{
int list[100], n,i,x,p;
printf("Enter the size of the list\n");
scanf("%d",&n);
printf("Enter the element\n");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;
printf("Enter the element to search\n ");
scanf("%d",&x);
for(i=-1;i<n;i++)
{
if(list[i]==x)
p=i;
}
if(p>=0)
printf("position of element %d is %d\n",x,p);
else
printf("try again");
getch();
return 0;
}
Enter the size of the list
3
Enter the element
12
13
45
Enter the element to search
45
position of element 45 is 2
#include<conio.h>
int main()
{
int list[100], n,i,x,p;
printf("Enter the size of the list\n");
scanf("%d",&n);
printf("Enter the element\n");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
p=0;
printf("Enter the element to search\n ");
scanf("%d",&x);
for(i=-1;i<n;i++)
{
if(list[i]==x)
p=i;
}
if(p>=0)
printf("position of element %d is %d\n",x,p);
else
printf("try again");
getch();
return 0;
}
Enter the size of the list
3
Enter the element
12
13
45
Enter the element to search
45
position of element 45 is 2
Try this:
ReplyDeleteEnter the size of the list
3
Enter the element
23
23
23
Enter the element to search
23
position of element 23 is 2
What is this........??????????
position of element 23 is 0,1 also...
#include
ReplyDelete#include
int main()
{
int a[100];
int n=0;
printf("enter the no of element:");
scanf("%d",&n);
printf("enter %d element in the array\n",n);
int i;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int s=0,found=0;
printf("enter the element to searched:");
scanf("%d",&s);
int pos=0;
for(i=0;i<n;i++)
if(a[i]==s)
{
pos=i+1;
++found;
}
if(found)
printf("\nelement is found at position %d",pos);
else
printf("\n element is not found");
getch();
return 0;
}
iske me to 2 bh dikha rha hai rohit par tmhare me to aise me 0 dikha rha h..... so first correct ur own program.....
ReplyDelete