# Operators in C | conditional operator 2

Question:5
C program to take input for a number, if the number is <=10 calculate and print its cube otherwise print its square?
Sol:

```#include<stdio.h>
int main()
{
int a,b;
printf("Enter any no ");
scanf("%d",&a);
b=a<=10?a*a*a:a*a;
printf("Result = %d",b);
return(0);
}```
```/* Output */
Enter any no 5
Result = 125

Enter any no 12
Result = 144```

Question:6
C program to take input for a number, if the number is <=10 calculate and print its cube otherwise print its square (Without using a variable)?
Sol:

```#include<stdio.h>
int main()
{
int a;
printf("Enter any no ");
scanf("%d",&a);
a<=10?printf("Cube = %d",a*a*a):printf("Square = %d",a*a);
return(0);
}```
```/* Output */
Enter any no 6
Cube = 216

Enter any no 12
Square = 144```

Question:7
C program to take input for 3 numbers, check and print the largest number?
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 36
85
95
Max no = 95
```

Question:8
C program to take input for 3 numbers, check and print the smallest number?
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 75
84
25
Min no = 25
```

Important Pages