Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

10.

 Write a C program to find the eligibility of admission for a professional course


based on the following criteria: Go to the editor
Eligibility Criteria: Marks in Maths >=65 and Marks in Phy >=55 and Marks in
Chem>=50 and Total in all three subjects >=190 or Total in Maths and Physics
>=140 ------------------------------------- Input the marks obtained in Physics:65 Input
the marks obtained in Chemistry:51 Input the marks obtained in Mathematics:72
Total marks of Maths, Physics and Chemistry: 188 Total marks of Maths and
Physics: 137 The candidate is not eligible.
Expected Output :
The candidate is not eligible for admission.
Answer
#include <stdio.h>

int main()

int maths, phy, chem, total_pcm, total_pm;

printf("Enter the marks of maths : \n");

scanf("%d",&maths);

printf("Enter the marks of phy : \n");

scanf("%d",&phy);

printf("Enter the marks of chem : \n");

scanf("%d",&chem);

printf("Enter the marks of total_pcm : \n");

scanf("%d",&total_pcm);

printf("Enter the marks of total_pm : \n");

scanf("%d",&total_pm);

if((maths>=65&&phy>=55&&chem>=50)&&(total_pcm>=190||total_pm>=140))
{

printf("The candidate is eligible for admission.");

else

printf("The candidate is not eligible for admission.");

return 0;

12. Write a C program to read roll no, name and marks of three subjects and
calculate the total, percentage and division. Go to the editor
Test Data :
Input the Roll Number of the student :784
Input the Name of the Student :James
Input the marks of Physics, Chemistry and Computer Application : 70 80 90
Expected Output :
Roll No : 784
Name of Student : James
Marks in Physics : 70
Marks in Chemistry : 80
Marks in Computer Application : 90
Total Marks = 240
Percentage = 80.00
Division = First
Answer:
#include <stdio.h>
int main()
{
int roll_no, phy, chem, computer, total, division;
char name[10];
float percentage;
printf(" \n Enter the roll no. : ");
scanf("%d" ,&roll_no);

printf("\n Enter the students name : ");


scanf("%s" ,name);

printf("\n Enter the marks of phy : ");


scanf("%d" ,&phy);

printf(" \n Enter the marks of chem : ");


scanf("%d" ,&chem);

printf(" \n Enter the marks of Computer Application : ");


scanf("%d" ,&computer);

printf(" the students name : %s",name);


total= phy + chem+ computer;

printf("\nTotal = %d \n",total);

percentage = (total)/3;
printf("Percentage (%) = %f \n",percentage);

if(percentage>70.00)
{
printf("Division = Distriction");
}
else if(percentage>60.00&&percentage>70.00)
{
printf("Division = 1st class");
}
else if(percentage>50.00&&percentage>60.00)
{
printf("Division = 2nd class");
}
else if(percentage>35.00&&percentage>50.00)
{
printf("Division = 3rd class");
}
else
{
printf("Division = Failed");
}
return 0;
}

13. Write a C program to read temperature in centigrade and display a suitable


message according to temperature state below : Go to the editor
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot
Test Data :
42
Expected Output :
Its very hot.
Answer:
#include <stdio.h>
int main()
{
int Temp;

printf(" \n Enter the temprature here. : ");


scanf("%d" ,&Temp);

if(Temp < 0)
{
printf("Freezing weather");
}
else if(Temp>0&&Temp<=10.00)
{
printf("Very Cold weather");
}
else if(Temp>10&&Temp<=20.00)
{
printf("Cold weather");
}
else if(Temp>20&&Temp<=30.00)
{
printf("Normal in Temp");
}
else if(Temp>30&&Temp<=40.00)
{
printf("Its Hot");
}
else if(Temp>=40)
{
printf("Its Very Hot");
}
return 0;
}

14. Write a C program to check whether a triangle is Equilateral, Isosceles or


Scalene. Go to the editor
Test Data :
50 50 60
Expected Output :
This is an isosceles triangle.
Click me to see the solution

and

15. Write a C program to check whether a triangle can be formed by the given


value for the angles. Go to the editor
Test Data :
40 55 65
Expected Output :
The triangle is not valid.

Answer:-

#include <stdio.h>
int main()
{
int anglea,angleb,anglec;
printf("Enter the angles of triangle = ");
scanf("%d,%d,%d",&anglea,&angleb,&anglec);

if(anglea+angleb+anglec==180)
{
if(anglea==angleb&&angleb==anglec)
{
printf("This is an equilateral triangle.");
}
else if (anglea==angleb||anglea==anglec||angleb==anglec)
{
printf("This is an isosceles triangle.");
}
else
{
printf("This is a scalene triangle.");
}
}
else
{
printf("The triangle is not valid.");
}
return 0;

}
16. Write a C program to check whether a character is an alphabet, digit or
special character. Go to the editor
Test Data :
@
Expected Output :
This is a special character.
Click me to see the solution

And

17. Write a C program to check whether an alphabet is a vowel or consonant. Go


to the editor
Test Data :
k
Expected Output :
The alphabet is a consonant.

Answer:
#include <stdio.h>
int main()
{
char ch;

printf("Enter the charecter here = ");


scanf("%c",&ch);

if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
{
if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||
ch=='U')
{
printf("The alphabet is a vowel.");
}
else
{
printf("The alphabet is a consonant.");
}
}
else if (ch>='0'&&ch<='9')
{
printf("This is a digit.");
}
else
{
printf("This is a special character.");
}

return 0;

18. Write a C program to calculate profit and loss on a transaction. Go to the


editor
Test Data :
500 700
Expected Output :
You can booked your profit amount : 200

Answer:
#include <stdio.h>
int main()
{
int amount1,amount2,PnL;
printf("Enter the amount of purchases : ");
scanf("%d",&amount1);
printf("Enter the amount of Sell : ");
scanf("%d",&amount2);
if(amount2-amount1>=0)
{
PnL=amount2-amount1;
printf("You made profit ₹ : %d ", PnL);
}
else
{
(amount2-amount1<0);
PnL=amount2-amount1;
printf("You made loss ₹ : %d",PnL);
}
return 0;
}

19. Write a program in C to calculate and print the Electricity bill of a given


customer. The customer id., name and unit consumed by the user should be
taken from the keyboard and display the total amount to pay to the customer.
The charge are as follow : Go to the editor

Unit Charge/unit
upto 199 @1.20

200 and above but less than 400 @1.50

400 and above but less than 600 @1.80

600 and above @2.00

If bill exceeds Rs. 400 then a surcharge of 15% will be charged and the minimum
bill should be of Rs. 100/-

Test Data :
1001
James
800
Expected Output :
Customer IDNO :1001
Customer Name :James
unit Consumed :800
Amount Charges @Rs. 2.00 per unit : 1600.00
Surchage Amount : 240.00
Net Amount Paid By the Customer : 1840.00
Answer.

#include <stdio.h>

int main()

int cust_id;

float unit,amount,rate,surcharge;

char name[10];

printf("Enter the customer id no.: ");


scanf("%d",&cust_id);

printf("\nEnter the customer name.: ");

scanf("%s",&name);

printf("\nEnter the consumed unit: ");

scanf("%f",&unit);

amount=unit*rate;

if (unit<=199)

amount=unit*1.20;

printf("\nAmount Charges @Rs.1.20 per unit = %f ",amount);

else if (unit>=200&&unit<400)

amount=unit*1.50;

printf("\nAmount Charges @Rs.1.50 per unit = %f ",amount);

else if (unit>=400&&unit<600)

amount=unit*1.80;

printf("\nAmount Charges @Rs.1.80 per unit = %f ",amount);

else if (unit>=600)

amount=unit*2.00;

printf("\nAmount Charges @Rs.2.00 per unit = %f ",amount);

if(unit<=83.33333)

amount=100;
printf("\nMinimum bill amount = 100 ");

if(amount>400)

surcharge=amount*0.15;

printf("\nSurchage Amount : %f",surcharge);

amount=amount+surcharge;

printf("\nNet Amount Paid By the Customer : %f",amount);

return 0;}

