0% found this document useful (0 votes)
15 views25 pages

Assignment 4 PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views25 pages

Assignment 4 PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//Write a C program to find maximum between two numbers.

#include<stdio.h>

void main()

int a,b;

printf("enter two number:");

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

if(a>b)

printf("maximum no. is a:%d", a);

else

printf("maximum no. is b:%d", b);

}
//Write a C program to find maximum between three numbers.

#include<stdio.h>

void main()

int a,b,c;

printf("enter three number:");

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

if(a>b && a>c)

printf("maximum no. is a:%d", a);

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

printf("maximum no. is b:%d", b);

else

printf("maximum no. is c:%d", c);

}
//Write a C program to check whether a number is even or odd.

#include<stdio.h>

void main()

int n,e;

printf("enter the number:");

scanf("%d", &n);

if(n%2==0)

printf("number is even");

else

printf("number is odd");

}
//write a C program to check whether a year is leap year or not.

#include<stdio.h>

void main()

int year;

printf("enter a year:");

scanf("%d", &year);

if((year%100!=0)&&(year%4==0||year%400==0))

printf("year is leap year");

else

printf("year is not leap year");

}
//Write a C program to check whether a number is negative, positive or zero.

#include<stdio.h>

void main()

int n;

printf("enter the number:");

scanf("%d", &n);

if(n>0)

printf("number is positive");

else if(n<0)

printf("number is negetive");

else

printf("number is zero");

}
//Write a C program to check whether a number is divisible by 5 and 11 or not.

#include<stdio.h>

void main()

int n;

printf("enter the number:");

scanf("%d", &n);

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

printf("number is divisible");

else

printf("number is not divisible");

}
//Write a C program to input week number and print week day.

#include<stdio.h>

void main()

int wn;

printf("enter weak number(1-7):");

scanf("%d", &wn);

if(wn==1)

printf("Monday\n");

else if(wn==2)

printf("Tuesday\n");

else if(wn==3)

printf("Wednesday\n");

else if(wn==4)

printf("Thursday\n");
}

else if(wn==5)

printf("Friday\n");

else if(wn==6)

printf("Saturday\n");

else if(wn==7)

printf("Sunday\n");

else

printf("invalid weak number:please enter a weak number between 1 and 7.\n");

}
//Write a C program to input month number and print number of days in that month.

#include<stdio.h>

void main()

int mn;

printf("enter month number(1-12):");

scanf("%d", &mn);

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

printf("31 Days.\n");

else if(mn==2)

printf("28 or 29 Days (depending on leap year).\n");

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

printf("30 days.\n");

else

printf("invalid month.\n");

}
}

//Write a C program to input angles of a triangle and check whether triangle is valid or not.

#include<stdio.h>

void main()

int angle1,angle2,angle3,s;

printf("enter three angles of triangle:");

scanf("%d %d %d", &angle1,&angle2,&angle3);

s=angle1+angle2+angle3;

if(s==180 && angle1>0 && angle2>0 && angle3>0)

printf("The triangle is valid.\n");

else

printf("The triangle is invalid.\n");

}
//Write a C program to input all sides of a triangle and check whether triangle is valid or not.

#include<stdio.h>

void main()

float side1,side2,side3;

printf("enter the length of three sides");

scanf("%d %d %d", &side1,&side2,&side3);

if(side1+side2>side3 && side2+side3>side1 && side1+side3>side2)

printf("The triangle is valid");

else

printf("The triangle is invalid");

}
//Write a C program to check whether the triangle is equilateral, isosceles or scalene triangle.

#include<stdio.h>

void main()

int s1,s2,s3;

printf("enter length of three sides of triangle:\n");

scanf("%d %d %d", &s1,&s2,&s3);

if(s1==s2 && s2==s3)

printf("The triangle is an equilateral triangle.\n");

else if(s1==s2 || s2==s3 || s3==s1)

printf("The triangle is an isosceles triangle.\n");

else

printf("The triangle is a scalene triangle.\n");

}
//Write a C program to find all roots of a quadratic equation.

#include<stdio.h>

#include<math.h>

void main()

float a,b,c,D,r1,r2,rp,ip;

printf("enter the values of a,b and c:");

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

D=b*b-4*a*c;

if(D>0)

r1=(-b+sqrt(D))/(2*a);

r2=(-b-sqrt(D))/(2*a);

printf("root are real and distinct:\n %.2f %.2f",r1,r2);

else if(D==0)

r1=r2=-b/(2*a);

printf("roots are real and equal:\n %.2f",r1);

}
else

rp=-b/(2*a);

ip=sqrt(-D)/(2*a);

printf("Roots are complex and imaginary:\n");

printf("r0ot1=%.2f+%.2f\n",rp,ip);

printf("root2=%.2f-%.2f\n",rp,ip);

}
//Write a C program to calculate profit or loss.

#include<stdio.h>

void main()

float CP,SP,P,L;

printf("Enter Cost Price and Selling Price:");

scanf("%f %f", &CP,&SP);

if(SP>CP)

P=SP-CP;

printf("Profit:%.2f\n",P);

else if(CP>SP)

L=CP-SP;

printf("Loss:%.2f\n",L);

else

printf("No Profit, No Loss\n");

}
//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

//Percentage >= 40%: Grade E

//Percentage < 40%: Grade F

#include<stdio.h>

void main()

int Ph,Ch,B,M,C;

float P;

printf("Enter marks of five subjects:");

scanf("%d %d %d %d %d",&Ph,&Ch,&B,&M,&C);

P=(float)(Ph+Ch+B+M+C)/5.0;

printf("Percentage = %.2f\n",P);

if(P>= 90)

printf("Grade A\n");

else if(P>= 80)

{
printf("Grade B\n");

else if(P>= 70)

printf("Grade C\n");

else if(P>= 60)

printf("Grade D\n");

else if(P>= 40)

printf("Grade E\n");

else

printf("Grade F\n");

}
//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 >= 30000: HRA = 30%, DA = 95%

#include<stdio.h>

void main() {

float basic_salary, gross_salary, HRA, DA;

printf("Enter the basic salary of the employee: ");

scanf("%f", &basic_salary);

if (basic_salary >= 30000)

HRA = 0.30 * basic_salary;

DA = 0.95 * basic_salary;

else if(basic_salary >= 20000)

HRA = 0.25 * basic_salary;

DA = 0.90 * basic_salary;

else if (basic_salary >= 10000)

HRA = 0.20 * basic_salary;


DA = 0.80 * basic_salary;

else

HRA = 0;

DA = 0;

printf("Note: For basic salary less than 10000, HRA and DA are set to 0 in this example.\n");

gross_salary = basic_salary + HRA + DA;

printf("Basic Salary: %.2f\n", basic_salary);

printf("HRA: %.2f\n", HRA);

printf("DA: %.2f\n", DA);

printf("Gross Salary: %.2f\n", gross_salary);

You might also like