If Condition Programs Set 5

Question:21
C program to take input for three numbers, check and print the lowest 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("Min no = %d",m);
return 0;
}```

Output:

Enter 3 nos 25
63
4
Min no = 4

Question:22
C program to take input for three number, check and print the lowest 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("Min no = %d",m);
return 0;
}```

Output:

Enter 3 nos 95
68
78
Min no = 68

Question:23
C program to take input for three numbers, check and print the lowest 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("Min no = %d",m);
return 0;
}```

Output:

Enter 3 nos 42
57
8
Min no = 8

Question:24
Write a C program to take input for three number check and print the following;
(i). Largest no
(ii). Lowest no
(iii). Difference between largest and lowest number
Sol:

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

Output:

Enter 3 nos 25
96
3
Max no = 96 Min no = 3 Diff = 93

Question:25
C program to take input for a two-digit number and print sum of the digits?
Sol:

```#include <stdio.h>
int main()
{
int n,d1,d2,s;
printf("Enter a 2 digit no ");
scanf("%d",&n);
if(n>=10 && n<=99)
{
d1=n%10;
n=n/10;
d2=n%10;
s=d1+d2;
printf("Sum of digits = %d",s);
}
else
printf("Number is not a 2 digit no");
return 0;
}```

Output:

case:1
Enter a 2 digit no 369
Number is not a 2 digit no

case:2
Enter a 2 digit no 25
Sum of digits = 7

Important Pages