Problem Solving Assignment
Problem Solving Assignment
Instructions:
Task 1 (8 marks)
Complete the following program so that its output is as given in the output section
below.
#include <stdio.h>
int main(){
int age = 9;
double weight = 25.5;
char gender = 'M';
char name[10] = "ABDULLAH";
printf("Name : %s\n",name);
printf("Age : %d\n",age);
printf("Weight : %.1f\n",weight);
printf("Gender : %c",gender);
return 0;
}
Output
Task 2 (8 marks)
Which of the following variable declarations are correct? (Note: can use related
header file)
long good-by;
short shrift = 0;
double bubble = 0, toil= 9, trouble = 8
byte the Bullet ;
int doubleVariable=9.0;
char thisMustBeTooLong ;
int 8ball;
bool has$=true;
Correct:
short shrift = 0;
char thisMustBeTooLong ;
bool has$=true;
y = 2x2 + 3 + bx + c
2a
where a,b,c and x is double data type. The value of a is 2.0, b is 5.0, c
is 6.0 and x is 2.0.
#include <stdio.h>
int main() {
double a=2.0,b=5.0,c=6.0,x=2.0;
double y = (2*x*x + 3)/(2*a) + b*x + c;
printf("y=%.2lf",y);
return 0;
}
In this exercise, students will learn how to assign a value to variables and apply how
to assign constant variables using the given formula. The also will learn how to write
an arithmetic formula in Java.
double fahrenheitTemp;
fahrenheitTemp =(9*clesiusTemp/5)+base;
The following are the formula to find a volume and surface area of a sphere. Write a
complete program to calculate a volume and surface area of sphere with a radius
value is 6.
Volume = 4πr3 Surface Area = 4πr2 where r = radius
3
Assume the value of π is 3.142 and the output should be 904.896 and 452.448
respectively.
#include <stdio.h>
int main()
{
printf("volume:%.3f\nsurface area:%.3f\n",volume,surfaceArea);
return 0;