You are on page 1of 10

Q1 #include<stdio.

h>

int main()

int a,b;

printf("enter two numbers\n");

scanf("%d%d",&a,&b);

if(a>b)

printf("greater number is %d\n",a);

else

printf("greater number is %d\n",b);

return 0;

Q2 #include<stdio.h>
int main()
{
int a,b,c;

printf("enter 3 numbers\n");

scanf("%d%d%d",&a,&b,&c);

if(a>b && a>c)

printf("greatest number is %d\n",a);

else if(b>c && b>a)

printf ("greatest number is %d\n",b);

else if(c>a && c>b)

printf("greatest number is %d\n",c);

return 0;

}
Q3 #include<stdio.h>

int main()

int a;

printf("enter a number\n");

scanf("%d",&a);

if(a>0)

printf("the number is positive\n",a);

else if(a==0)

printf ("the number is zero \n",a);

else if(a<0)

printf("the number is negative\n",a);

return 0;

Q4 #include<stdio.h>

int
main ()

int a;

printf ("enter a number\n");

scanf ("%d", &a);

if (a % 5 == 0 && a % 11 == 0)

printf ("the number is divisible by 5 and 11\n");

else

printf ("it is not divisible by 5 and 11\n");

return 0;

Q5 #include<stdio.h>
int
main ()

int a;

printf ("enter a number\n");

scanf ("%d", &a);

if (a%2==0)

printf ("the number is EVEN \n", a);

else

printf ("the number is ODD\n", a);

return 0;

Q6 #include <stdio.h>

int main ()

int a , flag=0;

printf("enter the year\n");

scanf("%d",&a);

if(a%4==0)
{

if(a%100==0)

if(a%400==0)
flag=1;

else

flag=1;

if (flag==1)

printf("it is leap year \n",a);


else

printf("it is not leap year \n",a);

return 0;

Q7
#include <stdio.h>

int main()

char c;

printf("ENTER A CHARACTER\n");

scanf("%c",&c);

if((c>='a' && c<='z')||(c>='A' && c<='Z'))

printf("%c is an alphabet",c);

else

printf("it is not");

return 0;

Q8 #include <stdio.h>

int main()

char c;

printf("ENTER A CHARACTER\n");

scanf("%c",&c);

if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u'||c=='A' || c=='E' || c=='I'


|| c=='O' || c=='U')

printf("%c is vowel",c);

else
printf("it is consonant");

return 0;

Q9 #include<stdio.h>
int main()
{
char ch;
printf("enter any character\n");
scanf("%c",&ch);
if((ch>='a' && ch<='z')||(ch>='A' && ch<='Z'))
printf("%c is alphabet",ch);
else if(ch>='0' && ch<='9')
printf("%c is digit",ch);
else
printf ("%c is special character");
return 0;
}

Q10 #include <stdio.h>

int main()

char c;

printf("ENTER A CHARACTER\n");

scanf("%c",&c);

if(c>='a' && c<='z')

printf("%c is lower case",c);

else if(c>='A' && c<='Z')

printf("%c is upper case",c);

return 0;

Q11

Q12 #include <stdio.h>

int main()

