C Assignment 1
C Assignment 1
int a,b,c;
printf("enter the number");
scanf("%d %d",&a,&b);
c=a+b;
printf("sum of two number %d",c);
}
3. Write a C program to enter two numbers and perform all arithmetic operations.
#include<stdio.h>
main()
{
int a,b,c;
printf("enter the number");
scanf("%d %d",&a,&b);
c=a+b;
printf(" addition is %d",c);
c=a-b;
printf("\n subtraction is %d",c);
c=a*b;
printf("\n multiplication is %d",c);
c=a/b;
printf("\n division is %d",c);
c=a%b;
printf("\n remainder is %d ",c);
}
4. Write a C program to enter length and breadth of a rectangle and find its
perimeter.
#include<stdio.h>
main()
{
int l,b,p;
printf("Enter length");
scanf("%d",&l);
printf("\nEnter breadth");
scanf("%d",&b);
p=2*(l+b);
MONIKA JAGADALE
printf("Perimeter of rectangle %d",p);
}
5. Write a C program to enter length and breadth of a rectangle and find its area.
#include<stdio.h>
main()
{
int l,b,p;
printf("Enter length");
scanf("%d",&l);
printf("\nEnter breadth");
scanf("%d",&b);
p=2*(l+b);
printf("Perimeter of rectangle %d",p);
}
6. Write a C program to enter radius of a circle and find its diameter, circumference
and area.
#include<stdio.h>
main()
{
int l,b,area;
printf("\nEnter length:");
scanf("%d",&l);
printf("\nEnter Breadth:");
scanf("%d",&b);
area=l*b;
printf("\n Area of Rectangle:%d",area);
}
7. Write a C program to enter length in centimeter and convert it into meter and
kilometer.
#include<stdio.h>
main()
{
double len;
double m,km;
printf("centikmeter");
scanf("%lf",&len);
m=len/100;
MONIKA JAGADALE
printf("meter=%lf",m);
km=len/100000;
printf("\nkilometre=%lf",km);
}
8. Write a C program to enter temperature in Celsius and convert it into Fahrenheit.
#include<stdio.h>
main()
{
float temp,faren;
printf("Enetr temperature in celcius:");
scanf("%f",&temp);
faren=temp*(1.8)+32;
printf("\ntemperature =%f farenheit",faren);
}
9. Write a C program to enter temperature in Fahrenheit and convert to Celsius
#include<stdio.h>
main()
{
float temp,cels;
printf("Enetr temperature in farenheit:");
scanf("%f",&temp);
cels=(temp-32)/(1.8);
printf("\ntemperature =%f celsius",cels);
}
10. Write a C program to convert days into years, weeks and days.
#include<stdio.h>
int main()
{
int day,year,week,days;
printf("Enter NO.days");
scanf("%d",&day);
year=day/365;
week=(day-(year*365))/7;
days=day-((year*365)+(week*7));
printf("\n%dyear,%dweek,%dday",year,week,days);
}
11. Write a C program to find power of any number x ^ y.
MONIKA JAGADALE
#include<stdio.h>
main()
{
int i,base,expo,s=1,g;
printf("\nEnter Base");
scanf("%d",&base);
printf("\nEnter Exponent");
scanf("%d",&expo);
for(i=1;i<=expo;i++)
{
g=base;
s=s*g;
}
printf("\nRESULT:%d^%d=%d",base,expo,s);
}
12. Write a C program to enter any number and calculate its square root.
#include<stdio.h>
main()
{
int i,n;
printf("\nEnter number");
scanf("%d",&n);
i=n*n;
printf("\nSquare Root of %d is %d",n,i);
}
13. Write a C program to enter two angles of a triangle and find the third angle.
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter angle-1");
scanf("%d",&a);
printf("Enter angle-2");
scanf("%d",&b);
c=180-(a+b);
MONIKA JAGADALE
printf("Third Angle is %d",c);
}
14. Write a C program to enter base and height of a triangle and find its area.
#include<stdio.h>
main()
{
float h,b,area;
printf("\nEnter Height");
scanf("%f",&h);
printf("\nEnter Base");
scanf("%f",&b);
area=(h*b)/2;
printf("\nArea of Triangle:%f",area);
}
15. Write a C program to calculate area of an equilateral triangle.
#include<stdio.h>
#include<math.h>
main()
{
float area,a;
printf("\nEnter side(a):");
scanf("%f",&a);
area=(sqrt(3)/4)*(a*a);
printf("\nArea of Equilatral triangle is:%f",area);
}
16. Write a C program to enter marks of five subjects and calculate total, average
and percentage.
#include<stdio.h>
main()
{
float a,b,c,d,e;
float total,avg,percent;
printf("\nEnter English Marks:");
scanf("%f",&a);
printf("\nEnter Hindi Marks:");
scanf("%f",&b);
MONIKA JAGADALE
printf("\nEnter Marathi Marks:");
scanf("%f",&c);
printf("\nEnter Maths Marks:");
scanf("%f",&d);
printf("\nEnter Science Marks:");
scanf("%f",&e);
total=a+b+c+d+e;
avg=(a+b+c+d+e)/5;
percent=(total/5)*100;
printf("\nTotal=%f",total);
printf("\nAverage=%f",avg);
printf("\nPercentage=%f",percent);
}
17. Write a C program to enter P, T, R and calculate Simple Interest.
#include<stdio.h>
main()
{
float p,t,r;
float si;
printf("\nEnter Principle:");
scanf("%f",&p);
printf("\nEnter Time:");
scanf("%f",&t);
printf("\nEnter Rate:");
scanf("%f",&r);
si=(p*t*r)/100;
printf("\nSimple Interest:%f",si);
}
18. Write a C program to enter P, T, R and calculate Compound Interest.
#include<stdio.h>
#include<math.h>
main()
{
float p,t,r;
float ci;
printf("\nEnter Principle:");
scanf("%f",&p);
MONIKA JAGADALE
printf("\nEnter Time:");
scanf("%f",&t);
printf("\nEnter Rate:");
scanf("%f",&r);
ci=p*pow(1+(r/100),t);
printf("\nCompound Interest:%f",ci);
}
if(n>0)
MONIKA JAGADALE
{
printf("\n%d is positive number",n);
}
else if(n<0)
{
printf("\n%d is Negative Number",n);
}
else
{
printf("\n%d is Zero",n);
}
}
4. Write a C program to check whether a number is divisible by 5 and 11 or not.
#include<stdio.h>
main()
{
int n;
printf("Enter Number");
scanf("%d",&n);
if(y%2==0)
{
printf("\n%d is Leap Year",y);
}
else
{
printf("\n%d is not Leap Year",y);
}
}
7. Write a C program to check whether a character is alphabet or not.
#include<stdio.h>
main()
{
char a;
printf("Enter Character");
scanf("%c",&a);
if(wn==1)
{
printf("\nMONDAY");
}
else if(wn==2)
{
printf("\nTUESDAY");
}
else if(wn==3)
{
printf("\nWEDENSDAY");
}
else if(wn==4)
{
printf("\nTHURSDAY");
}
else if(wn==5)
{
printf("\nFRIDAY");
}
else if(wn==6)
{
printf("\nSATURSDAY");
}
else if(wn==7)
{
printf("\nSUNDAY");
}
else
{
printf("\n is Invalid Input");
}
}
12. Write a C program to input month number and print number of days in that month.
#include<stdio.h>
MONIKA JAGADALE
main()
{
int n;
printf("Enter Month Number");
scanf("%d",&n);
if(n==1)
{
printf("\nMonth=Januray & days=31");
}
else if(n==2)
{
printf("\nMonth=February & days=28(Common Year) & days=29(Leap
Year)");
}
else if(n==3)
{
printf("\nMonth=March & days=31");
}
else if(n==4)
{
printf("\nMonth=April & days=30");
}
else if(n==5)
{
printf("\nMonth=May & days=31");
}
else if(n==6)
{
printf("\nMonth=June & days=30");
}
else if(n==7)
{
printf("\nMonth=July & days=31");
}
else if(n==8)
{
MONIKA JAGADALE
printf("\nMonth=August & days=31");
}
else if(n==9)
{
printf("\nMonth=September & days=30");
}
else if(n==10)
{
printf("\nMonth=October& days=31");
}
else if(n==11)
{
printf("\nMonth=November & days=30");
}
else if(n==12)
{
printf("\nMonth=December & days=31");
}
else
{
printf("\n is Invalid Input");
}
}
13. Write a C program to count total number of notes in given amount.
#include<stdio.h>
main()
{
int amt,n2000,n500,n200,n100,n50,n20,n10;
printf("Enter Amount");
scanf("%d",&amt);
n2000=n500=n200=n100=n50=n20=n10=0;
if(amt>=2000)
{
n2000=amt/2000;
amt=n2000*2000;
}
MONIKA JAGADALE
if(amt>=500)
{
n500=amt/500;
amt=n500*500;
}
if(amt>=200)
{
n200=amt/200;
amt=n200*200;
}
if(amt>=100)
{
n100=amt/100;
amt=n100*100;
}
if(amt>=50)
{
n50=amt/50;
amt=n50*50;
}
if(amt>=20)
{
n20=amt/20;
amt=n20*20;
}
if(amt>=10)
{
n10=amt/10;
amt=n10*10;
}
printf("\n2000 Ruppee Note:%d",n2000);
printf("\n500 Ruppee Note:%d",n500);
printf("\n200 Ruppee Note:%d",n200);
printf("\n100 Ruppee Note:%d",n100);
printf("\n50 Ruppee Note:%d",n50);
printf("\n20 Ruppee Note:%d",n20);
printf("\n10 Ruppee Note:%d",n10);
MONIKA JAGADALE
}
14. Write a C program to input angles of a triangle and check whether triangle is valid or
not.
#include<stdio.h>
main()
{
int a,b,c,sum;
printf("Enter a");
scanf("%d",&a);
printf("Enter b");
scanf("%d",&b);
printf("Enter c");
scanf("%d",&c);
sum=a+b+c;
if(sum==180)
{
printf("\nThis the Valid Triangle");
}
else
{
printf("\nThis the Not a Valid Triangle");
}
}
15. Write a C program to input all sides of a triangle and check whether triangle is valid
or not.
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter a");
scanf("%d",&a);
printf("Enter b");
scanf("%d",&b);
printf("Enter c");
MONIKA JAGADALE
scanf("%d",&c);
if((a+b)>c)
{
if((b+c)>a)
{
if((a+c)>b)
{
printf("\nThis the Valid Triangle");
}
}
}
else
{
printf("\nThis the Not a Valid Triangle");
}
}
16. Write a C program to check whether the triangle is equilateral, isosceles or scalene
triangle.
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter a");
scanf("%d",&a);
printf("Enter b");
scanf("%d",&b);
printf("Enter c");
scanf("%d",&c);
if((a==b)&&(b==c)&&(c==a))
{
printf("\n TRIANGLE IS EQUILATERAL TRIANGLE");
}
MONIKA JAGADALE
if((a==b)||(b==c)||(c==a))
{
printf("\n TRIANGLE IS ISOSCELES TRIANGLE");
}
if((a!=b)&&(b!=c)&&(c!=a))
{
printf("\n TRIANGLE IS SCALENE TRIANGLE");
}
else
{
printf("\nThis the Not a Valid Triangle");
}
}
17. Write a C program to find all roots of a quadratic equation.
#include<stdio.h>
#include<math.h>
main()
{
float a,b,c;
float discriminant;
float r1,r2,im,i;
printf("Enter a");
scanf("%d",&a);
printf("Enter b");
scanf("%d",&b);
printf("Enter c");
scanf("%d",&c);
discriminant=(b*b)-(4*a*c);
if(discriminant>0)
{
r1=(-b+sqrt(discriminant))/2*a;
r2=(-b-sqrt(discriminant))/2*a;
printf("\nTWO DISTINCT & REAL EXISTS:%2f & %2f",r1,r2);
}
else if(discriminant==0)
MONIKA JAGADALE
{
r1=r2=-b/(2*a);
printf("\nTWO EQUAL & REAL ROOTS EXISTS:%2f & %2f",r1,r2);
}
else if(discriminant<0)
{
r1=r2=-b/(2*a);
i=sqrt(-discriminant)/(2*a);
printf("\nTWO DISTICT AND COMPLEX ROOTS EXISTS:%2f+i%2f&%2f-
i&2f",r1,im,r2,im);
}
}
18. Write a C program to calculate profit or loss.
#include<stdio.h>
main()
{
int sp,cp,profit,loss;
printf("\nEnter Selling Price:");
scanf("%d",&sp);
printf("\nEnter Cost Price:");
scanf("%d",&cp);
profit=sp-cp;
loss=cp-sp;
if(profit>loss)
{
printf("\nIts A Profit",profit);
}
else
{
printf("\nIts A Loss",loss);
}
}
19. Write a C program to input marks of five subjects Physics, Chemistry, Biology,
Mathematics and Computer. Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
MONIKA JAGADALE
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
#include<stdio.h>
main()
{
float a,b,c,d,e;
float total,percent;
printf("\nEnter English Marks:");
scanf("%f",&a);
printf("\nEnter Hindi Marks:");
scanf("%f",&b);
printf("\nEnter Marathi Marks:");
scanf("%f",&c);
printf("\nEnter Maths Marks:");
scanf("%f",&d);
printf("\nEnter Science Marks:");
scanf("%f",&e);
total=a+b+c+d+e;
percent=(total/500)*100;
printf("\nPercentage=%f",percent);
if(percent>=90)
{
printf("\n GRADE A");
}
else if(percent>=80 && percent<=89)
{
printf("\n GRADE B");
}
if(percent>=70 && percent<=79)
{
printf("\n GRADE C");
}
if(percent>=60 && percent<=69)
{
printf("\n GRADE D");
}
if(percent>=40 && percent<=59)
MONIKA JAGADALE
{
printf("\n GRADE E");
}
if(percent<40)
{
printf("\n GRADE F");
}
else
{
printf("\nBetter Luck Next Time");
}
}
20. Write a C program to input basic salary of an employee and calculate its Gross
salary according to following:
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary <= 20000 : HRA = 25%, DA = 90%
Basic Salary > 20000 : HRA = 30%, DA = 95%
#include<stdio.h>
main()
{
float sal,da,hra,gross;
printf("Enter Salary:");
scanf("%d",&sal);
if(sal<=10000)
{
hra=sal*0.2;
da=sal*0.8;
}
else if(sal<=20000)
{
hra=sal*0.25;
da=sal*0.9;
}
else if(sal>20000)
{
hra=sal*0.3;
MONIKA JAGADALE
da=sal*0.95;
}
else
{
printf("\n");
}
gross=sal+da+hra;
printf("Gross Salary=%2f",gross);
}
21. Write a C program to input electricity unit charges and calculate total electricity bill
according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill
#include<stdio.h>
main()
{
float u,a,s,n;
printf("Enter Electricity Unit:");
scanf("%f",&u);
if(u<=50)
{
a=u*0.50;
}
else if(u<=150)
{
a=25+((u-50)*0.75);
}
else if(u<=250)
{
a=100+((u-150)*1.20);
}
else if(u>250)
{
a=220+((u-250)*1.50);
}
MONIKA JAGADALE
else
{
printf("\n");
}
s=a*0.20;
n=a+s;
printf("Your Total Electicity Bill=%2f",n);
}
}
}
5. Write a C program to check whether a number is even or odd using switch case.
#include<stdio.h>
main()
{
int a;
printf("Enter First Number:");
scanf("%d",&a);
switch(a%2==0)
{
case 1:
printf("\n%d is Even",a);
break;
MONIKA JAGADALE
case 0:
printf("\n%d is Odd",a);
break;
}
}
6. Write a C program to check whether a number is positive, negative or zero using
switch case.
#include<stdio.h>
main()
{
int a;
printf("Enter First Number:");
scanf("%d",&a);
switch(a>0)
{
case 1:
printf("\n%d is Positive Number",a);
break;
case 0:
switch(a<0)
{
case 1:
printf("%d Is A Negative Number",a);
break;
case 0:
printf("%d Is A Zero",a);
break;
}
}
}
7. Write a C program to find roots of a quadratic equation using switch case .
#include<stdio.h>
#include<math.h>
main()
MONIKA JAGADALE
{
float a,b,c;
float discriminant;
float r1,r2,im,i;
printf("Enter a");
scanf("%d",&a);
printf("Enter b");
scanf("%d",&b);
printf("Enter c");
scanf("%d",&c);
discriminant=(b*b)-(4*a*c);
switch(discriminant>0)
{
case 1:
r1=(-b+sqrt(discriminant))/2*a;
r2=(-b-sqrt(discriminant))/2*a;
printf("\nTWO DISTINCT & REAL EXISTS:%2f & %2f",r1,r2);
break;
case 0:
switch(discriminant<0)
{
case 1:
r1=r2=-b/(2*a);
i=sqrt(-discriminant)/(2*a);
printf("\nTWO DISTICT AND COMPLEX ROOTS EXISTS:
%2f+i%2f&%2f-i&2f",r1,im,r2,im);
break;
case 0:
r1=r2=-b/(2*a);
printf("\nTWO EQUAL & REAL ROOTS EXISTS:%2f &
%2f",r1,r2);
break;
}
}
MONIKA JAGADALE
}
8. Write a C program to create Simple Calculator using switch case .
#include<stdio.h>
main()
{
int a,b,c,choice;
printf("Enter First Number:");
scanf("%d",&a);
printf("Enter Second Number:");
scanf("%d",&b);
printf("1.Add \t2.Sub \t3.Mult \t4.Div \t5.Rem");
printf("\nEnter Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
c=a+b;
printf("addition of %d and %d is %d",a,b,c);
break;
case 2:
c=a-b;
printf("subtraction of %d and %d is %d",a,b,c);
break;
case 3:
c=a*b;
printf("multiplication of %d and %d is %d",a,b,c);
break;
case 4:
c=a/b;
printf("division of %d and %d is %d",a,b,c);
break;
case 5:
c=a%b;
printf("remainder of %d and %d is %d",a,b,c);
break;
}
MONIKA JAGADALE