Experiment 04
Experiment 04
OBJECTIVE:-
Write a program to print the greatest of three variables using if else statement.
INTRODUCTION:-
In this experiment, through the creation of a basic program to print the greatest of three
variables, we will try to understand logic creation with help of if else and nested if else
statements and about the basic features of C language, i.e., it’s syntax, structure and
compilation process.
ALGORITHM:-
PROGRAM CODE:-
#include<stdio.h>
int main()
{
int n1,n2,n3;
printf("Name: Dipanshu Sharma\nRoll No.: 24/B01/056\n");
printf("Enter any three numbers.\n");
scanf("%d",&n1);
scanf("%d",&n2);
scanf("%d",&n3);
if(n1>n2)
{
if(n1>n3)
printf("%d is the greatest number.\n",n1);
else
printf("%d is the greatest number.\n",n3);
}
else{
if(n2>n3)
printf("%d is the greatest number.\n",n2);
else
printf("%d is the greatest number.\n",n3);
}}
OUTPUT:-
Upon successful compilation and execution, the program will produce the following output:
RESULT:-
The greatest of the three input numbers was successfully displayed on the console, upon
successful execution and compilation of the program.
This experiment gave us an insight into the basic structure of a C program. We learned the
following: