Professional Documents
Culture Documents
(SRD12603)
PRACTICAL TASK 2
REPORT PRACTICAL TASK 2
NAME STUDENT ID
MUHAMMAD AQIL BIN NASIRUDDIN 54105120020
DANISH THAQIF BIN ZAINAL ASRI 54105120109
MUHAMMAD SUFI BIN MUSTAFA 54105120060
Question :
Fahrenheit. Prompt the user to enter the temperature in Celcius value and use the
formula F = C x 1.8 + 32
Answer :
#include<stdio.h>
main()
{
float Celsius;
float Fahrenheit;
printf("Enter Degrees Celsius : ");
scanf( "%f", & Celsius);
}
FLOW CHART
START
READ C
F=9/5(C+32)
PRINT F
END
Question :
2. Write a program to compute the volume of a cylinder or sphere depending upon user
choice. The program will first display the menu and allow user to choose on of the following
options:
i. Volume of Cylinder
ii. Volume of Sphere
If user enters option 1, prompt the user for the radius r and height h of the cylinder and
output the volume of a cylinder. Use formula V= π r2h. If user enters option 2, prompt the
user for the radius r of the sphere and output the volume of a sphere. Use formula V = 4/3 π
r3 . Use the constant value 3.142 for π.
Answer :
#include<stdio.h>
main()
{
float radius,height,volume_of_cylinder,volume_of_sphere,PI = 3.142;
int no1;
printf("PROGRAM TO FIND A VOLUME OF CYLINDER AND VOLUME OF SPHERE\n");
printf("-------------------------------------------------------------\n");
printf("ENTER 1 TO FIND A VOLUME OF CYLINDER\n");
printf("ENTER 2 TO FIND VOLUME OF SPHERE\n");
scanf("%d", &no1);
if (no1 == 1)
{
printf("ENTER RADIUS :");
scanf("%f", &radius);
volume_of_cylinder = PI*(radius*radius)*height;
START
USERS
READ r, h V(C)=3.142*r*r*h PRINT V(C)
ENTER==1
USERS V(C)=3.142*4/3*r*r*r
READ r PRINT V(C)
ENTER==2
PRINT “INVALID
SELECTION”
END
Question :
3. By using if…else stmt or switch stmt, write an interactive program that may be used to
compute the area of square (area=side2) or triangle (area=1/2 x base x height) after
prompting the user to type the first character of the figure name (S or T). The output should
be display as follows:
Answer : 1.1
#include<stdio.h>
main()
{
float area,side,base,height;
char type_of_shape;
switch (type_of_shape)
{
case 'S':
case 's':printf("TO CALCULATE AREA OF SQUARE\n");
printf("ENTER SIDE :");
scanf("%f", &side);
area = side*side;
printf("AREA OF SQUARE = %.2f", area);
break;
case 'T':
case 't':printf("TO CALCULATE AREA OF TRIANGLE\n");
printf("ENTER BASE :");
scanf("%f", &base);
printf("ENTER HEIGHT :");
scanf("%f", &height);
area = 0.5*base*height;
printf("AREA OF TRIANGLE = %.2f", area);
break;
END
Question :
ENTER MULTIPLICAND: 2
ENTER MULTIPLIER: 3
1x2=2
2x2=4
3x2=6
Answer : 1.1
#include<stdio.h>
main()
{
int counter=1;
float i,j,p;
printf("Multipication Operation Table\n\n");
printf("Enter Multiplicand: ");
scanf("%f" ,&i);
printf("Enter Multiplier:");
scanf("%f" ,&j);
do
{
p=counter*i;
scanf("&d",&counter);
}
Answer : 1.2
#include<stdio.h>
main()
{
int counter=1,j;
float i,p;
printf("Multipication Operation Table\n\n");
printf("Enter Multiplier:");
scanf("%d" ,&j);
printf("Enter Multiplicand: ");
scanf("%f" , &i);
while(counter<=j)
{
p=counter*i;
printf("%d X %.f = %.f \n\n",counter,i,p);
counter++;
}
return 0;
}
Answer : 1.3
#include<stdio.h>
main()
{
int counter,i,j,p;
for(counter=1;counter<=j;counter=counter+1)
{
p=counter*i;
printf("%d*%d=%d\n",counter,i,p);
}
return 0;
}
FLOW CHART
START
I=MULTIPLICAND_NO
J= MULTIPLIER_NO
READ MULTIPLICAND_NO,
READ MULTIPLIER_NO
COUNTER=1
COUNTER<=
MULTIPLIER_
NO
PRODUCT =
COUNTER*MULTIPLICAND_NO
PRINT PRODUCT
END
Question :
a. 1 0
b. 2 0 1
c. 4 0 1 2
d. 8 0 1 2 3
e. 16 0 1 2
f. 32 0 1
g. 64 0
Answer output 1 :
#include<stdio.h>
main()
{
int counter;
printf("Program to Count Up No\n\n");
for(counter=1;counter<=64;counter=counter*2)
{
printf("%d\n", counter);
}
return 0;
}
Answer output 2 :
#include<stdio.h>
main()
{
int n=3;
int i,j;
for(i=0;i<=n;i++)
{
for(j=0;j<=i;j++)
{
printf("%d\t",j);
}
printf("\n");
}
for(i=0;i<=n;i++)
{
for(j=0;j<n-i;j++)
printf("%d\t",j);
printf("\n");
}
return 0;
}
FLOW CHART OUTPUT 1 :
FLOW CHART OUPUT 2 :
6. Write a C program to find a total value of even numbers entered by the user. If the
user enters -1, the program will terminated and display the total value.
Answer :
#include<stdio.h>
main()
{
int count,sum=0,data , i;
for(count=0; ;count++)
{
printf("\nEnter number (-1 to terminate) : ");
scanf("%d" ,&data);
if (data==-1)
{
break;
}
else
{
if(data%2==1 || data%2==-1)
{
continue;
}
else
{
sum=sum+data;
printf("Even number = %d\n",data);
}
}
}
printf("\nTotal value from the entered number is %d",sum);
return 0;
}
FLOW CHART