0% found this document useful (0 votes)
26 views

Problem Solving Assignment

Uploaded by

Mutasim Billah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Problem Solving Assignment

Uploaded by

Mutasim Billah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT 1

Instructions:

Answer all questions given


Send hardcopy only
Send on FRIDAY, 25th November during class
Late submissions, 2 marks deduction each day cumulatively.
No appeal

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;

Task 3 (10 marks)

Write a C program to find the value of y in the following equation.

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

Task 4 (10 marks)

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.

Discuss the following problems with your instructor.

The formula to convert a temperature from Celsius to Fahrenheit is as below.

Fahrenheit = 9/5 x Celsius + 32

Complete the following code to solve the above problem.


#include <stdio.h>

int main (String[] args)


{
// Declare a data type for BASE and CONVERSION_FACTOR

int base = 32;

double conversion_factor = 9.0 / 5.0;

// Declare a fahrenheitTemp as double

double fahrenheitTemp;

// Assign a value (eg 24) to celsiusTemp variable

int celsiusTemp = 37; // value to convert

// Write a formula to convert from Fahrenheit to Celsius

fahrenheitTemp =(9*clesiusTemp/5)+base;

printf("Celsius Temperature: %d", celsiusTemp);


printf("Fahrenheit Equivalent:%lf",fahrenheitTemp);
}

Task 5 (10 marks)

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()
{

float radius =6.0;

float surfaceArea = 4*3.142*radius*radius;

double volume = (4*3.142*radius*radius*radius)/3;

printf("volume:%.3f\nsurface area:%.3f\n",volume,surfaceArea);

return 0;

You might also like