In: Computer Science
PROGRAM IS DONE WITH C++ LANGUAGE.
IT IS TESTED IN DEV-C++ 5.11 SOFTWARE AND IS GIVING CORRECT OUTPUT.
PROGRAM IS DONE IN TWO WAYS
PROGRAM 1. TAKE INDIVIDUAL 4 DIGITS FROM USER AND FIND MAX AND MIN FROM THEM.
PROGRAM 2. TAKE 4 DIGITS IN NUMBER FORMAT, FROM USER THEN FIND THE MAX AND MIN DIGITS FROM THEM.
PROGRAM 1
#include<iostream>
using namespace std;
int main()
{
int dig[4],i;
int max=0,min;
/* enter 4 digits */
cout<<"enter four digits" <<endl;
for(i=0;i<4;i++)
{
cin>>dig[i];
}
/* calculate max value */
for(i=0;i<4;i++)
{
if(dig[i]>max)
{
max=dig[i];
}
}
min=dig[0];
/* calculate min value */
for(i=0;i<4;i++)
{
if(min>dig[i])
{
min=dig[i];
}
}
/* print max and min value */
cout<<endl<<"the biggest is "
<<max;
cout<<endl<<"the smallest is
"<<min;
return 0;
}
SCREEN SHOT
OUTPUT
PROGRAM 2
#include<iostream>
using namespace std;
int main()
{
int dig[4],i,n;
int max=0,min;
i=0;
/* enter 4 digit number */
cout<<"enter a number of 4 digits :";
cin>>n;
/* while loop will run until n is zero */
while(n!=0)
{
/* take digits in array */
dig[i]= n%10;
n=n/10;
i++;
}
/* calculate max value */
for(i=0;i<4;i++)
{
if(dig[i]>max)
{
max=dig[i];
}
}
min=dig[0];
/* calculate min value */
for(i=0;i<4;i++)
{
if(min>dig[i])
{
min=dig[i];
}
}
/* print max and min value */
cout<<endl<<"the biggest is "
<<max;
cout<<endl<<"the smallest is
"<<min;
return 0;
}
SCREEN SHOT
OUTPUT