Tutorial 2 - ANS Programming
Tutorial 2 - ANS Programming
Programming Fundamental
Tutorial 2: Answer
ANS:
#include <stdio.h>
int main()
{
printf(”This is BETC1313 tutorial 1”);
printf(”\nHave a nice day!”);
return 0;
}
b)
ANS:
#include <stdio.h>
int main()
{
printf(”weight item 1:”);
scanf ("%f", &item1);
printf(”weight item 2:”);
scanf ("%f", &item2);
printf(”weight item 3:”);
scanf ("%f", &item3);
return 0;
}
BETC1313
Programming Fundamental
2. Assume a, b and c are integer variables with a = 3 and b = 7 and each expression is
independent. Determine the results of these statements:
a) c = b / a; ANS: 2
b) c = b % a; ANS: 1
c) c = a + b * a; ANS: 24
d) c = ++b / --a; ANS: 4
e) c = a * 2 / a + b++; ANS: 9
f) c = 9 * b % a + --b; ANS: 6
3. Given with i = 2, j = 5 and k = 15, and each expression is independent. Evaluate each
of the following expressions (True or False):
a) i > j - k ANS: T
b) i != k ANS: T
c) k <= k / j ANS: F
d) (j < i) || (k > j) ANS: T
e) (i >= 1) && (j == 5) ANS: T
f) (i > 0) && (j < k) || (k < i) ANS: T
4. Draw a flowchart and write a C program that reads radius and length of a cylinder,
and computes area and volume using the following formulas:
area = π (radius)2
volume = area x length
Start
area = radius*radius*pi
volume = area*length
END
BETC1313
Programming Fundamental
//ANS:
#include <stdio.h>
int main()
{
5. Draw a flowchart and write a C program that converts pounds into kilograms. The
program prompts user to enter a number in pounds, converts it to kilograms, and
displays the result. 1 pound is 0.454 kilogram.
Start
Read a number in
pounds
kilograms = pounds*0.454
END
BETC1313
Programming Fundamental
//ANS:
#include <stdio.h>
int main()
{
double pound, kg;
kg = pound * 0.454;
printf("\n\nPounds in kilograms: ");
printf("\n%0.4lf pounds = %0.4lf kilograms\n", pound, kg);
return 0;
}
6. Draw a flowchart and write a C program that asks user to enter his/her birth year. The
program then calculates the corresponding age and displays it to the console. If the
age is larger than 100, prints a message “You are blessed!” and if the age is less than
5, displays the message “You are a smart kid!”.
Start
Display age
Yes
age > 100
Display “You are blessed!” A
No
Yes
age < 5 Display “You are a smart kid!”
A
No A
END
BETC1313
Programming Fundamental
#include <stdio.h>
#include <stdlib.h>
int main()
{
int yearBorn, age, yearNow = 2017;
return 0;
}