Chapter - 3: The Decision Control

What would be the output of the following programs:


H
Sections
1
Exercises

(a)

#include<stdio.h>
int main()
{
	int i = -4, j, num ;
 	
	j = ( num < 0 ? 0 : num * num ) ;
 	printf ( "%d\n", j ) ;
	
	return 0;	
}

Output:

num*num


(b)

#include<stdio.h>
int main()
{
	int k, num = 30 ;
	
	k = ( num > 5 ? ( num <= 10 ? 100 : 200 ) : 500 ) ;
	printf ( "\n%d", num ) ; 
	
	return 0;	
}

Output:

30


(c)

#include<stdio.h>
int main()
{
	int j = 4 ;
 	
	 (!j != 1 ? printf ( "\nWelcome") : printf ( "\nGood Bye") ) ; 
	
	return 0;	
}

Output:

Welcome


© 2020 Garbage Valuegarbage value logo