verificarea aparitiei unui numar in sir

Fie a1,a2,a3….an un si de numere si x un nr real dat. Sa se verifice daca x se afla printre numerele date

#include <iostream>

using namespace std;

int main()
{

int i,n,gasit=0;;
float a,x;
cout<<“n=”;cin>>n;
cout<<“x=”;cin>>x;
for(i=1;i<=n;i++)
{
cout<<“a=”;cin>>a;
if(a==x) gasit=1;
}
if (gasit==1) cout<<“numarul “<<x<<” se gaseste in sir”;
else cout<<“numarul “<<x<<” nu se gaseste in sir”;

return 0;
}

Leave a Comment

%d bloggers like this: