Professional Documents
Culture Documents
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.
}
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));
}