Page 1
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
TEST 1-MONDAY
The output should be similar to:
Write a program to calculate mass of the liquid in a tank. Allow the user to input the
volume either in cm or meter, and prompt the user to recalculate if desire.
Note that:
Oil density (ρ)= 850 kg/m3
Mass=ρV
Page 2
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
#include<math.h>
main(){
float oildensity, tankvolume,mass=0;
char oilunit,again;
printf("This program calculate the mass of oil in a tank");
start:
printf("\n\nEnter oil density: ");scanf("%f",&oildensity);
printf("Enter tank volume: ");scanf("%f",&tankvolume);
printf("\nEnter volume unit(m=meter, c=centimeter): ");scanf("%s",&oilunit);
recalculate:
switch (oilunit){
case 'c':
mass= oildensity*((pow(tankvolume,3))/pow(100,3)); break;
case 'm':
mass= oildensity*(pow(tankvolume,3)); break;
default:
printf("You have entered a wrong type of unit");
printf("\n\nEnter oil density unit(g for gram/k for kg): ");scanf("%s",&oilunit);
goto recalculate; }
printf("\n\n\tThe Mass of oil is %.4fkg",mass);
printf("\n\nDo you want to re-calculate: ");scanf("%s",&again);
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 3
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
#include<math.h>
main(){
float oildensity, tankvolume,mass=0;
char oilunit,again;
printf("This program calculate the mass of oil in a tank");
start:
printf("\n\nEnter oil density: ");scanf("%f",&oildensity);
printf("Enter tank volume: ");scanf("%f",&tankvolume);
printf("\nEnter volume unit(m=meter, c=centimeter): ");scanf("%s",&oilunit);
recalculate:
if (oilunit== 'c'){
mass= oildensity*((pow(tankvolume,3))/pow(100,3)); }
else if (oilunit== 'm'){
mass= oildensity*(pow(tankvolume,3));}
else{
printf("You have entered a wrong type of unit");
printf("\n\nEnter oil density unit(g for gram/k for kg): ");scanf("%s",&oilunit);
goto recalculate; }
printf("\n\n\tThe Mass of oil is %.4fkg",mass);
printf("\n\nDo you want to re-calculate(enter y for yes): ");scanf("%s",&again);
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 4
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
float oildensity, tankvolume,mass=0;
char oilunit,again;
printf("This program calculate the mass of oil in a tank");
start:
printf("\n\nEnter oil density: ");scanf("%f",&oildensity);
printf("Enter tank volume: ");scanf("%f",&tankvolume);
printf("\nEnter volume unit(m=meter, c=centimeter): ");scanf("%s",&oilunit);
recalculate:
switch (oilunit){
case 'c':
mass= oildensity*(tankvolume/100); break;
case 'm':
mass= oildensity*tankvolume; break;
default:
printf("You have entered a wrong type of unit");
printf("\n\nEnter oil density unit(g for gram/k for kg): ");scanf("%s",&oilunit);
goto recalculate;
}
printf("\n\n\tThe Mass of oil is %.4fkg",mass);
printf("\n\nDo you want to re-calculate: ");scanf("%s",&again);
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 5
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
float oildensity, tankvolume,mass=0;
char oilunit,again;
printf("This program calculate the mass of oil in a tank");
start:
printf("\n\nEnter oil density: ");scanf("%f",&oildensity);
printf("Enter tank volume: ");scanf("%f",&tankvolume);
printf("\nEnter volume unit(m=meter, c=centimeter): ");scanf("%s",&oilunit);
recalculate:
if (oilunit== 'c'){
mass= oildensity*(tankvolume/100); }
else if (oilunit== 'm'){
mass= oildensity*tankvolume;}
else{
printf("You have entered a wrong type of unit");
printf("\n\nEnter oil density unit(g for gram/k for kg): ");scanf("%s",&oilunit);
goto recalculate;
}
printf("\n\n\tThe Mass of oil is %.4fkg",mass);
printf("\n\nDo you want to re-calculate(enter y for yes): ");scanf("%s",&again);
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 6
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
TEST 1-TUESDAY
Base on the table develop a simple program on how long should a
man/woman should exercise to burn calories off either by jogging or
bicycling. The user must be able to keep calculating until the key end
otherwise.
Example: A 65kg woman needs to burn of 800 calories by jogging, how
long does she need to jog in order to burn of all of the calories.
The output should be similar to :
Energy output: 𝑤𝑒𝑖𝑔ℎ𝑡 𝑥 𝑎𝑐𝑡𝑖𝑣𝑖𝑡𝑦 𝑐𝑎𝑙𝑜𝑟𝑖𝑒𝑠
68𝑘𝑔 Δ 64 x
540
68
Duration: 𝑡𝑜𝑡𝑎𝑙 𝑐𝑎𝑙𝑜𝑟𝑖𝑒𝑠
𝐸𝑛𝑒𝑟𝑔𝑦 𝑜𝑢𝑡𝑝𝑢𝑡 Δ
800
516.17
Page 7
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
float calorin,weight,totalhour=0;
int type;
char again;
printf("\t\t\t\4\4\4Exercise Calculator\4\4\4\n\n");
start:
printf("\nEnter calories intake: ");scanf("%f",&calorin);
printf("Enter your weight: ");scanf("%f",&weight);
choose:
printf("\nPlease choose type of exercise \n1. Jogging\n2. Bicycling\nPlease enter type: ");scanf("%d",&type);
switch(type){
case 1:
totalhour=calorin/(weight*(540/68));
printf("\n\tIn order to burn %.f of calories you need to jog for %.1fhr",calorin,totalhour);break;
case 2:
totalhour=calorin/(weight*(639/68));
printf("\n\tIn order to burn %.f of calories you need to cycle for %.1fhr",calorin,totalhour);break;
default:
goto choose;break;
}
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 8
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
float calorin,weight,totalhour=0;
int type;
char again;
printf("\t\t\t\4\4\4Exercise Calculator\4\4\4\n\n");
start:
printf("\nEnter calories intake: ");scanf("%f",&calorin);
printf("Enter your weight: ");scanf("%f",&weight);
choose:
printf("\nPlease choose type of exercise \n1. Jogging\n2. Bicycling\nPlease enter type: ");scanf("%d",&type);
if (type==1){
totalhour=calorin/(weight*(540/68));
printf("\n\tIn order to burn %.f of calories you need to jog for %.1fhr",calorin,totalhour); }
else if (type==2){
totalhour=calorin/(weight*(639/68));
printf("\n\tIn order to burn %.f of calories you need to cycle for %.1fhr",calorin,totalhour); }
else { goto choose;}
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 9
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
TEST 1-TUESDAY
Base on the table develop a simple program on how long should a
man/woman should exercise to burn calories off either by jogging or
playing tennis. The user must be able to keep calculating until the key
end otherwise.
Example: A 65kg woman needs to burn of 800 calories by jogging, how
long does she need to jog in order to burn of all of the calories.
The output should be similar to :
Energy output: 𝑤𝑒𝑖𝑔ℎ𝑡 𝑥 𝑎𝑐𝑡𝑖𝑣𝑖𝑡𝑦 𝑐𝑎𝑙𝑜𝑟𝑖𝑒𝑠
68𝑘𝑔 Δ 64 x
540
68
Duration: 𝑡𝑜𝑡𝑎𝑙 𝑐𝑎𝑙𝑜𝑟𝑖𝑒𝑠
𝐸𝑛𝑒𝑟𝑔𝑦 𝑜𝑢𝑡𝑝𝑢𝑡 Δ
800
508.23
Page 10
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
float calorin,weight,totalhour=0;
int type;
char again;
printf("\t\t\t\4\4\4Exercise Calculator\4\4\4\n\n");
start:
printf("\nEnter calories intake: ");scanf("%f",&calorin);
printf("Enter your weight: ");scanf("%f",&weight);
choose:
printf("\nPlease choose type of exercise \n1. Jogging\n2. Tennis\nPlease enter type: ");scanf("%d",&type);
switch(type){
case 1:
totalhour=calorin/(weight*(540/68));
printf("\n\tIn order to burn %.f of calories you need to jog for %.1fhr",calorin,totalhour);break;
case 2:
totalhour=calorin/(weight*(480/68));
printf("\n\tIn order to burn %.f of calories you need to play intense tennis for %.1fhr", calorin,totalhour); break;
default:
goto choose; break; }
printf("\n\nDo you want to re-calculate(enter y for yes): ");scanf("%s",&again);
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 11
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
float calorin,weight,totalhour=0;
int type;
char again;
printf("\t\t\t\4\4\4Exercise Calculator\4\4\4\n\n");
start:
printf("\nEnter calories intake: ");scanf("%f",&calorin);
printf("Enter your weight: ");scanf("%f",&weight);
choose:
printf("\nPlease choose type of exercise \n1. Jogging\n2. Tennis\nPlease enter type: ");scanf("%d",&type);
if(type==1){
totalhour=calorin/(weight*(540/68));
printf("\n\tIn order to burn %.f of calories you need to jog for %.1fhr",calorin,totalhour);}
else if(type==2){
totalhour=calorin/(weight*(480/68));
printf("\n\tIn order to burn %.f of calories you need to play intense tennis for %.1fhr",calorin,totalhour); }
else{
goto choose; }
printf("\n\nDo you want to re-calculate(enter y for yes): ");scanf("%s",&again);
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 12
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
TEST 1-TUESDAY
Base on the table develop a simple program on how long should a
man/woman should exercise to burn calories off either by fast swimming
or bicycling. The user must be able to keep calculating until the key end
otherwise.
Example: A 65kg woman needs to burn of 800 calories by jogging, how
long does she need to jog in order to burn of all of the calories.
The output should be similar to :
Energy output: 𝑤𝑒𝑖𝑔ℎ𝑡 𝑥 𝑎𝑐𝑡𝑖𝑣𝑖𝑡𝑦 𝑐𝑎𝑙𝑜𝑟𝑖𝑒𝑠
68𝑘𝑔 Δ 64 x
540
68
Duration: 𝑡𝑜𝑡𝑎𝑙 𝑐𝑎𝑙𝑜𝑟𝑖𝑒𝑠
𝐸𝑛𝑒𝑟𝑔𝑦 𝑜𝑢𝑡𝑝𝑢𝑡 Δ
800
508.23
Page 13
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
float calorin,weight,totalhour=0;
int type;
char again;
printf("\t\t\t\4\4\4Exercise Calculator\4\4\4\n\n");
start:
printf("\nEnter calories intake: ");scanf("%f",&calorin);
printf("Enter your weight: ");scanf("%f",&weight);
choose:
printf("\nPlease choose type of exercise \n1. Fast Swimming\n2. Bicycling\nPlease enter type: ");scanf("%d",&type);
switch(type){
case 1:
totalhour=calorin/(weight*(860/68));
printf("\n\tIn order to burn %.f of calories you need to fast swimming for %.1fhr",calorin,totalhour);break;
case 2:
totalhour=calorin/(weight*(639/68));
printf("\n\tIn order to burn %.f of calories you need to cycle for %.1fhr",calorin,totalhour);
break;
default:
goto choose;break;
}
Page 14
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
float calorin,weight,totalhour=0;
int type;
char again;
printf("\t\t\t\4\4\4Exercise Calculator\4\4\4\n\n");
start:
printf("\nEnter calories intake: ");scanf("%f",&calorin);
printf("Enter your weight: ");scanf("%f",&weight);
choose:
printf("\nPlease choose type of exercise \n1. Fast Swimming\n2. Bicycling\nPlease enter type: ");scanf("%d",&type);
if(type==1){
totalhour=calorin/(weight*(860/68));
printf("\n\tIn order to burn %.f of calories you need to fast swimming for %.1fhr", calorin,totalhour);}
else if (type==2){
totalhour=calorin/(weight*(639/68));
printf("\n\tIn order to burn %.f of calories you need to cycle for %.1fhr",calorin,totalhour); }
else{
goto choose; }
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 15
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
TEST 1-WEDNESDAY
The output should be similar to:
The user must be able to keep calculating until the key end otherwise.
Develop a simple program to calculate
radius of a circle. The user need to
choose whether to input area or
circumference of the circle.
Note that:
area= πxrad2
and circumference = 2xπxrad
Page 16
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.1416
main(){
char type,again;
float radius,circumference,area;
printf("\t\4\4\4This program calculate radius of a circle\4\4\4");
start:
printf("\n\na:area\nc:circumference\n\nEnter the information that you have:");
scanf("%s",&type);
cal:
switch(type){
case 'a':
printf("\nEnter area of a circle:");scanf("%f",&area);
radius = sqrt(area/PI);
printf("\nThe area of a circle is %.2f while the radius is %.4f",area,radius); break;
case 'c':
printf("\nEnter circumference of a circle:");scanf("%f",&circumference);
radius= circumference/(PI*2);
printf("\nThe circumference of a circle is %.2f while the radius is %.4f",circumference,radius);break;
default:
printf("\na:area\nc:circumference\n\nPlease re-enter selection:");
scanf("%s",&type); goto cal; }
if(again=='y' || again=='Y') { goto start;}
getch();
}
Page 17
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.1416
main(){
char type,again;
float radius,circumference,area;
printf("\t\4\4\4This program calculate radius of a circle\4\4\4");
start:
printf("\n\na:area\nc:circumference\n\nEnter the information that you have:");
scanf("%s",&type);
cal:
if (type=='a'){
printf("\nEnter area of a circle:");scanf("%f",&area);
radius = sqrt(area/PI);
printf("\nThe area of a circle is %.2f while the radius is %.4f",area,radius);}
else if(type== 'c'){
printf("\nEnter circumference of a circle:");scanf("%f",&circumference);
radius=circumference/(PI*2);
printf("\nThe circumference of a circle is %.2f while the radius is %.4f",circumference,radius);}
else{
printf("\na:area\nc:circumference\n\nPlease re-enter selection:");
scanf("%s",&type); goto cal;}
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 18
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
TEST 1-WEDNESDAY
The output should be similar to :
The user must be able to keep calculating until the key end otherwise.
Develop a simple program to calculate
either an area or perimeters of a semi
circle. The program must prompt the
user to input radius.
Note that:
area= πxrad2
and circumference = 2xπxrad
20.7075
Page 19
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
#define PI 3.1415
main(){
char type,again;
float radius,circumference,area,perimeters;
printf("\t\4\4\4SEMI-CIRCLE CALCULATOR\4\4\4");
start:
printf("\na:area\np:perimeters\n\nEnter selection:");
scanf("%s",&type);
printf("\nEnter radius of the semi-circle:");
scanf("%f",&radius);
cal:
switch(type){
case 'a':
area= 0.5*(PI*pow(radius,2));
printf("\nThe area of a semi-circle for %.2f radius is %.4f",radius,area); break;
case 'p':
circumference= 2*PI*radius;
perimeters= (2 *radius)+ (circumference/2);
printf("\nThe perimeters of a semi-circle for %.2f of radius is %.4f",radius,perimeters);break;
default:
printf("wrong selection");
printf("\na:area\np:Perimeters\n\nPlease re-enter selection:");
scanf("%s",&type); goto cal; }
if(again=='y' || again=='Y')
goto start;
getch(); }
Page 20
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
#define PI 3.1415
main(){
char type,again;
float radius,circumference,area,perimeters;
printf("\t\4\4\4SEMI-CIRCLE CALCULATOR\4\4\4");
start:
printf("\na:area\np:perimeters\n\nEnter selection:");
scanf("%s",&type);
printf("\nEnter radius of the semi-circle:");
scanf("%f",&radius);
cal:
if(type=='a'){
area= 0.5*(PI*pow(radius,2));
printf("\nThe area of a semi-circle for %.2f radius is %.4f",radius,area);}
else if(type=='p'){
circumference= 2*PI*radius;
perimeters= (2 *radius)+ (circumference/2);
printf("\nThe perimeters of a semi-circle for %.2f of radius is %.4f",radius,perimeters);}
else{ printf("wrong selection");
printf("\na:area\np:Perimeters\n\nPlease re-enter selection:");
scanf("%s",&type); goto cal;
}
if(again=='y' || again=='Y')
goto start;
getch();
}
Page 21
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
TEST 1-THURSDAY
The output should be similar to:
Write a program to prove the theory of prefix and postfix in C Program slybuss. Allow the
user to keep testing until ‘n’ is keyed in by the user
Note that:
Postfix : a++,a—
Prefix :++a,--a
Page 22
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
int a,prepost;
char b;
printf("\tThis program is use to proof theory of postfix and prefix");
sekalilagi:
printf("\n\nEnter value a: "); scanf("%d",&a);
choose:
printf("\nPlease choose\n1. postfix\n2. Prefix\nPlease enter your choice: "); scanf("%d",&prepost);
switch (prepost){
case 1:
printf("\npostfix/a++ for a is %d at the end a =%d", a++,a);
printf("\nand a after ; is %d",a);
printf("\n\npostfix/a-- for a is %d at the end a =%d", a--,a);
printf("\nand a after ; is %d",a); break;
case 2:
printf("\nprefix/++a for a = %d at the end a =%d", ++a,a);
printf("\nand a after ; is %d",a);
printf("\n\nprefix/--a for a = %d at the end a =%d", --a,a);
printf("\nand a after ; is %d",a); break;
default: goto choose; }
printf("\n\nEnter n to stop re-trying: "); scanf("%s",&b);
if (b!='n'){ goto sekalilagi;}
getch();
}
Page 23
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
main(){
int a,prepost;
char b;
printf("\tThis program is use to proof theory of postfix and prefix");
sekalilagi:
printf("\n\nEnter value a: "); scanf("%d",&a);
choose:
printf("\nPlease choose\n1. postfix\n2. Prefix\nPlease enter your choice: "); scanf("%d",&prepost);
if (prepost==1){
printf("\npostfix/a++ for a is %d at the end a =%d", a++,a);
printf("\nand a after ; is %d",a);
printf("\n\npostfix/a-- for a is %d at the end a =%d", a--,a);
printf("\nand a after ; is %d",a); }
else if (prepost==2){
printf("\nprefix/++a for a = %d at the end a =%d", ++a,a);
printf("\nand a after ; is %d",a);
printf("\n\nprefix/--a for a = %d at the end a =%d", --a,a);
printf("\nand a after ; is %d",a);}
else { goto choose;}
printf("\n\nEnter n to stop re-trying: "); scanf("%s",&b);
if (b!='n'){ goto sekalilagi;}
getch();
}
Page 24
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
TEST 1-FRIDAY
The output should be similar to:
Write a program to segregat number of students according to :
GRADE E: 0 <= mark <=49
GRADE D: 50 <=mark <=59
GRADE C: 60 <= mark <=69
GRADE B: 70 <= mark <=79
GRADE A: 80 <= mark <=100
Page 25
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
int main(){
int noofstudent=0,mark=0, gradeA=0,gradeB=0,gradeC=0,gradeD=0,gradeE=0;
int i=1;
printf("\4\4The Program segregrate the number of students according to grade\4\4\ ");
printf("\n\nEnter Number of student: "); scanf ("%d",&noofstudent);
loop:
printf("%d student mark: ",i); scanf ("%d",&mark);
if (mark>=0 && mark <=49)
{ gradeE++; }
else if (mark>=50 && mark <=59)
{ gradeD++; }
else if (mark>=60 && mark <=69)
{ gradeC++; }
else if (mark>=70 && mark <=79)
{ gradeB++; }
else if (mark>=80 && mark <=100)
{ gradeA++; }
i++;
if (i<noofstudent)
goto loop;
Page 26
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
printf("\n______________________________________________\n ");
printf("\nThere is %d students receive grade A ",gradeA);
printf("\nThere is %d students receive grade B ",gradeB);
printf("\nThere is %d students receive grade C ",gradeC);
printf("\nThere is %d students receive grade D ",gradeD);
printf("\nThere is %d students receive grade E ",gradeE);
getch();
return 0;
}
Page 27
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
TEST 1-FRIDAY
The output should be similar to :
The user must be able to keep calculating until the key end otherwise.
Develelope a simple program which
receive radius of a circle from user and
allowed user to choose between
calculating area of a circle or
circumferense of a circle,:
Note that:
area= πxrad2
and circumference = 2xπxrad
Page 28
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.1416
main(){
char type,b;
float radius,circumference,area;
printf("This program calculate Area or Circumference of a circle");
again:
printf("\na:area\nc:circumference\n\nEnter selection:");scanf("%s",&type);
printf("\nEnter radius of a circle:"); scanf("%f",&radius);
cal:
switch(type){
case 'a':
area= PI*pow(radius,2);
printf("\nThe area of a circle for %.2fcm radius is %.4f",radius,area); break;
case 'c':
circumference= 2*PI*radius;
printf("\nThe circumference of a circle for %.2fcm radius is %.4f",radius,circumference);break;
default:
printf("wrong selection");
printf("\na:area\nc:circumference\n\nPlease re-enter selection:");
scanf("%s",&type); goto cal; }
printf("\n\nEnter n to stop re-trying: "); scanf("%s",&b);
if (b!='n'){ goto again;}
getch();
}
Page 29
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING BTI10202 COMPUTER PROGRAMMING
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.1416
main(){
char type,b;
float radius,circumference,area;
printf("This program calculate Area or Circumference of a circle");
again:
printf("\na:area\nc:circumference\n\nEnter selection:");
scanf("%s",&type);
printf("\nEnter radius of a circle:");
scanf("%f",&radius);
cal:
if (type=='a'){
area= PI*pow(radius,2);
printf("\nThe area of a circle for %.2fcm radius is %.4f",radius,area); }
else if (type=='c') {
circumference= 2*PI*radius;
printf("\nThe circumference of a circle for %.2fcm radius is %.4f",radius,circumference);}
else {
printf("wrong selection");
printf("\na:area\nc:circumference\n\nPlease re-enter selection:");
scanf("%s",&type); goto cal; }
printf("\n\nEnter n to stop re-trying: "); scanf("%s",&b);
if (b!='n'){ goto again;}
getch(); }