C Programming BCA Practical Slips Solution
Slip11
Q1. Write a C program to accept the cost price and selling price from the user. Find out if
the seller has made a profit or loss and display how much profit or loss has been made.
[15 Marks]
#include <stdio.h>
int main()
{
int cp,sp, amt;
/* Input cost price and selling price of a product */
printf("Enter cost price: ");
scanf("%d", &cp);
printf("Enter selling price: ");
scanf("%d", &sp);
if(sp > cp)
{
/* Calculate Profit */
amt = sp - cp;
printf("Profit = %d", amt);
}
else if(cp > sp)
{
/* Calculate Loss */
amt = cp - sp;
printf("Loss = %d", amt);
}
else
{
/* Neither profit nor loss */
printf("No Profit No Loss.");
}
return 0;
}
Q2. Accept radius from the user and write a program having menu with the following
options and corresponding actions [25 Marks]
Options Actions
1. 1. Area of Circle Compute area of circle and print
2. Circumference of Circle Compute Circumference of circle and print
3. Volume of Sphere Compute Volume of Sphere and print
#include<stdio.h>
void main()
{
int r,choice;
float area,c,vol,PI= 3.142;
printf("\n Enter the radius of circle:- ");
scanf("%d",&r);
printf("\n Please make a choice from the following :");
printf("\n \n Options:\t \t \t \t");
printf("Actions:");
printf("\n \n 1. Area of the circle :");
printf("\t \tCompute area of the circle and print");
printf("\n \n 2. Circumference of the circle ");
printf("\tCompute circumference of circle and print");
printf("\n \n 3. Area of the sphere ");
printf("\t \t Compute volume of sphere and print \n \n ");
scanf("%d",&choice);
switch(choice)
{
case 1:
area=PI*r*r;
printf("\n The area of the circle is %f \n \n",area);
break;
case 2:
c=2*PI*r;
printf("\n The circumference of the circle is %f \n \n",c);
break;
case 3:
vol=(4/3)*PI*r*r;
printf("\n The volume of the sphere is %f \n \n",vol);
break;
default:
printf("\n You haven made invalid choice \n \n");
}
} // End of the code
No comments:
Post a Comment