Sunday 16 October 2011

Chapter 1: [F] What would be the output of the following programs:

(a)

main( )
{

int   i = 2, j = 3, k, l ;
float   a, b ;
k = i / j * j ;
l = j / i * i ;
a = i / j * j ;
b = j / i * i ;
printf( "%d %d %f %f", k, l, a, b ) ;
}

Output
0 2 0.000000 2.000000



(b)
 
main( )
{
int  a, b ;
a = -3 - - 3 ;
b = -3 - - ( - 3 ) ;
printf ( "a = %d b = %d", a, b ) ;
}

Output
a = 0 b = -6


(c)
main( )
{
float a = 5,  b = 2 ;
int c ;
c = a % b ;
printf ( "%d", c ) ;
}

Output
modulus operator can not be used between floats.
Compiler will give the error and there will be no output.



(d)

main( )
{
printf ( "nn \n\n nn\n" ) ;
printf ( "nn /n/n nn/n" ) ;
}


Output
nn

 nn
nn /n/n nn/n





(e) 

main( ) 
int a, b ; 
printf ( "Enter values of a and b" ) ; 
scanf ( " %d %d ", &a, &b ) ; 
printf ( "a = %d b = %d", a, b ) ; 
 

Output

Enter values of a and b
1
2
a = 1 b = 2 





(f) 
main( ) 
int p, q ; 
printf ( "Enter values of p and q" ) ; 
scanf ( " %d %d ", &p, &q ) ; 
printf ( "p = %d q =%d", p, q ) ; 


Output

Enter values of p and q
5 10
p=5 q=10













4 comments:

  1. Using integer rules of subtraction.here,
    a=-3+3, which further will be equals to 0
    and,
    b= -3 +(-3), which further equals to -6

    ReplyDelete