0% found this document useful (0 votes)
39 views17 pages

Industrial Computing

The document provides details of a practical task report for an industrial computing lecture. It includes the names of 3 students, their student IDs, and answers to 6 questions related to writing C programs. The questions cover topics like converting between Celsius and Fahrenheit, calculating cylinder and sphere volumes, computing square and triangle areas, producing multiplication tables, counting up numbers, and calculating totals of even numbers entered by a user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views17 pages

Industrial Computing

The document provides details of a practical task report for an industrial computing lecture. It includes the names of 3 students, their student IDs, and answers to 6 questions related to writing C programs. The questions cover topics like converting between Celsius and Fahrenheit, calculating cylinder and sphere volumes, computing square and triangle areas, producing multiplication tables, counting up numbers, and calculating totals of even numbers entered by a user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

INDUSTRIAL COMPUTING

(SRD12603)

LECTURE NAME :MADAM ZALINA BINTI OTHMAN

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 :

1. Write a C program to convert temperature from degrees Celcius to degree

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);

Fahrenheit =(Celsius + 1.8) + 32;

printf("Convert to Degree Fahrenheit: %.2f",Fahrenheit);


return 0;

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

printf("ENTER HEIGHT :");


scanf("%f", &height);

volume_of_cylinder = PI*(radius*radius)*height;

printf("VOLUME OF CYLINDER : %2.f",volume_of_cylinder);


}
else if (no1 == 2)
{
printf("ENTER RADIUS :");
scanf("%f", &radius);
volume_of_sphere = 4/3*PI*(radius*radius*radius);
printf("VOLUME OF SPHERE : %2.f",volume_of_sphere);
}
else
printf("SYNTAX ERROR\n\n");
return 0 ;
}
FLOW CHART

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;

printf("PROGRAM TO FIND AREA OF SQUARE OR TRIANGLE\n");


printf("-------------------------------------------\n");
printf("ENTER 'S' TO FIND SQUARE\n");
printf("ENTER 'T' TO FIND TRIANGLE\n");
printf("ENTER YOUR SELECTION :");
scanf("%s", &type_of_shape);
printf("\n\n");

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;

default: printf("INVALID SELECTION\n\n");


}
return 0;
}
Answer : 1.2
#include<stdio.h>
main()
{ float s , b , h , A ;
char symbol;
printf("Program to compute the Area Of Triangle Or Square\n");
printf("Menu Program\n");
printf("S - Area Of Square\n");
printf("T - Area Of Triangle\n");
printf("Enter Your Selection: ");
scanf("%s" ,&symbol);
if(symbol=='S')
{
printf("To Find Area Of Square\n");
printf("Enter Side Of Square: ");
scanf("%f" ,&s);
A=s*s;
printf("Area Of Square: %.2f", A);
}
else if(symbol=='s')
{
printf("To Find Area Of Square\n");
printf("Enter Side Of Square: ");
scanf("%f" ,&s);
A=s*s;
printf("Area Of Square: %.2f", A);
}
else if(symbol=='T')
{
printf("To Find Area Of Triangle\n");
printf("Enter Height Of Triangle: ");
scanf("%f" ,&h);
printf("Enter Base Of Triangle: ");
scanf("%f" ,&b);
A=0.5*b*h;
printf("Area Of Triangle: %.2f" , A);
}
else if(symbol=='t')
{
printf("To Find Area Of Triangle\n");
printf("Enter Height Of Triangle: ");
scanf("%f" ,&h);
printf("Enter Base Of Triangle: ");
scanf("%f" ,&b);
A=0.5*b*h;
printf("Area Of Triangle: %.2f" , A);
}
else
printf("Invalid Selection\n\n");
return 0;
}
FLOW CHART
START

SYMBOL==S READ s A(S)=s*s PRINT A(S)

SYMBOL==T READ b, h A(T)=O.5*b*h PRINT A(T)

PRINT “INVALID SELECTION”

END
Question :

4. To produce the multiplication table by using repetition statement. An output for


this program should display like this:

MULTIPLICATION OPERATION TABLE

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);

printf("%d X %.f = %.f\n\n", counter, i , p);


counter ++;
}
while(counter<=j);
return 0;

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

printf("MULTIPLICATION OPERATION TABLE\n");


printf("ENTER MULTIPLICAND: ");
scanf("%d", &i);
printf("ENTER MULTIPLIER: ");
scanf("%d", &j);

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 :

5. Write a program in C language to produce the following outputs:


Output 1 Output 2

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

You might also like