20. Write a program in C to accept a grade and declare the equivalent


description : Go to the editor

Grade Description

E Excellent

V Very Good

G Good

A Average

F Fail
Test Data :
Input the grade :A
Expected Output :
You have chosen : Average
Answer:

#include <stdio.h>

int main()

char grade;

char E,e,V,v,G,g,A,a,F,f;

printf("Input the grade : ");

scanf("%c",&grade);

if(grade=='E' || grade=='e')

printf("\nYou have chosen : Excellent");

else if(grade=='V'|| grade=='v')

printf("\nYou have chosen : Very Good");

else if(grade=='G'|| grade=='g')

printf("\nYou have chosen : Good");

else if(grade=='A'|| grade=='a')

printf("\nYou have chosen : Average");

else if(grade=='F'|| grade=='f')


{

printf("\nYou have chosen : Fail");

return 0;

As per switch case

#include <stdio.h>

int main()

char ch;

printf("Enter the number: ");

scanf("%c",&ch);

switch (ch)

case 'E':

printf("Excellent");

break;

case 'V':

printf("Very Good");

break;

case 'G':

printf("Good");
break;

case 'A':

printf("Average");

break;

case 'F':

printf("Fail");

break;

default:

printf("Charecter is invalid.");

break;

return 0;

21. Write a program in C to read any day number in integer and display day
name in the word. Go to the editor
Test Data :
4
Expected Output :
Thursday

Answer:
#include <stdio.h>

int main()

int digit;
printf("Enter the digit : ");

scanf("%d",&digit);

if(digit==1)

printf("Monday");

else if (digit==2)

printf("Tuesday");

else if (digit==3)

printf("Wednesday");

else if (digit==4)

printf("Thursday");

else if (digit==5)

printf("Friday");

else if (digit==6)

printf("Saturday");

else if (digit==7)

{
printf("Sunday");

else if (digit==0)

printf("Please enter the digit between 1 to 7.");

else

printf("In week there is only 7 days.");

return 0;

As per switch case

#include <stdio.h>

int main()

int digit;

printf("Enter the number: ");

scanf("%d",&digit);

switch (digit)

case 1:

printf("Monday");

break;
case 2:

printf("Tuesday");

break;

case 3:

printf("Wednesday");

break;

case 4:

printf("Thursday");

break;

case 5:

printf("Friday");

break;

case 6:

printf("Saturday");

break;

case 7:

printf("Sunday");

break;

default:

printf("Number is invalid.");

break;

}
return 0;

22. Write a program in C to read any digit, display in the word. Go to the editor
Test Data :
4
Expected Output :
Four
Answer:

#include <stdio.h>

int main()

int digit;

printf("Enter the digit : ");

scanf("%d",&digit);

if (digit==0)

printf("Zero");

else if(digit==1)

printf("One");

else if (digit==2)

printf("Two");
}

