﻿ C exercises and solutions: C operators (con)

C exercises and solutions: C operators (con)

C operators exercises (con.)

1. Write C code to generate the results as shown below:

Results:
=======Quizzes===============
Enter the score of the first quiz: 90
Enter the score of the second quiz: 75
Enter the score of the third quiz: 91
=======Mid-term==============
Enter the score of the mid-term: 80
=======Final=================
Enter the score of the final: 89

Quiz Total:      256
Mid-term :       80
Final        :       89
……………………
Total: 425

Solution:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

float q1;
float q2;
float q3;
float qtotal;
float midterm;
float final;
float total;
printf("==========QUIZZES================\n");
printf("Enter the score of the first quizz:");
scanf("%f",&q1);
printf("\n");
printf("Enter the score of the second quizz:");
scanf("%f",&q2);
printf("\n");
printf("Enter the score of the third quizz:");
scanf("%f",&q3);
printf("\n");
printf("==========MID-TERM==============\n");
printf("Enter the score of the mid-term:");
scanf("%f",&midterm);
printf("\n");
printf("===========FINAL================\n");
printf("Enter the score of the final:");
scanf("%f",&final);
printf("\n");
qtotal=q1+q2+q3;
total=qtotal+midterm+final;
printf("Quizz Total:%5.2f",qtotal);
printf("\n");
printf("Mid term:%9.2f",midterm);
printf("\n");
printf("Final:%12.2f",final);
printf("\n");
printf(".................................\n");
printf("Total:%12.2f",total);
printf("\n");

system("PAUSE");
return 0;
}

2. Given the following pseudo code, write a program that executes it.

c.      compute p=x*y
d.     compute s=x+y
e.      total=s2+p*(s-x)*(p+y)
f.       print total Solution:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

float x;
float y;
float p;
float s;
float total;
printf("Enter x value:");
scanf("%f",&x);
printf("\n");
printf("Enter y value:");
scanf("%f",&y);
printf("\n");
p=x*y;
s=x+y;
total=s*s+p*(s-x)*(p+y);
printf("Total:%.2f",total);
printf("\n");

system("PAUSE");
return 0;
} Dee#include #include int main() { float x,y,p,s,total; printf("read x:"); scanf("%f",&x); printf("read y:"); scanf("%f",&y); p=x*y; s=x+y; total=s*s+p*(s-x)*(p+y); printf("Solution:%.2f\n",total); return 0; }2017-03-20 Shri Sharad Anant Neman#include #include main() { int a,b,c,d,e; printf("==========Quizzes============================\n"); printf("Enter the Score of the first quiz: "); scanf("%d",&a); printf("Enter the Score of the second quiz: "); scanf("%d",&b); printf("Enter the Score of the third quiz: "); scanf("%d",&c); printf("==========Mid-term===========================\n"); printf("Enter the Score of the mid-term: "); scanf("%d",&d); printf("==========Final===============================\n"); printf("Enter the Score of the final: "); scanf("%d",&e); printf("Quiz Total: %d\n",a+b+c); printf("Mid-term: %d\n",d); printf("Final: %d\n",e); printf(".................\n"); printf("Total: %d",a+b+c+d+e); getch(); } printf("Quizz Total:%5.2f",qtotal); Why %5.2f used in first exercise?2017-02-09 dheeraj patel#include int main() { int x,y,p,s,total; printf("read "); scanf("%d",&x); printf("read "); scanf("%d",&y); p=x*y; s=x+y; total=s*s+p*(s-x)*(p+y); printf("%d",total); return 0; } 2015-09-08 ler#include int main() { int x, y, s, p, total; printf("read x: "); scanf("%d", &x); printf("\n"); printf("read y: "); scanf("%d", &y); printf("\n"); p=x*y; s=x+y; total=s*s+p*(s-p)*(p+y); printf("%d\n", total); return 0; } 2015-05-28