IF CONDITION PROGRAMS SET 4

Question: 16
C program to take input for three number check and print largest number? (Method :1)
Sol:

#include <stdio.h>
 int main()
 {
     int a,b,c;
     printf("Enter 3 nos ");
     scanf("%d %d %d",&a,&b,&c);
     if(a>b && a>c)
         printf("max no = %d",a);
     else
         if(b>c)
             printf("max no = %d",b);
         else
             printf("max no = %d",c);
 return 0;
 }

Output:

Enter 3 nos 25
63
98
max no = 98

Question:17
C program to take input for three number check and print largest number? (Method :2)
Sol:

#include <stdio.h>
 int main()
 {
     int a,b,c,m;
     printf("Enter 3 nos ");
     scanf("%d %d %d",&a,&b,&c);
     if(a>b && a>c)
         m=a;
     else
         if(b>c)
             m=b;
         else
             m=c;
     printf("max no = %d",m);
 return 0;
 }

Output:

Enter 3 nos 14
52
67
max no = 67

Question:18
C program to take input for three number check and print largest number? (Method :3)
Sol:

#include <stdio.h>
 int main()
 {
     int a,b,c,m;
     printf("Enter 3 nos ");
     scanf("%d %d %d",&a,&b,&c);
     m=a;
     if(b>m)
         m=b;
     if(c>m)
         m=c;
     printf("max no = %d",m);
 return 0;
 }

Output:

Enter 3 nos 25
98
75
max no = 98

Question:19
C program to take input for three number check and print largest number? (Method :4)
Sol:

#include <stdio.h>
 int main()
 {
     int a,b,c,m;
     printf("Enter 3 nos ");
     scanf("%d %d %d",&a,&b,&c);
     m=(a>b && a>c)?a:(b>c)?b:c;
 printf("max no = %d",m);
 return 0;
 }

Output:

Enter 3 nos 85
65
37
max no = 85

Question:20
C program to take input for three number check and print lowest number? (Method:1)
Sol:

#include <stdio.h>
 int main()
 {
     int a,b,c;
     printf("Enter 3 nos ");
     scanf("%d %d %d",&a,&b,&c);
     if(a<b && a<c)
         printf("Min no  = %d",a);
     else
         if(b<c)
         printf("Min no = %d",b);
     else
         printf("Min no = %d",c);
 return 0;
 }

Output:

Enter 3 nos 25
63
54
Min no = 25

C Language Programming Tutorial

C Language Tutorial Home     Introduction to C Language     Tokens     If Condition      goto statement and Labelname     Switch Statements     For loop     While Loop     Do while loop     break and continue     Functions     Recursion     Inbuild Functions     Storage Classes     Preprocessor     Arrays     Pointers     Structures and Unions     File Handling     Projects