Computer Science, asked by kaurgurpreet2067, 6 months ago

01. Write a program to input 4 numbers using
function argument and find the greatest
and smallest of the four numbers.​

Answers

Answered by shivaramcvm
1

There is a way as pointed out by Mukesh Kumar

#include<stdio.h>  

#include<stdlib.h>  

int main()  

{  

int a,b,c,d,largest;  

 

//Getting the numbers  

printf("Enter the numbers out of which you have to find the greatest\n ");  

scanf("%d %d %d %d",&a,&b,&c,&d);  

 

//Actual Computation  

largest= (a>b)?(a>c)?(a>d)?a:d:(c>d)?c:d:(b>c)?(b>d)?b:d:(c>d)?c:d;  

printf("The largest number is %d",largest);  

return 0;  

}  

Another way is with the help of switch statement but it has a catch- that you need to specify the upper limit of the numbers that you are going to input. Here is a C code-

#include<stdio.h>  

#include<stdlib.h>  

#define MAX_LIMIT 10000  

int main()  

{  

int a,b,c,d,largest;  

 

//Getting the numbers  

printf("Enter the numbers out of which you have to find the greatest\n ");  

scanf("%d %d %d %d",&a,&b,&c,&d);  

 

//Actual Computation  

   for( int i=MAX_LIMIT; i>= -(MAX_LIMIT); i--)  

   {  

        switch(a-i)  

        {  

           case 0:printf("%d is largest number\n",a);  

           exit(-1);  

        }  

       switch(b-i)  

        {  

           case 0:printf("%d is largest number\n",b);  

           exit(-1);  

        }  

       switch(c-i)  

        {  

           case 0:printf("%d is largest number\n",c);  

           exit(-1);  

        }  

       switch(d-i)  

        {  

           case 0:printf("%d is largest number\n",d);  

           exit(-1);  

        }  

   }  

return 0;  

}  

pls mark as brainlist...

Answered by anindyaadhikari13
2

Question:-

Write a program to input 4 numbers using function argument and find the greatest and fue smallest of the four number.

Program:-

In Java

class MaxMin

{

static void main(int a, int b, int c, int d)

{

int max=Math.max(a, Math.max(b, Math.max(c, d)));

int min=Math.min(a, Math.min(b, Math.min(c, d)));

System.out.println("Max: "+max);

System.out.println("Min: "+min);

}

}

Similar questions