else if (digit==3)

printf("Three");

else if (digit==4)

printf("Four");

else if (digit==5)

printf("Five");

else if (digit==6)

printf("Six");

else if (digit==7)

printf("Seven");

else if (digit==8)

printf("Eight");

else if (digit==9)

printf("Nine");

}
else

printf("This program is only for 0 to 9 digit");

return 0;

As per switch case

#include <stdio.h>

int main()

int digit;

printf("Enter the number: ");

scanf("%d",&digit);

switch (digit)

case 1:

printf("One");

break;

case 2:

printf("Two");

break;
case 3:

printf("Three");

break;

case 4:

printf("Four");

break;

case 5:

printf("Five");

break;

case 6:

printf("Six");

break;

case 7:

printf("Seven");

break;

case 8:

printf("Eight");

break;

case 9:

printf("Nine");

break;

default:
printf("Number is In valid");

break;

return 0;

23. Write a program in C to read any Month Number in integer and display Month
name in the word. Go to the editor
Test Data :
4
Expected Output :
April

Answer:

#include <stdio.h>

int main()

int digit;

printf("Enter the digit : ");

scanf("%d",&digit);

if(digit==1)

printf("January");

else if (digit==2)
{

printf("February");

else if (digit==3)

printf("March");

else if (digit==4)

printf("April");

else if (digit==5)

printf("May");

else if (digit==6)

printf("June");

else if (digit==7)

printf("July");

else if (digit==8)

printf("August");

else if (digit==9)

{
printf("September");

else if (digit==10)

printf("October");

else if (digit==11)

printf("November");

else if (digit==12)

printf("December");

else

(digit==0||digit>=13);

printf("This program is only for 1 to 12 digit");

return 0;

23. Write a program in C to read any Month Number in integer and display Month
name in the word. Go to the editor
Test Data :
4
Expected Output :
April
Click me to see the solution
And

24. Write a program in C to read any Month Number in integer and display the
number of days for this month. Go to the editor
Test Data :
7
Expected Output :
Month have 31 days
Answer:

#include <stdio.h>

int main()

int digit;

printf("Enter the digit to get Month & Days : ");

scanf("%d",&digit);

if(digit==1)

printf("January , 31 days ");

else if (digit==2)

printf("February , 28 days");

else if (digit==3)

printf("March , 31 days");
}

else if (digit==4)

printf("April , 30 days");

else if (digit==5)

printf("May, 31 days");

else if (digit==6)

printf("June, 30 days");

else if (digit==7)

printf("July, 31 days");

else if (digit==8)

printf("August, 31 days");

else if (digit==9)

printf("September, 30 days");

else if (digit==10)

printf("October, 31 days");

}
else if (digit==11)

