0% found this document useful (0 votes)
53 views5 pages

CP Finals

1) The code calculates the volume of a sphere and cone given radius and height inputs from the user. It prints the volumes. 2) A flowchart is provided to explain the coding steps for calculating volumes of a sphere and cone: start by defining pi, prompt for radius and height input, calculate volumes using formulas, print volumes, end. 3) The syntax of a programming language specifies code structure while semantics refers to the meaning and interpretation of code symbols.
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)
53 views5 pages

CP Finals

1) The code calculates the volume of a sphere and cone given radius and height inputs from the user. It prints the volumes. 2) A flowchart is provided to explain the coding steps for calculating volumes of a sphere and cone: start by defining pi, prompt for radius and height input, calculate volumes using formulas, print volumes, end. 3) The syntax of a programming language specifies code structure while semantics refers to the meaning and interpretation of code symbols.
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/ 5

Q1

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 //

2. Document every coding using flowchart for better understanding

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;

printf(“Enter Your Name : “);


scanf(“%s”,&name);

printf("Enter working hours : ");


scanf("%d", &hour);

gross_salary = 15.00*hour;

printf("\nGross salary : %d", gross_salary);


return (0);

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

B) 1)Enter your Num: 10 10


20*
2) Error

Question 4
A)

#include <stdio.h>
#include <math.h>

int BonusCalc(float);

int main( )
{
float sale;

printf("Enter Total Sale :");


scanf("%d", &sale);

BonusCalc(sale);

return 0;
}

int BonusCalc( float i)


{
int total;
if(i>7600)
{
total=i+(i*0.33);
}

else if (i>3000 && i<=7600)


{
total=i+(i*0.15);
}

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;

printf("Enter Radius Of Shpere :\n"); scanf("%f",&radius);

volume=(4/3)*Pi*radius*radius;

printf("\n The Volume of Shpere =%f",volume);

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

Prompt the user to enter the


radius of the sphere and the
height of the cone

Read the radius of the sphere


and the height of the cone

Compute the volume of the sphere


V=4/3*pi*r*r and the volume of
cone V= pi*r*r*h

Write the volume of the cone and


sphere

end

You might also like