0% found this document useful (0 votes)
7 views2 pages

Mex 2018

The document is a mid-semester exam for an Introduction to Computer Science and Programming course, consisting of multiple-choice and programming questions. It covers topics such as computer components, programming concepts, and C-language syntax. Students are instructed to answer all questions in Section A and only one question in Section B.
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)
7 views2 pages

Mex 2018

The document is a mid-semester exam for an Introduction to Computer Science and Programming course, consisting of multiple-choice and programming questions. It covers topics such as computer components, programming concepts, and C-language syntax. Students are instructed to answer all questions in Section A and only one question in Section B.
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/ 2

School of Computing and Engineering Sciences

COSC101/111-Inroduction to Computer Science and Programming I


Mid-Semester Exam

Instructions: Answer ALL questions in Section A and only ONE (1) in section B.

1. Name five components of computers [2 ½]


Sol: Input devices, Output devices, processor (CPU), main memory and secondary memory
2. ----------------------- is a set of instructions for a computer to follow. [2]
Sol: computer program
3. List the order in which the steps that follow should be carried out during the development of a computer
program to solve a problem: [2]
a. Determine the data types of the memory cells required for storage of problem inputs and outputs.
b. Determine the problem inputs and outputs.
c. Read and understand the problem.
d. Write an initial algorithm.
e. Refine algorithm steps where needed.
Sol: [c, b, a, d, e]
4. Three uses of C-Language include-------------------------, ----------------------------and ------------------------- [ 1 ½]
Sol: Operating Systems, Language compilers, Utilities, Assemblers, text editors
4. The object file is created by the __________. [2]
a. editor
b. linker
c. loader
d. central processing unit
e. compiler[A]
5. T/F. A syntax error in a program is an error that causes the program to produce incorrect output. [2]
Sol: [F]
6. Declare an integer variable called total and initialize it to zero [2]
Sol: int total;
total = 0;

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;

8. Write a for loop to print out the values 1 to 10 on separate lines.


Sol: for( k = 1; k <= 10; k = k + 1 )
printf("%d\n", k) ;

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

You might also like