Ad

Chapter - 3: The Decision Control

What will be the output of the following programs:


Ad
E
Sections
1
Exercises

(a)

#include<stdio.h>
int main ()
{
	int i = 4, z = 12 ;
	if ( i = 5 || z > 50 )
		printf ( "\nDean of students affairs" ) ;
	else
		printf ( "\nDosa" ) ; 
}

Output:

Dean of students affairs


(b)

#include<stdio.h>
int main()
{
	int i = 4, j = -1, k = 0, w, x, y, z ;
	
	w = i || j || k ;
	x = i && j && k ;
	y = i || j && k ;
	z = i && j || k ;
	printf ( "\nw = %d x = %d y = %d z = %d", w, x, y, z ) ; 
	
	return 0;
}

Output:

w = 1 x = 0 y = 1 z = 1


(c)

#include<stdio.h>
int main()
{
	int i = -3, j = 3 ;
	
	if ( !i + !j * 1 )
		printf ( "\nMassaro" ) ;
	else
		printf ( "\nBennarivo" ) ; 
	
	return 0;
}

Output:

Bennarivo


(d)

#include<stdio.h>
int main()
{
	int a = 40 ;
	
	if ( a > 40 && a < 45 )
		printf ( "a is greater than 40 and less than 45" ) ; 
	else
		printf ( "%d", a ) ; 	
	return 0;
}

Output:

40


(e)

#include<stdio.h>
int main()
{
	int x = 20 , y = 40 , z = 45 ;
	
	if ( x > y && x > z )
		printf( "x is big" ) ;
	else if ( y > x && y > z )
		printf( "y is big" ) ;
	else if ( z > x && z > y )
		printf( "z is big" ) ; 
	
	return 0;
}

Output:

z is big


(f)

#include<stdio.h>
int main()
{
	int i = -1, j = 1, k ,l ;
	
	k = !i && j ;
	l = !i || j ;
	printf ( "%d %d", i, j ) ; 
	return 0;
}

Output:

-1 1


(g)

#include<stdio.h>
int main()
{
	int j = 4, k ;

	k = !5 && j ;
	printf ( "\nk = %d", k ) ; 
	
	return 0;
}

Output:

k = 0

Ad

© 2024 Garbage Valuegarbage value logo