printf("November, 30 days");

else if (digit==12)

printf("December, 31 days");

else

(digit==0||digit>=13);

printf("This program is only for 1 to 12 digit");

return 0;

As per switch case

#include <stdio.h>

int main()

int digit;

printf("Enter the number: ");

scanf("%d",&digit);

switch (digit)

{
case 1:

printf("January month have 31 days");

break;

case 2:

printf("February month have 28 days");

break;

case 3:

printf("March month have 31 days");

break;

case 4:

printf("April month have 30 days");

break;

case 5:

printf("May month have 31 days");

break;

case 6:

printf("June month have 30 days");

break;

case 7:

printf("July month have 31 days");

break;

case 8:
printf("August month have 31 days");

break;

case 9:

printf("September month have 30 days");

break;

case 10:

printf("October month have 31 days");

break;

case 11:

printf("November month have 30 days");

break;

case 12:

printf("December month have 31 days");

break;

default:

printf("Number is invalid.");

break;

return 0;

}
25. Write a program in C which is a Menu-Driven Program to compute the area of
the various geometrical shape. Go to the editor
Test Data :
1
5
Expected Output :
The area is : 78.500000

Answer:

#include <stdio.h>

int main()

int shape;

float r, l, b, h, area;

printf("Select the shape [circle(1), square(2), rectangle(3), triangle(4)] = ");

scanf("%d",&shape);

switch(shape)

//area of the circle

case 1:

printf("Enter the amount of r = ");

scanf("%f",&r);

area=3.14*r*r;

printf("Area of the circle is = %f ",area);

break;

//area of the triangle

case 2:

printf("Enter the amount of b & h = ");


scanf("%f %f",&b,&h);

area=0.5*(b*h);

printf("Area of the triangle is = %f ",area);

break;

//area of the rectangle

case 3:

printf("Enter the amount of l & b = ");

scanf("%f %f",&l,&b);

area=l*b;

printf("Area of the rectangle is = %f ",area);

break;

//area of the square

default :

printf("Enter the amount of l = ");

scanf("%f",&l);

area=4*l;

printf("Area of the square is = %f ",area);

return 0;

}
26. Write a program in C which is a Menu-Driven Program to perform a simple
calculation. Go to the editor
Test Data :
10
2
3
Expected Output :
The Multiplication of 10 and 2 is: 20

Answer
#include <stdio.h>

int main()

int num1,num2,option,add,subs,multi,division ;

printf("Select the option from the below \n addition (1) \n substraction (2) \n multiplication
(3) \n division (4) \n select option = ");

scanf("%d", &option);

switch(option)

//Addition

case 1:

printf("Enter the 1st digit = " );

scanf("%d",&num1);

printf("Enter the 2nd digit = " );

scanf("%d",&num2);

add=num1+num2;

printf("Addition of the 2 number is = %d ",add);

break;

//Substraction

case 2:
printf("Enter the 1st digit = ");

scanf("%d",&num1);

printf("Enter the 2nd digit = ");

scanf("%d",&num2);

subs=num1-num2;

printf("Substraction of the 2 number is = %d ",subs);

break;

//Multiplication

case 3:

printf("Enter the 1st digit = ");

scanf("%d",&num1);

printf("Enter the 2nd digit = ");

scanf("%d",&num2);

multi=num1*num2;

printf("Multiplication of the 2 number is = %d ",multi);

break;

//Division

case 4 :

printf("Enter the 1st digit = ");

scanf("%d",&num1);

printf("Enter the 2nd digit = ");

scanf("%d",&num2);

division=num1/num2;

printf("Division of the 2 number is = %d ",division);

break;

default :
printf("This program is only for Addition, Substraction, Multiplication, Division.");

break;

return 0;

You might also like