Chapter - 3: The Decision Control

What will be the output of the following programs:


A
Sections
1
Exercises

(a)

#include<stdio.h>
int main()
{
	int a = 300, b, c ;
	if ( a >= 400 )
		b = 300 ;
		c = 200 ;
	printf ( "\n%d %d", b, c ) ;
	return 0;
}

Output: 

0 200


(b)

#include<stdio.h>
int main()
{
	int a = 500, b, c ;
	if ( a >= 400 ) 
	b = 300 ;
	c = 200 ;
	printf ( "\n%d %d", b, c ) ;
	return 0;
}

Output:

300 200


(c)

#include<stdio.h>
int main()
{
	int x = 10, y = 20;
	if ( x == y );
	printf ( "\n%d %d", x, y );
	return 0;
}

Output: 

10 20


(d)

#include<stdio.h>
int main()
{
	int x = 3 ;
	float y = 3.0 ;
	if ( x == y )
	    printf ( "\nx and y are equal" );
	else
	    printf ( "\nx and y are not equal" );
	return 0;
}

Output: 

x and y are equal


(e)

#include<stdio.h>
int main( )
{
	int x = 3, y, z ;
	y = x = 10 ;
	z = x < 10 ;
	printf ( "\nx = %d y = %d z = %d", x, y, z ) ;
	return 0;
}

Output:

x =  10 

y = 10 

z = 0


(f)

#include<stdio.h>
int main( )
{
	int i = 65 ;
	char j = 'A' ;
	if ( i == j )
		printf ( "C is WOW" ) ;
	else
		printf( "C is a headache" ) ;
	return 0;
}

Output:

C is WOW


© 2021 Garbage Valuegarbage value logo