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.


a.     read x
b.     read y
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;
}


Comments

Dee comment

 Dee

#include <stdio.h>
#include<stdlib.h>
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 comment

 Shri Sharad Anant Neman

#include<stdio.h>
#include<conio.h>
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 comment

 dheeraj patel

#include<stdio.h>
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 comment

 ler

#include <stdio.h>
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



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.