Mex 2018
Mex 2018
Instructions: Answer ALL questions in Section A and only ONE (1) in section B.
6. Create a C- program that prints your name, and add your three scores you got in one of your courses. [2 ½]
Sol: #include<stdio.h>
Int main(){
char[20] = “name”;
float S1,S2,S3, Total;
Total = S1+S2+S3;
printf(“My name is:\n”, name);
printf(“The sum of scores is :”,Total);
}
7. Declare an integer variable called total and initialize it to zero [2]
int total;
total = 0;
9. Write a for loop to print out the values 1 to 10 on separate lines. [2]
10. The expression
x *= i + j / y; is equivalent to ______. Sol: d
a. x = x * i + j / y;
b. x = (x * i) + j / y;
c. x = (x * i + j) / y;
d. x = x * (i + j / y);
e. none of the above
===========================================================================================
Section B(Answer only One(1) question
1(a). Given a = 5, b = 1, x = 10, and y = 5, create a program that outputs the result of the formula
f = (ax- b)(x-yb) using a single printf() function [5mks]
#include<stdio.h>
int main(){
int a=5,b=1,x=10,y=5;
f = (a*x-b)*(x-y*b)
printf(“the result of formula is:” f)
}
1(b). Write a program that asks the user to enter two numbers, obtains the two numbers from the user and
prints the sum, product, difference. [5mks]
Sol: #include<stdio.h>
int main(){
int A,B;
printf(“Enter two numbers A and B:”);
scanf(“The first number “%d\n” “%d\n”, &A &B);
printf(“The sum of the two numbers is:\n”, A + B);
printf(“The difference of the two numbers is:\n”, A-B);
printf(“The product of the two numbers is:” A*B);
}
2a) Write a program that reads in the radius of a circle and prints the circle’s diameter, circumference and area.
Use the constant value 3.14159 for pi.
Sol:
b).Create a c-program that multiply all even integers between 1 and 50 by 4 and otherwise by 3.
Sol:
#include<stdio.h>
Int main(){
Int x;
for(x=1;x<=50;x++){
If(x%2==0){
X*=4;
else
X*=3
}
{
}