C++ Program To locate a no. in the list

//To locate a number in a list
#include <iostream>
using namespace std;
int main()
{	
	int i,n;
	double x;
	cout<<"Enter the size of the list"<<endl;
	cin>>n;
	cout<<"Enter the elements of the list\n";
	double a[n];
	for (i=0;i<n;i++)
	{
	cin>>a[i];
	}
	cout<<"Which no. do you wish to find?\n";
	cin>>x;
	for(i=0;i<n;i++)
	{
		if (a[i]==x)
		{
		cout<<"The no. is at "<<i<<"th position in the list.\n";
		break;
		}
		if(i==n-1)
		cout<<"Sorry, the no. can't be found\n";
	}
	return 0;
	
}

I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.



Leave a Reply

Your email address will not be published. Required fields are marked *