You are on page 1of 1

Submitted by: (Students Name)_____________________________________

Class/Semester:___________________

Assignment 2 (Based on if, if-else, switch, for, while, do-while)


Deadline: 30-oct-2014
Subject: Fundamental of Computers & C Programming (DA1210)
1.

What is output/error in this program?


void main( ) {
if(0)
printf(1); }

2. What will be the output?


void main( ) {
if(1)
printf(1);
printf(0);
else
printf(2); }
(a)10 (b)2 (c) No output (d) 1 0
3. What will be the output?
void main() {
char y=p;
switch(y) {
if(y==p) {
case p: printf(%s, pleasant);
case b: printf(%s,mood);
}
else
case g:printf(%s,moo);
default: printf(%s, );
} }
(a)pleasantmood (b)moo (c)mood
4. What will be the output?
void main() {
char x=h;
switch(x) {
case h:printf(%c, h);
case e:printf(%c, a);
case l:printf(%c, i);
case l:printf(%c, !);break;
case o:printf(%c, o);
} }
(a)Hai! (b)Hao (c)0Hai (d)None

5. What will be out as a string?


void main() {
if(a < b)
printf(hello
);
printf( how r u? );
if(a<a)
printf(sir ? );
}
6. what will be the output as a string?
void main() {
int a,b,c;
a=b=c=12;
a++; b++; c++;
if(a==b && b==c && a==c)
printf(welcome);
else
printf(good bye);
}
7. Print the following pattern using switch statement
*
**
***
****
8. Find the bug/error in the following code
void main() {
char x=x;
switch(x) {
case x: printf(%c,c); break;
case x : printf(%c, d); continue;
case x: printf(%c, x);
} }
9. What will be the value of f in the program execution?
void main() {
char k;
float f=5;
for(k=1;k<=10;k++) {
f-=0.1; }
printf(\n f=%g, f);

Prepared By: Mr.Ajay Kumar, CSE Faculty, DIT University Dehradun

}
(a)f=4 (b)f=-65 (c)f=66 (d) none
10. Find the value of SUM in following program?
void main() {
int n=1245, k=1, sum=0;
while(n!=0)
{
k=n%10;
sum=sum+k;
k=n/10;
n=k;
}
printf(sum=%d, sum); }
(a)SUM=13 (b) SUM=12 (c) SUM=10

11. What will be the output?


void main() {
char c=48;
while(c!=5) {
while(1)
{
printf(%c, c++);
break;
} } }

(a)012345 (b)01234 (c)1


12.Display the * in specific pattern.
void main() {
int x=3, i,j;
for(i=1; i<=x; i++) {
for(j=1; j<=i ; j++) {
printf( * );
}
printf(\n);
}
getch();
}

visit us: http://sites.google.com/site/kumarajay7th

You might also like