CP Finals
CP Finals
C) 4/3*3.142*r*r*r=volume of sphere
3.142*r*r*h=volume of cone
D)1. Do coding with explanations through comment line which is explaining the line with
backslashes //
Question 2
A) The syntax of a programming language is a collection of rules to specify the structure or
form of code whereas semantics refers to the interpretation of the code or the associated
meaning of the symbols, characters or any part of a program.
B)3) #include<stdio.h>
int main()
{
int gross_salary, hour;
string name;
gross_salary = 15.00*hour;
Question 3
A)
#include <stdio.h>
int main() {
char op;
double first, second;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &first, &second);
switch (op) {
case '+':
printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
break;
// operator doesn't match any case constant
default:
printf("Error! operator is not correct");
}
return 0;
}
Question 4
A)
#include <stdio.h>
#include <math.h>
int BonusCalc(float);
int main( )
{
float sale;
BonusCalc(sale);
return 0;
}
else
{
total=i;
}
printf(“Bonus: RM%.total”);
4b) X=0
*ptr=0
X=5
*ptr=5
X=6
*ptr=6
4c)
#include <stdio.h>
int main()
{
float radius, volume;
float Pi=3.142;
volume=(4/3)*Pi*radius*radius;
return 0;
}
Nagulan Vegneswaran
D022010032
Question 1
a)
#include <studio.h>
int main()
{
float radius,height,volume;
float pie=3.14285714286;
float volumeofshpere, volumeofcone;
printf("enter radius : ");
scanf("%f",&radius);
printf("enter height : ");
scanf("%f",&height);
volumeofshpere=(4.0/3.0)pie(radius*radius*radius);
printf("Volume of the sphere=%f",volumeofshpere);
volumeofcone=(pie*radius*radius*height)/(3*7);
printf("VOC: %f\n",volumeofcone);
return 0;
B)
start
Pi=3.142
end