WAP to Find Greatest Digit in C++

WAP to Greatest Digit in C++ for 3 numbers:-

#include<iostream>
using namespace std;
int main()
{
int a,b,c,g;
cout<<"ENTER THREE NUMBERS\n";
cin>>a>>b>>c;
    g=a;
 
    if(b>g)
    {
    g=b;
}
if(c>g)
{
g=c;
}
cout<<"Greatest number is:- "<<g;
}

INPUT:-


5

85

225


OUTPUT:-

Output Console


Greatest number is:- 225


WAP to Greatest Digit in C++ for n numbers:-

#include<iostream>
using namespace std;
int main()
{
int n,g,i;
cout<<"Enter total no. of Elements"<<endl;
cin>>n;
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
g=a[0];
for(i=1;i<n;i++)
{
if(a[i]>g)
{
g=a[i];
}
}
cout<<"Greatest Digit out of these "<<n<<" Elements:-"<<g;
}

INPUT:-
5
95
45
65
101
25


OUTPUT:-





Output Console

Greatest Digit out of these 5 Elements:-101








Previous Post
Next Post
Related Posts

0 comments: