0% found this document useful (0 votes)
1 views3 pages

Experiment 04

This document outlines an experiment to write a C program that determines the greatest of three variables using if-else statements. It includes the objective, algorithm, program code, expected output, and learning outcomes related to C programming structure and control flow. The experiment emphasizes understanding the syntax, structure, and compilation process of a basic C program.

Uploaded by

Dipanshu Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views3 pages

Experiment 04

This document outlines an experiment to write a C program that determines the greatest of three variables using if-else statements. It includes the objective, algorithm, program code, expected output, and learning outcomes related to C programming structure and control flow. The experiment emphasizes understanding the syntax, structure, and compilation process of a basic C program.

Uploaded by

Dipanshu Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT 4

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: To print the greatest of three variables using if else statement


Input: Three numbers, n1, n2 and n3, of which the greatest has to be displayed.
Output: The greatest of the three input numbers is displayed on the console.
STEP 1: Start the program.
STEP 2: Include the necessary header file: #include<stdio.h>.
STEP 3: Define the main function.
STEP 4: Input three numbers n1, n2 and n3 from the user.
STEP 5: if(n1>n2), then
{
check if(n1>n3),
then print “n1 is the greatest number.”
else
print “n3 is the greatest number.”
} else{
check if(n2>n3),
then print “n2 is the greatest number.”
else print “n3 is the greatest number.”
}
STEP 6: Stop.

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.

LEARNING FROM EXPERIMENT:-

This experiment gave us an insight into the basic structure of a C program. We learned the
following:

• Creation of a header file.


• Creation of a main function, which is the starting point of the program.
• Usage of if else and nested if else statements to control the follow of execution of
instructions in a program.
• Usage of printf function, which displays the output on the console.
• About the successful compilation and execution of the program.

You might also like