0% found this document useful (0 votes)
35 views

Lab Assignment 4

The document contains several C programs that demonstrate basic conditional logic and input/output operations. The programs include: checking if a number is positive or negative, even or odd, calculating profit/loss, finding the largest of three numbers, solving a quadratic equation, calculating exam results, displaying age-based remarks, and determining sales commission based on sales amount. A menu-based program is also included that allows the user to calculate the area or perimeter of a rectangle or exit the program.

Uploaded by

Bishal Shahi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Lab Assignment 4

The document contains several C programs that demonstrate basic conditional logic and input/output operations. The programs include: checking if a number is positive or negative, even or odd, calculating profit/loss, finding the largest of three numbers, solving a quadratic equation, calculating exam results, displaying age-based remarks, and determining sales commission based on sales amount. A menu-based program is also included that allows the user to calculate the area or perimeter of a rectangle or exit the program.

Uploaded by

Bishal Shahi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

 WAP to load a number and check whether it is positive or negative .

/*Program to check whether the number is positive or negative */


#include<stdio.h>
#include<conio.h>
int main()
{
int a;
printf("Enter the number: ");
scanf("%d",&a);
if(a>0)
{
printf("The number is positive");
}
else
{
printf("The number is negative");
}
return 0;
}
Output:

 WAP to check whether a number is odd or even.

/*Program to check whether the number is odd or even*/


#include<stdio.h>
#include<conio.h>
int main()
{
int a;
printf("Enter the number: ");
scanf("%d",&a);
if(a%2==0)
{
printf("The number is even");
}
else
{
printf("The number is odd");
}
return 0;
}
Output:

 WAP to read cost price and selling price of a good and find profit or loss amount.

/*Program to find profit or loss amount*/


#include<stdio.h>
#include<conio.h>
int main()
{
int CP,SP,Profit,Loss;
printf("Enter the cost price: ");
scanf("%d",&CP);
printf("Enter the selling price: ");
scanf("%d",&SP);
if(CP<SP)
{
Profit=SP-CP;
printf("The profit is %d",Profit);
}
else
{
Loss=CP-SP;
printf("The loss is %d",Loss);
}
return 0;
}
Output:
 WAP to find the largest among three numbers.

/*Program to find the largest number */


#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
printf("Enter the values of x,y and z: ");
scanf("%d%d%d",&x,&y,&z);
if(x>y&&x>z)
{
printf("%d is the largest",x);
}
else if(y>x&&y>z)
{
printf("%d is the largest",y);
}
else
{
printf("%d is the largest",z);
}
return 0;
}
Output:

 WAP to read the coefficients of a quadratic equation and find all its roots.

/*program to find roots of quadratic equation*/


#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int a,b,c,d,r1,r2;
printf("Enter the values of a,b and c: ");
scanf("%d%d%d",&a,&b,&c);
d=sqrt(pow(b,2)-4*a*c);
if((pow(b,2)-4*a*c)>=0)
{
r1=(-b+d)/(2*a);
r2=(-b-d)/(2*a);
printf("\n The roots of the equation are %d and %d ",r1,r2);
}
else
{
printf("\n There are no real roots");
}
return 0;
}
Output:

 WAP to read marks obtained in your final exam in all subjects and find total
marks, percentage, result and division.

/* Program to find total marks, percentage, result and division*/


#include<stdio.h>
#include<conio.h>
int main()
{
int phy,math,cp,dl,iit,total;
float p;
printf("Enter the marks obtained in phy, math, cp, dl and iit: ");
scanf("%d%d%d%d%d",&phy,&math,&cp,&dl,&iit);
total=phy+math+iit+cp+dl;
p= (float) total/5;
printf("\n The total marks obtained is %d",total);
printf("\n Percentage=%.2f",p);
if(phy>=40&&math>=40&&cp>=40&&dl>=40&&iit>=40)
{
printf("\n Result= PASS");
if(p>=60)
{
printf("\n First Division");
}
else if(p>=50)
{
printf("\n Second division");
}
else if(p>=40)
{
printf("\n Third division");
}
else
{
printf("\n FAIL");
}
}
else
{
printf("\n Result= FAIL");
}
return 0;

}
Output:

 WAP to read age of the person and display remarks accordingly.

Age Remarks
Age<12 Child
12<= age <20 Teen
20<= age <30 Adult
30<= age <55 Young
Age>=55 Old

/* Program to read age and display remarks*/

#include<stdio.h>
#include<conio.h>
int main()
{
int age;
printf("Enter the age of the person: ");
scanf("%d",&age);
if(age<12)
{
printf("\n Child");
}
else if(age>=12 && age<20)
{
printf("\n Teen");
}
else if(age>=20 && age<30)
{
printf("\n Adult");
}
else if(age>=30 && age<55)
{
printf("\n Young");
}
else
{
printf("\n Old");
}
return 0;
}
Output:

 WAP to find sales person commission on sales amount according to following


conditions.

Sales amount Commission


<5000 0%
>=5000 and <10000 5%
>=10000 and <15000 7%
>=15000 10%

/* Program to find commission on sales amount */


#include<stdio.h>
#include<conio.h>
int main()
{
int a,c;
printf("Enter the sales amount: ");
scanf("%d",&a);
if(a<5000)
{
c=0;
printf("\n The commission amount= %d",c);
}
else if(a>=5000 && a<10000)
{
c=(5*a)/100;
printf("\n The commission amount= %d",c);
}
else if(a>=10000 && a<15000)
{
c=0.07*a;
printf("\n The commission amount= %d",c);
}
else
{
c=0.1*a;
printf("\n The commission amount= %d",c);
}
return 0;
}
Output:

 Write a menu base program for:


1. Area of rectangle
2. Perimeter of rectangle
3. Exit

/* Menu based program */


#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
int main()
{
int a,l,b,p,choice;
printf("1. Area of rectangle \n2. Perimeter of rectangle \n3. Exit");
printf("\nEnter the length and breadth of rectangle: ");
scanf("%d%d",&l,&b);
printf("\n Enter your choice(1-3): ");
scanf("%d",&choice);
switch(choice)
{
case 1:
a=l*b;
printf("\nThe area of rectangle is %d",a);
break;
case 2:
p=2*(l+b);
printf("\n The perimeter of rectangle is %d",p);
break;
case 3:
break;
default:
printf("\n Exiting the program");
exit(0);
}

return 0;
}
Output:

You might also like