PPC Lab2
PPC Lab2
#include <stdio.h>
int main()
{
int dividend, divisor, quotient, remainder;
printf("Enter dividend: ");
scanf("%d", ÷nd);
printf("Enter divisor: ");
scanf("%d", &divisor);
// Computes quotient
quotient = dividend / divisor;
// Computes remainder
remainder = dividend % divisor;
Output
Enter dividend: 25
Enter divisor: 4
Quotient = 6
Remainder = 1
#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
#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;
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);
subtotal=quantity*unitprice;
discountamt=subtotal*discountrate/100;
subtaxable=subtotal-discountamt;
taxam=subtaxable*TAX_RATE/100;
total=subtaxable+taxam;
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;
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;
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