INDEX
MODULE Date IDX PROGRAM PAGE Sign &
NO NO Marks
Simple computational problems using the operator’ precedence
and associativity
4.1 Evaluate the following expressions.
a.A+B*C+(D*E) + F*G
b. A/B*C-B+A*D/3
c.A+++B---A
4 d. J= (i++) + (++i)
4.2 Find the maximum of three numbers using
conditional operator
4.3 Take marks of 5 subjects in integers, and find the
total, average in float
4.4 Find the given number is even or odd or zero
4.5 Find the factorial of given number using any loop.
MODULE 4 - Program 4.1
AIM : Write a C program to 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)
ALGORITHM :
STEP 1 : START
STEP 2 : Read A, B, C, D, E, F, G, I values
STEP 3 : Calculate R1= A+B*C+(D*E) + F*G
STEP 4 : Calculate R2= A/B*C-B+A*D/3
STEP 5 : Calculate R3= A+++B---A
STEP 6 : Calculate J= (i++) + (++i)
STEP 7: Display R1, R2, R3, J
STEP 5 : Stop
FLOWCHART :
START
Read
A,B,C,D,E,F,G,I
Calculate
R1= A+B*C+(D*E) + F*G
R2= A/B*C-B+A*D/3
R3= A+++B---A
J= (i++) + (++i)
Display R1, R2, R3, J
STOP
PROGRAM :
#include<stdio.h>
int main()
{
int A, B, C, D, E, F, G, I,R1,R2,R3,J;
printf("\n 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);
R1= A+B*C+(D*E)+F*G;
printf("\n Value of A+B*C+(D*E)+F*G = %d",R1);
R2= A/B*C-B+A*D/3;
printf("\n Value of A/B*C-B+A*D/3 = %d",R2);
R3= A+++B---A;
printf("\n Value of A+++B---A = %d",R3);
J= (I++) + (++I);
printf("\n Value of (i++) + (++i) = %d",J);
return 0;
}
OUTPUT :
MODULE 4 – Program 4.2
AIM : write a C program to find the biggest of three numbers.
ALGORITHM :
STEP 1 : START
STEP 2 : Read a, b ,c values
STEP 3 : if (a>b) and (a>c) then display a is bigger go to step 5
STEP 4 : If b>c then display b is bigger otherwise display c is bigger
STEP 5 : Stop
FLOWCHART :
PROGRAM :
#include<stdio.h>
int main()
{
int a,b,c;
printf("\n enter any three numbers\t");
scanf("%d %d %d",&a,&b,&c);
if ((a>b)&&(a>c))
printf("%d is big ",a);
else if (b>c)
printf("%d is big ",b);
else
printf("%d is big ",c);
return 0;
}
OUTPUT :
enter any three numbers 324
4 is big
enter any three numbers 352
5 is big
enter any three numbers 743
7 is big
MODULE 4 - Program 4.3
Aim: Write a c program to take marks of 5 subjects in integers, and
find the total, average in float
Algorithm:
Step1: Start
Step2: Declare the variables m1,m2,m3,m4,m5,total,average
Step3: Read the variables m1,m2,m3,m4,m5
Step4: total=m1+m2+m3+m4+m5
Step5: average=total/5.0
Step6: Display total and average of 5 subjects
Step7: stop
FLOWCHART :
PROGRAM :
#include <stdio.h>
int main()
{
int m1,m2,m3,m4,m5,total;
float average;
printf("Enter marks of 5 subjects in integers: ");
scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);
total=m1+m2+m3+m4+m5;
average=total/3.0;
printf("\nTotal and average marks of 5 subjects in integers
Total=%d Average= %.2f",total,average);
return 0;
}
Input: Enter marks of 5 subjects in integers: 80 85 90 75 70
Output: Total and average marks of 5 subjects in integers
Total=400 Average= 133.33
MODULE 4 - Program 4.4
AIM : Write a C program to find the given number is even or odd or
zero
ALGORITHM :
STEP 1 : START
STEP 2 : Read n
STEP 3 : if n==0 then display “zero” goto step 5
STEP 4 : if n%2==0 then display “ Even” otherwise display “ Odd “
STEP 5 : Stop
FLOWCHART :
START
Read n
NO If n=0
YES
If YES Display “ZERO”
NO n%2=0
Display “Even”
Display “Odd”
STOP
PROGRAM :
#include<stdio.h>
int main()
{
int n;
printf("\n Enter any number : ");
scanf("%d",&n);
if(n==0)
printf("\n The given number is Zero ");
else if(n%2==0)
printf("\n The given number is Even ");
else
printf("\n The given number is Odd ");
return 0;
}
OUTPUT :
MODULE 4 - Program 4.5
AIM : Write a C program to Find the factorial of given number using any
loop.
ALGORITHM :
STEP-1: Start
STEP-2: read n
STEP-3: f=1, i=1
STEP-4: repeat step 5 until i>n
STEP-5: calculate f=f*i , i=i+1
STEP-6: Display f
STEP-7: Stop
FLOWCHART:
PROGRAM :
#include<stdio.h>
int main ()
{
int n,i=1;
long f=1;
printf("\n enter the number \t");
scanf("%d",&n);
while(i<=n)
{
f=f*i;
i++;
}
printf("\n factorial = %ld",f);
return 0;
}
OUTPUT :
enter the number 5
factorial = 120