You are on page 1of 28

REVISION

1. Predict the output of following code


 main()

int i=10,j=2,k=0,m;
m=++i&&++j&&++k;
printf(“%d%d%d%d”, i, j, k, m);
}
 
2. Predict the output of following code:
main()
{
int x=10,y=-10;
printf(“%x \t”, x<<2);
printf(“%x”, y>>2);
}
3.Predict the output of following code:
main()
{
int i=10,j=2,k=0,m;
m=++i || ++j || ++k;
printf(“%d%d%d%d”,i,j,k,m);
}
4. Guess the output:
main()
{
printf(“\nks”);
printf(“\bmi\a”);
printf(“\rha\n”);
}
5.Predict the output of following code:
main()
{
int sum;
char ch1 = ’a’;
char ch2 = ’b’;
sum = ch1 + ch2;
printf(“%d”, sum);
}
6. main()
{
int i=10,j=20;
int *p,*q;
*p=i;
q=&j;
printf(“%d, %d”,*p,*q);
}
7.Predict the output of the following code:
#include <stdio.h>
float sub(float, float);
int main()
{
float a = 4.5, b = 3.2, c;
c = sub(a, b);
printf("%f", c);
return 0;
}
float sub(float a, float b)
{ return (a - b);
}
8. Predict the output of following code:

#include<stdio.h> int calc (int n)


int calc (int); int main ()  { int s, d;
{ int a, b; if (n!=0)
{ d = n%10;
 a = calc (123);
n = n/10;
b = calc (123);
s = d + calc (n);
printf ("%d, %d\n",a,b);
 }
return 0;
else return 0;
 }
return s;
   
}
9. Predict the output of following code:
struct birthdate
{
int date;
int month;
int year;
};
main()
{
union student
{
int stuid;
char stuname[2];
struct birthdate dob;
} u1={1234, “ab”};
printf(“%d”,sizeof(u1)); }
FACE
10. Predict the output of following code:
main()
{
struct student
{
int rollno : 6;
int examid : 5;
};
printf(“%ld”, sizeof(struct student));
}
11. Predict output of the following code:
main ()
{
 int x, a=10;
x=a==10? printf ("hai\t"): printf ("hello\n");
printf ("%d", x);
}
12. Predict the output of following code:
 main()
{
enum value
{
a=4.3,b,c,d,e
} var;
printf("%d\n", sizeof( var));
}
13. Predict the output of following code:
 main()
 {
int i=0,n;
int a[10]={1,2,3,4,5,6,7,8};
n=a[++i]+ i++ + a[i++] + a[i];
printf(“%d”, n);
 
}
14. Predict the output of following code: 
main() 

int a[3][2]={{1,2},{3,4},{5,6}};
printf(“%d, %d, %d\n”, a[2][1],*(a[2]+1),*(*(a+2)+1));
}
15. Predict output of the following code:

main()
{
int a, b=10;
a+=b-- - b++ + a;
b+=a-- - a++ + b;
printf(“%d %d”,a,b);
return 0;
}

16
16.What will be the output of following program?

main()
{
float c=0;
for( ; c++; printf(“%f”,c));
printf(“%f”,c);
}

17
17. What will be the output of the given program?

#include<stdio.h>
int main()
{
    int a=10,b=3,c=7;
    c=3+7==10;
    printf("%d",++c);
    return 0;
}

18
18. What will be the output of the given program?

#include<stdio.h>
int main()
{
    int a=10,b=3,c=7;
    c=3+(7==10);
    printf("%d",++c);
    return 0;
}

19
19.What could be the output for the following program?

#include<stdio.h>
void main()
{
int a = - - 2;
printf(“%d“,2+ ++a);
}

20
20. .What could be the output for the following program?

#include<stdio.h>
void main()
{
int a = -( - 2);
printf(“%d“,2+ ++a);
}

21
Write a program to find out the roots of a quadratic
equation: ax^2+bx+c=0; The values of a,b,c are given as
input. Also, check whether roots are real and equal, real
and distinct or unreal.
Input: 1 1 -2
Output: Real and distinct 1,-2

Input: 1 -2 1
Output: Real and equal 1,1

Input: 1 3 3
Output: Unreal
#include <stdio.h>
#include<math.h>
int main()
{
int a,b,c,d;
float x1,x2;
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
if(d==0)
{
printf("Real and equal");
x1=x2=-b/(2*a);
}

else if(d>0)
{
printf("Real and distinct");
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
}
else
{
printf("Unreal");
return 0;
}
printf("\n%0.2f,", x1);
printf("\n%0.2f", x2);
return 0;
}
Write a program to check whether a given
input integer is prime or not. If it is prime,
print the square root of the integer(precision
should be two digits). If it is non-prime print
0.00 instead.

Input: 2
Output: 1.41

Input : 4
Output: 0.00
#include <stdio.h>
#include<math.h>
int main()
{
int n;
scanf("%d",&n);
int ctr=0;
for(int j=2;j<=n/2;j++)
{
if(n%j==0)

{
ctr++;
break;
}

}
if((ctr==0)&&(n!=1)&&(n!=0))
printf("%0.2f",sqrt(n));
else
printf("0.00");
return 0;
}
• Write a C program to reverse a given integer.
Input: 123 Output: 321
Input: 4532 Output: 2354
• Write a C program to find the sum of the
factorial of digits of the given number.

Input: 123; Output: 1!+2!+3! = (1+2+6) = 9


Input: 326; Output: 3!+2!+6! = (6+2+720)=728 )
#include <stdio.h>
int main()
{
int n,rem,rev=0;
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;

}
printf("%d", rev);
return 0;
}
#include <stdio.h>
int fact(int );
int main()
{
int n,rem,sum=0;
scanf("%d", &n);
while(n!=0)
{
rem=n%10;
sum+=fact(rem);
n=n/10;

}
printf("%d", sum);
return 0;
}
int fact(int n)
{
if(n==0||n==1)
return 1;
else
return (n*fact(n-1));
}

You might also like