+1 vote
in Class 11 by kratos

Write a C++ program to find the position of a given number in an array.

1 Answer

+6 votes
by kratos
 
Best answer

include

void main()

{

int a[100],n,i,position = -1,ele;

cout<<"Enter the size";

cin>>n;

cout <<"Enter the values";

for (i=0;i<n;i++)

cin>>a[i];

cout<<"Now,Enter the number to find its position";

cin>> ele;

for(i=0;i<n;i++)

If(a[i] = = else)

Position = i;

if(position>=0)

cout<<"The position of the number is "<<position<<end1;

else

cout<<"The number is not found"<<end1;

...