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

PPC Lab2

Uploaded by

1ayusharun1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

PPC Lab2

Uploaded by

1ayusharun1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

a) C-Program to calculate quotient and reminder of two numbers

#include <stdio.h>
int main()
{
int dividend, divisor, quotient, remainder;
printf("Enter dividend: ");
scanf("%d", &dividend);
printf("Enter divisor: ");
scanf("%d", &divisor);

// Computes quotient
quotient = dividend / divisor;

// Computes remainder
remainder = dividend % divisor;

printf("Quotient = %d\n", quotient);


printf("Remainder = %d", remainder);
return 0;
}

Output
 Enter dividend: 25
 Enter divisor: 4
 Quotient = 6
 Remainder = 1

b) C-Program to evaluate two complex expressions.

#include<stdio.h>
int main()
{
//local declarations
int a=3;
int b=4;
int c=5;
int x;
int y;

//statements
printf("initial values of variables:\n");
printf("a=%d\tb=%d\tc=%d\n\n",a,b,c);
x=a*4+b/2-c*b;
printf("value of the expression a*4+b/2-c*b :%d\n",x);
y=--a*(3+b)/2-c++*b;
printf("value of the expression --a*(3+b)/2-c++*b :%d\n",y);
printf("values of variables are now:\n");
printf("a=%d\tb=%d\tc=%d\n\n",a,b,c);
return 0;
}
Output
initial values of variables:
a=3 b=4 c=5

 value of the expression a*4+b/2-c*b :-6


 value of the expression --a*(3+b)/2-c++*b :-13
values of variables are now:
a=2 b=4 c=6
c) C-Program to demonstrate automatic and type casting of numeric

#include<stdio.h>
#include<stdbool.h>
int main()
{
//local declarations
bool b=true;
char c='A';
float d=245.3;
int i=3650;
short s=78;

//statements
printf("bool+char is char:%c\n",b+c);
printf("int * short is int: %d\n",i*s);
printf("float * char is float: %f\n",d*c);

c=c+b;
d=d+c;
b=false;
b=-d;

printf("\n After execution...\n");


printf("char +true: %c\n",c);
printf("float +char :%f\n",d);
printf("bool =-float:%f\n",b);

return 0;
}

Output
bool+char is char:B
int * short is int: 284700
float * char is float: 15944.500000

After execution...
char +true: B
float +char :311.299988
bool =-float:311.299988

d) C-Program to calculate the total sales given the unit price, quantity, discount and tax rate

#include<stdio.h>
#define TAX_RATE 8.50
int main()
{
//local declarations
int quantity;
float discountrate;
float discountamt;
float unitprice;
float subtotal;
float subtaxable;
float taxam;
float total;

//statements
printf("enter the number of items sold:\n");
scanf("%d",&quantity);

printf("enter the unit price:\n");


scanf("%f",&unitprice);
printf("enter the discount rate(percent):\n");
scanf("%f",&discountrate);

subtotal=quantity*unitprice;
discountamt=subtotal*discountrate/100;
subtaxable=subtotal-discountamt;
taxam=subtaxable*TAX_RATE/100;
total=subtaxable+taxam;

printf("\n quantity sold: %6d\n",quantity);


printf("unit price of items : %9.2f\n",unitprice);
printf(" --------------\n");

printf("subtotal : %9.2f\n",subtotal);
printf("discount : %-9.2f\n",discountamt);
printf("discount total: %9.2f\n",subtaxable);
printf("sales tax: %+9.2f\n",taxam);
printf("Totsl sales: %9.2f\n",total);

return 0;
}

Output
enter the number of items sold:
5
enter the unit price:
10
enter the discount rate(percent):
10
quantity sold: 5
unit price of items : 10.00
--------------
subtotal : 50.00
discount : 5.00
discount total: 45.00
sales tax: +3.83
Totsl sales: 48.83
e) C-Program to calculate a student’s average score for a course with 4 quizzes, 2 midterms
and a final. The quizzes are weighted 30%, the midterms 40% and the final 30%.
#include<stdio.h>
#define QUIZ_WEIGHT 30
#define MIDTERM_WEIGHT 40
#define FINAL_WEIGHT 30
#define QUIZ_MAX 400.00
#define MIDTERM_MAX 200.0
#define FINAL_MAX 100.00

int main()
{
int quiz1,quiz2,quiz3,quiz4,totalquiz;
int midterm1,midterm2,totalmidterm,final;
float quizpercent,midtermpercent,finalpercent,totalpercent;

printf("Enter the score of first quiz:");


scanf("%d",&quiz1);
printf("Enter the score of second quiz:");
scanf("%d",&quiz2);
printf("Enter the score of third quiz:");
scanf("%d",&quiz3);
printf("Enter the score of fourth quiz:");
scanf("%d",&quiz4);

printf("enter the score of first midterm:");


scanf("%d",&midterm1);
printf("enter the score of seconf midterm:");
scanf("%d",&midterm2);
printf("enter the score of Final:");
scanf("%d",&final);

totalquiz=quiz1+quiz2+quiz3+quiz4;
totalmidterm=midterm1+midterm2;

quizpercent=(float)totalquiz*QUIZ_WEIGHT/QUIZ_MAX;
midtermpercent=(float)totalmidterm*MIDTERM_WEIGHT/MIDTERM_MAX;
finalpercent=(float)final*FINAL_WEIGHT/FINAL_MAX;
totalpercent=quizpercent+midtermpercent+finalpercent;

printf(" quiz 1:%d\n",quiz1);


printf(" quiz 2:%d\n",quiz2);
printf(" quiz 3:%d\n",quiz3);
printf(" quiz 4:%d\n",quiz4);
printf(" quiz total:%d\n",totalquiz);
printf("midterm 1:%4d\n",midterm1);
printf("midterm 2:%4d\n",midterm2);
printf("midterm total:%4d\n",totalmidterm);
printf("Final :%4d\n",final);
printf("quiz %6.1lf\n",quizpercent);
printf("midterm %6.1lf\n",midtermpercent);
printf("final %6.1lf\n",finalpercent);
printf("total %6.1lf\n",totalpercent);
return 0;
}

Output
Enter the score of first quiz:98
Enter the score of second quiz:89
Enter the score of third quiz:78
Enter the score of fourth quiz:79
enter the score of first midterm:90
enter the score of seconf midterm:100
enter the score of Final:92
quiz 1:98
quiz 2:89
quiz 3:78
quiz 4:79
quiz total:344
midterm 1: 90
midterm 2: 100
midterm total: 190
Final : 92
quiz 25.8
midterm 38.0
final 27.6
total 91.4

You might also like