0% found this document useful (0 votes)
30 views15 pages

Assign Emt

Uploaded by

collegmemories0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
30 views15 pages

Assign Emt

Uploaded by

collegmemories0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 15
Dr B R Ambedkar National Institute of Technology Jalandhar Department of Computer Science and Engineering Assignment —2 Faculty : Dr. Lalatendu Behera Full Marks - 100 ‘Student Name: Branch Name: Roll Number: QL. Which of the following are invalid variable names and why? Rs] BASICSALARY basic basichra #MEAN group. 422 population in 2006 over time mindovermatter FLOAT hELLO queue. team’svictory Plot #3 2015_DDay Q2. Point out the errors, if any, in the following C statements, if there is an error write reason 0 (251 (2) int = 314.562 * 150; (b) name = ‘Ajay’ ; (©) varchar = ‘3’ ; (@)3.14*1*r*h=vol_of cyl; ()k=(a*b)(ct(25a+b)(d+e); (@) m_inst = rate of interest * amount in rs ; (g) si= principal * rateofinterest * numberofyears / 100 ; (hy area = 3.14 r=*2; (O volume = 3.14" r42*h; @k=((a*b)+)(25*a+b); Q3. Evaluate the following expressions and show their hierarchy. ray (a) g=big/2 + big * 4/big -big + abc /3; (abe = 2.5, big = 2, assume g to be a float) ()— on=ink * act/2+3/2* act+2+ ig; (ink = 4, act = 1, tig = 3.2, assume on to be an int) © wit add /4-6/2+2/3*6/ god; (qui = 4, add = 2, god = 2, assume s to be an int) @ 3*a/4-6/2+2/3*6/g; (a= 4, g=3, assume s to be an int) Q4. Convert the following equations into corresponding C statements. i Ge zo S8C+b)2/e-0542a/(q+r) (a+b)*Cim) as De (peDye? 4 (@ pa Wt622 (era) BtV (A= LDC +a)/e-0.8 +2b (xtra (lly) QS. What would be the output of the following programs: Is] @) void main { inti float a, b; keisj*is l=jlitiz he bajsimi; rintt( "6d %6d %f %f", k, 1, a, b); } (o) int main() { int a = 80, b = 85, c = 70,d = 75, e = 60; printf("Average of 5 subjects is: %0.2F", latb+c+d+e)/5.0); return 0; } (e) int main() { inta = 5, b= 8; printf("Numbers before swapping a = %d, b = %d", a,b); a=atb; ab; a=ab; printf("\nNumbers after swapping a = %d, b = %d", a,b); return 0; } 0) main() printf (“a = %db = %d", a,b); } @ main() { printf ("nn \n\n nin" ) ; prinef ("nn /n/n nnn" ) ; , eo main() { int pqs printf ("Enter values of p and q"); scanf (" %d %d", p,q); printt ("p= %d q =%d", p,q); } Q6. What would be the output of the following programs? [uo] (@) main() { int a= 300, b, ¢; if(a>= 400) b= 300; 100 ; printf ("\n%d %d", b,c); } (©) main() { int x = 10, y= 20; if(x==y)5 printf ("\n%d %d", x, y) 3 } (e) main() { int x = float y if(x printf ("\nx and y are equal” ) ; else printf ("\nx and y are not equal" ); yt (b) main() { int a= 500, b,c; if(a>=400) b= 300; c= 200; printf ("\n%d %d", b, ¢); } (@) main() { intx=3,y=5; if( ) printf ("\n%ql", x) else; printf ("\n%d", y , (8 main() { intx=3,y,25 y=x=10; z=x<10; printf ("nx = %d y = %d 2 = %d", x, y, 2); } @ main() { int k= 35; printf ("\n%d %d %d", k } = 35, k= 50, k> 40); o main( ) 5.b,c5 15; c=a=}) printf ("\na and b are equal” ) ; } (© main() (@) main( ) { { if(X'<'x') int x= 10; printf ( "\nascii value of X is smaller than that of if (x >= 2) then x") printf ("\n9%d", x); } } (e) main() (8) main( ) { { int x= 10; int x= 10, y=15; ifx>=2 if (x% 2=¥%3) printf ("\nd%d", x); printf (*\nCarpathians” ) ; } } (g) main( ) (h) main( ) { { intx=30, y=40; int x= 10; if(x==y) if (x>=2) then printi( "x is equal to y" ); printf ("in%dl", x) elseif (x>y) } printf( “x is greater than y" ) ; elseif (x50) if(i=5 &&2>5) prinef ("\nDean of students affairs" ); else printf ("wnDosa" ) ; , printf ("\wnLet us C" ); else printf ("wnWish C was free !" ) ; , (©) main() { inti=4,j=-1,k=0,w, x,y,z; w=illjllk; X= 8& j &&k; y=illj&&k; Z=18&j||k; printf ("nw = %d x = %d y = %d-2 = %6d", W, x, ¥, 2); ) (e) main() { inti=-3,j=3; if(itj*1) printf ("\nMassaro” ) ; else printé ("\nBennarivo" ) ; } (g) main() { int p= 8,q= 20; if (p==5 &&q>5) printf ("\nWhy not G") ; else printf ("\nDefinitely C 1") ; ) (i) main() { intx=20,y=40,2=45; if(x>y&&x>z) printi( "x is big"); else if (y > x && y>z) (a) main() { inti=4,j=-1,k=0,y,2; yri+S&&j+1k+2; Z=i+5||j+1&&k+2; printf (“\ny = %d z= 96d", y, 2) 5 y (9 main( ) { int a= 40; if (a> 40 &&a<45) printf (“a is greater than 40 and less than 45" ) ; else printf ("96d a) } (hy main() { inti=-1,)= 1k); =i &&j; 1=illj printf (°%d % } LI): G) main() { int Is fills printf ("%d %d", i,j) 3 prinei( "y is big") ; else if (2 > x && 2>y) printi( "2 is big” ); ) Q9. Point out the errors, if any, in the following programs and give reason of error: [8] @ main() { inti=2,j)=5; if(i== 2 &&j==5) printf ( "\nSatisfied at last" ); } (© main() { char spy ='a', password = if (spy == 'a' or password = printf ("\nAll the birds are safe in the nest" ) ; } (©) main() { int x = 10, y = 20; if (x>=2 andy <=50) printf ("\n%q", x); } (g) main() { int x = 2; if (x==2 &&x!=0); { (b) main() { int code, flag 5 if (code == 1 & flag == 0) printf ("\nThe eagle has landed” ) ; + (@) main { inti = 10, j=20; if(i=5) &&if (j= 10) printf ("\nHlave a nice day” ); } (Q main() { inta, b; if(a printf (\nGod is Great" ); } (b) main() { inti= 10, j=10 if (1 && j == 10) printf ("\nHave a nice day" ); printf ( "nH" ); } printf( "\nHello” ) ; } else printf( "Bye" ) ; } Q10. What would be the output of the following programs: BI (a) main() (b) main() { { inti=-4,j, num; int k, num = 30 ; j= (num <0? 0: num * num ) ; = (num > 5 ? (num <= 10? 100 : 200) : 500); printf ("ind j); printf ("\n%d", num ) ; ) + (c) main() { imtj=45 (1j != 1? printf ("\nWelcome") : printf ( "\nGood Bye") ) ; } QU1. Point out the errors, if any, in the following programs: 7 (a) main() (b) main() { int tag = 0, code = 1; if (tag ==0) 29%", i) 5 code > 1? printf ("\nHello" ) ? printf ("\ "))5 printf ("\nHello Hi !!") ; } (©) main() (@ main() { { inti=10,j; inta=5,b=6; i>=52(j=10):(j=15); (a==b? printé( "%d",a) ); princt ("ined %d", i,j) 5 , (e) main() { intn=9; ¢ ? printf( "You ate correct" ) ; prinef( "You are wrong" );) , (© main() { int kk = 65 ,I1; kk == 65 : printf ( "\n kk is equal to 65" ) : printf (Cn kk is not equal (0 65"); printf( "%d", IL) : } (g) main() { intx= 10, x== 20 && y != 10? printf( "True" prine{( "False" ); ) Q12. What would be the output of the following programs 18] (a) main() (b) main( ) { { intj; inti while (j <= 10) while (i<=10); { { printf ("\n9%d", j) 5 prinef ("wn%d", 1) 5 j=jrds itt; } , } } (©) main() (@) main() { { int; intx=1; while (j <= 10) while (x == 1) { printf ("in%q", 5); x=x-1; j=itl; printf ("\n%d", x) } } (e) main() { intx=1; while (x == 1) x=x-1 printf ("nd , (g) main() , @ main() { while (‘a' <'b') printf ( "\nmalyalam is a palindrome" ) ; } (&) main() { inti; while (i= 10) { prinef ("\n%d", i) ; isitt; } , } (8 main() { char x; while (x = 0; x <= 255 ;x*+) printf ("“\WnAscii value %d Character %e", x, x) 5 , (h) main() { intx=4,y=3,2; printf ("ind %d %d", x, y, 2) 3 , @) main() { inti=10 while (i= 20) printf ("nA computer buff!" ); > @ main() { float x = 1.1; while (x == 1.1) 4 pring ("wn%f", x); x=x-01; } , (m) main() { while (‘1'<'2) printf (“\nln while loop" ) ; + (0) main() { intx=4, y=0, 2; while (x { we continue ; else printf (“ind %d"”, x, y ) 5 , } (q@ main() { inti=1,j)=1; for(s3) { if(i>5) break ; else jets printf ("\n%d", j); isis , } (13)Find the output for following programs (n) main) { char x ; for (x= 0; x <= 255; x++) printf ("\MnAscii value %d Character 6", XX) 5 + (p) main() { intx=4, y=0, 2; while (x>=0) { if(x==y) break ; else printf (“\n%d %d”, x, y) 5 yes } } () intmaing { inti=1,j=1; for(; js printi(” jaier <1; return 0; } 17] (@) int main() { unsigned int a = 10; ana; prine{("%d\n", a); ) o void main() { int x= 97; int y = sizeof(x++); printh("x is %d", x); } © void main() { inta int k= (a+, ++a); prinef("%d\n", k); } () int main() ( if (~0 == 1) printf("yes\n"); else printf("no\n"); o (b) int main() { if (7 & 8) print{("Honesty"); if ((~7 & 0x000f) == 8) printf("is the best policy\n");} @) void main() { inta=5,b=-7,c=0,d; d= +a && +b | +6; printh("in%d%d%d%d", a,b, c, ds } o int main) { int x = +2; x=x2> 1 printf("%din", x); ) (h) void main() { float x = 0.1; if (== 0.1) print{("Sanfoundry"); else printf(" Advanced C Classes"); o int main void main { { unsigned int i = 23; float x = 0.1; signed char c= -23; printf("%d, ", »); if(i>o printt("%f", x); printi("Yest y else if (i <0) printf("No\n"); } 6 0 void main int main() { { double ch; switch (printf("Do")) printf(“enter a value between 1 to 2:"); q scanf("%I0", &ch); case 1: switch (ch) printf("Firstin"); break; case 2: print{("Second\n"); break; default: printf("Defaultin"); break; ) ) ) (m) (a) int main) int main() { { inti=0,}=0; inti=0; while (<5, |< 10) { itt; ies } continue; printf("%d, %6dh\n", i,j); printf("In while loop "); ) } while (i < 2); printf("%din", 1); © int main() { inti=0, j= 0, for (i 1< 25: for j= 0;) <3; printf("Lin"); break; } prinef("2\n"); } print{(“after loop\n"); , @ int main() { inti=0, j=0; while (1 < 2) { Titty while (<3) { printf("Loop\n"); goto 11; } } , ©) int main { inti= char ¢= "a while (i < 2){ iss switch (c) { primtf("9%c ", ); break; break; } ) printf("after loopin");

You might also like