#include <iostream.h>
#include <conio.h>
int main(void)
{
int nilai[10]={20,40,100,80,10,60,50,90,30,70};
int i;
cout<<"Enter the number you want to find (from 10 to 100) : ";
int key;
cin>>key;
int flag = 0; //sent flag to off
for(i=0; i<10; i++)
{
if (nilai[i]==key) //if match is found
{
flag=1; //turn flag on
break; //break out of for loop
}
}
if (flag)
{
cout<<"Your number is at subscript position "<<i<<"\n";
}
else
{
cout<<"Sorry I coud'nt find your number in this nilai."<<endl<<endl;
}
getch();
getch();
return 0;
}
#include <conio.h>
int main(void)
{
int nilai[10]={20,40,100,80,10,60,50,90,30,70};
int i;
cout<<"Enter the number you want to find (from 10 to 100) : ";
int key;
cin>>key;
int flag = 0; //sent flag to off
for(i=0; i<10; i++)
{
if (nilai[i]==key) //if match is found
{
flag=1; //turn flag on
break; //break out of for loop
}
}
if (flag)
{
cout<<"Your number is at subscript position "<<i<<"\n";
}
else
{
cout<<"Sorry I coud'nt find your number in this nilai."<<endl<<endl;
}
getch();
getch();
return 0;
}
int nilai[10]={20,40,100,80,10,60,50,90,30,70} merupakan data permanen yang ada dalam koding, jadi dapat diganti sesuai kebutuhan tugas agan sista,,</div>
0 komentar:
Posting Komentar