Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

WEEK 4

Objective: Explore the full scope of expressions, type-compatibility of variables &


constants and operators used in the expression and how operator precedence
works. Suggested Experiments/Activities:
Tutorial 4:Operators and the precedence and associativity:
Lab4: Simple computational problems using the operator’ precedence and
associativity

i) Evaluate the following expressions.


a. A+B*C+(D*E) + F*G
b. A/B*C-B+A*D/3
c. A+++B---A
d. J= (i++) + (++i)
ii) Find the maximum of three numbers using conditional operator
iii) Take marks of 5 subjects in integers, and find the total, average in float

i) Evaluate the following expressions.


a. A+B*C+(D*E) + F*G
b. A/B*C-B+A*D/3
c. A+++B---A
d. J= (i++) + (++i)

SOURCE CODE:
#include <stdio.h>
int main()
{
int A,B,C,D,E,F,G,i,J,res1,res2,res3;
printf("Enter the values of A,B,C,D,E,F,G,i:");
scanf("%d %d %d %d %d %d %d %d",&A,&B,&C,&D,&E,&F,&G,&i);
res1=A+B*C+(D*E)+F*G;
printf("A+B*C+(D*E)+F*G=%d\n",res1);
res2=A/B*C-B+A*D/3;
printf("A/B*C-B+A*D/3=%d\n",res2);
res3=A+++B---A;
printf("A+++B---A=%d , A=%d , B=%d\n",res3,A,B);
J= (i++) + (++i);
printf("J=%d i=%d",J,i);
return 0;
}

OUTPUT:
ii) Find the maximum of three numbers using conditional operator

SOURCE CODE:
#include<stdio.h>
int main()
{
int a, b, c, larg;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
printf("Enter third number: ");
scanf("%d", &c);
larg = (a>b)?((a>c)?a:c):((b>c)?b:c);
printf("Largest number is: %d", larg);
return 0;
}

OUTPUT:
iii) Take marks of 5 subjects in integers, and find the total, average in float
SOURCE CODE:
#include <stdio.h>
int main()
{
int English, Maths, Science, Social, Biology;
float total, average, percentage;
printf("Enter the marks of English, Maths, Science, Social and Biology: \n");
scanf("%d %d %d %d %d", &English, &Maths, &Science, &Social, &Biology);
total = English + Maths + Science + Social + Biology;
average = total / 5;
percentage = (total/500) * 100;
printf("Total Marks of the Student: %.2f\n", total);
printf("Average Marks of the Student: %.2f\n", average);
printf("Percentage of the Student: %.2f\n", percentage);
return 0;
}

OUTPUT:

You might also like