RAGHU INSTITUTE OF TECHNOLOGY
SPECIFICATION: (1)(b). C program to find the largest of three numbers using ternary
operator.
ALGORITHM:
STEP 1: START
STEP 2: Declare integer variables a,b,c
STEP 3: Read values a, b , c
STEP 4: check if a>b and a>c , then DISPLAY a and goto STEP 7
STEP 5: check if b>c , then DISPLAY b and goto STEP 7
STEP 6: else DISPLAY c
STEP 7: STOP.
FLOWCHART
START
Declare variables a,b,c
Read a,b,c
TRUE
FALSE
(a>b)&&
(a>c)
FALSE
TRUE
(b>c)
Display a is
greater
Display b is
greater
STOP
Department of Computer Science & Engg
Display c is
greater
RAGHU INSTITUTE OF TECHNOLOGY
PROGRAM
/* C Program to find the largest of three numbers */
/* Done by:-C-Faculty
// wk1b.c
Dated on:- 15/10/2013
*/
#include <stdio.h>
// stdio.h imports i/p and o/p functions
#include <curses.h>
// It imports i/p and o/p functions on curses(output screen)
int main()
// User defined program
// Main Program Begins
int a,b,c;
// Declare variable a, b & c in Integer Datatypes
clear();
// Clears the output screen of the computer
printf(/n Enter the values of a, b , c :-); // Displays the Quoted statement
scanf(%d%d%d,&a,&b,&c); // Reads the values of a , b ,c
(a>b)&&(a>c)? // Condition is satisfied so a is printed as greater than b and c
printf(/n The greatest number is:- %d,a) :
(b>c)?
// compare b and c values
printf(/n The greatest number is:- %d,b) :
printf(/n The greatest number is:- %d,c); // if the above two conditions fails then c is
greater
return(0);
}
// Returns the value 0
// Ends Main Program
PROCEDURE FOR EXECUTING THE PROGRAM:
Step 1: After typing the program, press ESC button+shift+: and then type wq(to save the program and
quit)
Step 2: Now compile the program by using the following command
cc wk1b .c lcurses lm
Step 3: Now go for running the program by using the command
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
./a.out
Step 4: To create an executing file use the command
cc wk1b.c -lcurses o larger
EXPECTED I/P AND O/P:
Output (1)
Enter the values of a, b , c :-2
3
4
The greatest number is:-4
Output (2)
Enter the values of a, b , c :-6
10
5
The greatest number is:-10
ORIGINAL I/P AND O/P:
Output (1)
Enter the values of a, b , c :-2
3
4
The greatest number is:-4
Output (2)
Enter the values of a, b , c :-6
10
5
The greatest number is:-10
VIVA VOCE QUESTIONS:
i) What are the various types of unconditional statements?
Ans: Goto , break and continue.
ii) What are the various types of conditional statements?
Ans: if, if-else , switch statements
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
iii) What is this operator ? :
Ans: This operator is a combination of ? and : . and takes three operands. This operatpor is known
as the conditional operator.
The general form of the conditional operator is as follows:
Conditional expression ? expression 1 : expression2
The conditional expression is evaluated first. If the result is nonzero, expression 1 is evaluated and
is returned as the value if the conditional expression. Otherwise, expression 2 is evaluated and its
value is returned.
--xXx--
Department of Computer Science & Engg