{
int c;

printf("ENTER A MONTH NUMBER :\n");

scanf("%d",&c);

if(c==1 || c==3 || c==5 ||c==7||c==8||c==10||c==12)

printf("month has 31 days",c);

else if(c==4||c==6||c==9||c==11)

printf("month has 30 days",c);

else if(c==2)

printf("month has 28 or 29 days");

else

printf("enter correct month number");

return 0;

Q13
#include <stdio.h>

int main()
{
int amount;
int note500, note100, note50, note20, note10, note5, note2, note1;
printf("Enter amount: ");
scanf("%d", &amount);
if(amount >= 500)
{
note500 = amount/500;
amount -= note500 * 500;
}
if(amount >= 100)
{
note100 = amount/100;
amount -= note100 * 100;
}
if(amount >= 50)
{
note50 = amount/50;
amount -= note50 * 50;
}
if(amount >= 20)
{
note20 = amount/20;
amount -= note20 * 20;
}
if(amount >= 10)
{
note10 = amount/10;
amount -= note10 * 10;
}
if(amount >= 5)
{
note5 = amount/5;
amount -= note5 * 5;
}
if(amount >= 2)
{
note2 = amount /2;
amount -= note2 * 2;
}
if(amount >= 1)
{
note1 = amount;
}
printf("Total number of notes = \n");
printf("500 = %d\n", note500);
printf("100 = %d\n", note100);
printf("50 = %d\n", note50);
printf("20 = %d\n", note20);
printf("10 = %d\n", note10);
printf("5 = %d\n", note5);
printf("2 = %d\n", note2);
printf("1 = %d\n", note1);

return 0;
}

Q14
#include <stdio.h>

int main()
{
int angle1, angle2, angle3, sum;

printf("Enter three angles of triangle: \n");


scanf("%d%d%d", &angle1, &angle2, &angle3);
sum = angle1 + angle2 + angle3;
if(sum == 180 && angle1 != 0 && angle2 != 0 && angle3 != 0)
printf("Triangle is valid.");
else
printf("Triangle is not valid.");
return 0;
}

Q15 #include <stdio.h>


int main()
{
int side1, side2, side3;
printf("enter three sides of triangle"\n);
scanf("%d%d%d",&side1,&side2,&side3);
if((side1+side2)>side3)
{
if((side2+side3)>side1)
{if ((side3+side1)>side2)
printf("triangle is valid");
}
}
else
printf("triangle is not valid");
return 0;
}

Q16 #include <stdio.h>


int main()
{
int a,b,c;
printf("enter three sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
if(a==b && b==c)
printf("triangle is equilateral");
else if(a==b||b==c||a==c)
printf("triangle is isosceles");
else
printf("triangle is scalene");
return 0;
}

Q17 #include <stdio.h>


int main()
{
float x,y,a,b,c,D;
printf("enter values of a,b,c such that a!=0\n");
scanf("%f%f%f",&a,&b,&c);
D=b*b-4*a*c;
if(D>0)
{ x=(-b+sqrt(D))/2*a;
y=(-b-sqrt(D))/2*a;
printf("the roots are %f\n%f",x,y);
}
else if(D==0)
{ x=y=-b/2*a;
printf(" the roots are %f\n%f",x,y);
}
else
printf(" the roots are unreal");
return 0;
}

Q18 #include<stdio.h>
int main()
{
int phy,maths,chem,bio,comp;
float per;
printf(" Enter marks obtained in five subjects\n");
scanf("%d%d%d%d%d",&phy,&maths,&chem,&bio,&comp);
per=(phy+maths+chem+bio+comp)/5.0;
printf("PERCENTAGE IS %.2f\n",per)
if(per>=90)
printf("GRADE A");
if(per>=80 && per<90)
printf("GRADE B");
if(per>=70 && per<80)
printf("GRADE C");
if(per>=60 && per<70)
printf("GRADE D");
if(per>=40 && per<60)
printf("GRADE E");
if(per<40)
printf("GRADE F");
return 0;
}

Q19
#include<stdio.h>
int main()
{
float basic_s,gross_s,da,hra;
printf("enter the basic salary:\n");
scanf("%f",&basic_s);
if(basic_s<=10000)
{ da=basic_s*0.8;
hra=basic_s*0.2;
}
else if(basic_s<=20000 && basic_s>10000)
{da=basic_s*0.9;
hra=basic_s*0.25;
}
else if(basic_s>20000)
{da=basic_s*0.95;
hra=basic_s*0.3;
}
gross_s=hra+da+basic_s;
printf("gross salary is %f",gross_s);
return 0;
}

Q20

#include <stdio.h>

int main()
{
int unit;
float amt, total_amt, sur_charge;
printf("Enter total units consumed: ");
scanf("%d", &unit);
if(unit <= 50)
{
amt = unit * 0.50;
}
else if(unit <= 150)
{
amt = 25 + ((unit-50) * 0.75);
}
else if(unit <= 250)
{
amt = 100 + ((unit-150) * 1.20);
}
else
{
amt = 220 + ((unit-250) * 1.50);
}
sur_charge = amt * 0.20;
total_amt = amt + sur_charge;

printf("Electricity Bill = Rs. %.2f", total_amt);

return 0;
}

You might also like