Popular Posts

29.Write a program to find the largest value from two using for loop .

29.Write a program to find the largest value from two using for loop .

#include
#include
int main()
{
clrscr();
int a[2];
cout<<"Enter two numbers: "; int i; for(i=0;i<2;i++) { cin>>a[i];
}
int max=a[2];
for(i=1;i<2;i++) { if(a[i]>max)
max=a[i];
}
cout<<"Largest number= "< getch();
return 0;
}

Output:

Enter two numbers: 24
20
Largest number= 24

No comments: