Professional Documents
Culture Documents
PIC Expt 2
PIC Expt 2
Grade: AA / AB / BB / BC / CC / CD /DD
AIM: Write a program to accept 3 numbers from the user and find the largest of the 3
numbers using
If - else if-else
Ternary operator
______________________________________________________________________
Expected OUTCOME of Experiment:
_____________________________________________________________________
Books/ Journals/ Websites referred:
_____________________________________________________________________
Problem Definition:
Ask user to input three numbers. Compare three numbers to find the largest of them
using
1. Nested if else statement
2. Using ternary operator
Department of Science and Humanities
Using if-else-if:
Implementation details:
Using if-else-if:
SOURCE CODE
#include <stdio.h>
int main()
{
int A, B, C; //declaring input variables
if(A>B)
{
if(A>C)
{
printf("Largest Number is %d",A);
}
else
{
printf("Largest Number is %d",C);
}
}
else
{
if(B>C)
{
printf("Largest Number is %d",B);
}
else
{
printf("Largest Number is %d",C);
}
}
return(0);
SOURCE CODE
#include <stdio.h>
int main()
{
int n1, n2, n3; //declaring input variables
return(0);
}
Department of Science and Humanities
Output(s):
Using If-else-if:
Using ternary operator:
Conclusion:
In this experiment, the use of ternary operators and if-else-if statement was learnt.
Ternary operators are a shorter and more efficient method of implementing decision
making in many cases as compared to if-else-if statement. They also have a shorter
syntax.
A1. Bitwise Operators are used for manipulating data at the bit level, also called bit level
programming. Bitwise operates on one or more bit patterns or binary numerals at the level of
their individual bits.
int a = 5;
a<<=2;