﻿ 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;
}