You are on page 1of 14

A) Choose the correct answer of the following:

1. The format ‘%d’ is used to identify _____ variable.

A. char B. int C. float D. string

2. The format ‘%c’ is used to identify _____ variable.

A. char B. int C. float D. string

3. The format ‘%s’ is used to identify _____ variable.

A. char B. int C. float D. string

4. The format ‘%i’ is used to identify _____ variable.

A. char B. int C. float D. string

5. The format ‘%____’is used to identify float variable.

A. f B. e C. g D. all of the above

6. Which of the following is correct according to datatypes memory size?

A. char < int < float B. int > char > float

C. char > int > float D. double > char > int

7. Which datatype has a variable memory size?

A. int B. string C. float D. character

8. What is the output of this C code?


1. #include <stdio.h>
2. int main()
3. {
4. float a = 5.376666;
5. printf("%f\n", a);
6. }

A. 5.38 B. 5.376666

C. 5 D. junk data

9. What is the output of this C code?


1. #include <stdio.h>
2. int main()
3. {
4. float a = 5.376666;
5. printf("%5.2f\n", a);
6. }
A. 5.38 B. 5.376666

C. 5 D. junk data

10. What is the output of this C code?


1. #include <stdio.h>
2. int main()
3. {
4. float a = 5.376666;
5. printf("%d\n", a);
6. }

A. 5.38 B. 5.376666

C. 5 D. junk data

11. What will be the output of the following code?


1. #include <stdio.h>
2. int main()
3. {
4. int i = 5;
5. int j = i % 3;
6. printf("%d\n", j);
7. }

A. 2 B. 1.666667 C. 1 D. -2
12. What will be the output of the following code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = -5;
5. int j = i % 3;
6. printf("%d\n", j);
7. }

A. 2 B. 1.666667 C. 1 D. -2
13. What will be the output of the following code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 5;
5. int j = i / 3;
6. printf("%d\n", j);
7. }

A. 2 B. 1.666667 C. 1 D. -2
14. What will be the output of the following code?
1. #include <stdio.h>
2. int main()
3. {
4. float i = 5.0;
5. float j = i / 3.0;
6. printf("%f\n", j);
7. }

A. 2 B. 1.666667 C. 1 D. -2
15. What will be the output of the following code?
1. #include <stdio.h>
2. int main()
3. {
4. float i = 5.0;
5. int j = i / 3;
6. printf("%d\n", j);
7. }

A. 2 B. 1.666667 C. 1 D. -2
16. What will be the output of the following code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 5;
5. int j = i % -3;
6. printf("%d\n", j);
7. }

A. 2 B. 1.666667 C. 1 D. -2
17. What will be the output of the following code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = 8 * 2 + 4 * 5 / 2;
5. printf("%d\n", j);
6. }

A. 120 B. 26 C. 50 D. 88

18. What will be the output of the following code?


1. #include <stdio.h>
2. int main()
3. {
4. int i = (8 * 2 + 4) * 5 / 2;
5. printf("%d\n", j);
6. }

A. 120 B. 26 C. 50 D. 88
19. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int i = 8 * (2 + 4) * 5 / 2;
5. printf("%d\n", j);
6. }

A. 120 B. 26 C. 50 D. 88

20. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int i = 8 * 2 + (4 * 5) / 2;
5. printf("%d\n", j);
6. }

A. 120 B. 26 C. 50 D. 88

21. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int i = 8 * (2 + 4 * 5) / 2;
5. printf("%d\n", j);
6. }

A. 120 B. 26 C. 50 D. 88

22. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int a = 5, b = 2;
5. int c = 2 * (a++) + (b--);
5. printf("%d\n", c);
6. }

A. 11 B. 12 C. 13 D. 14
23. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int a = 5, b = 2;
5. int c = 2 * (++a) + (b--);
5. printf("%d\n", c);
6. }

A. 11 B. 12 C. 13 D. 14

24. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int a = 5, b = 2;
5. int c = 2 * (++a) + (--b);
5. printf("%d\n", c);
6. }

A. 11 B. 12 C. 13 D. 14

25. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int a = 5, b = 2;
5. int c = 2 * (a++) + (--b);
5. printf("%d\n", c);
6. }

A. 11 B. 12 C. 13 D. 14

26. The priority order of arithmetic operations is:

A. %, *, /, +, - B. %, +, /, *, -

C. +, -, %, *, / D. %, +, -, *, /

27. Which is not considered an arithmetic operation?

A. x += 5 B. x *= 5

C. x %= 5 D. x != 5
28. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int a = 1;
5. if (a = 1) printf("Yes\n");
6. else printf("No\n");
7. }

A. Yes B. No

C. Error

29. What will be the output of the following code?


1. #include <stdio.h>
2. int main()
3. {
4. int a = 1;
5. if (a == 1) printf("Yes\n");
6. else printf("No\n");
7. }

A. Yes B. No

C. Error

30. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int a = 0;
5. if (a = 0) printf("Yes\n");
6. else printf("No\n");
7. }

A. Yes B. No

C. Error

31. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int a = 0;
5. if (a == 0) printf("Yes\n");
6. else printf("No\n");
7. }

A. Yes B. No

C. Error
32. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int a == 0;
5. if (a == 0) printf("Yes\n");
6. else printf("No\n");
7. }

A. Yes B. No

C. Error

33. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int x = 5, y = 5;
5. if (x == 10) y--;
6. printf("%d, %d", x, y--);
7. }

A. 5, 5 B. 5, 4

C. 10, 3 D. 10, 4

34. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int x = 5, y = 5;
5. if (x = 10) y--;
6. printf("%d, %d", x, y--);
7. }

A. 5, 5 B. 5, 4

C. 10, 3 D. 10, 4

35. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int x = 5, y = 5;
5. if (x = 10) y--;
6. printf("%d, %d", x, --y);
7. }
A. 5, 5 B. 5, 4

C. 10, 3 D. 10, 4

36. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int x = 5, y = 5;
5. if (x == 10) y--;
6. printf("%d, %d", x, --y);
7. }

A. 5, 5 B. 5, 4

C. 10, 3 D. 10, 4

37. What will be the output of the following code?

1. #include <stdio.h>
2. int main()
3. {
4. int x = 5, y = 5;
5. if (x == 5) y--;
6. printf("%d, %d", x, y--);
7. }

A. 5, 5 B. 5, 4

C. 10, 3 D. 10, 4
38. The expression ‘break’ isn't used within:

A. do-while B. if-else

C. for D. while

39. Which expression is used to come out of a loop only for that iteration?

A. break B. continue

C. exit () D. return

40. Which expression is used to end a loop?

A. break B. continue

C. exit () D. return

41. Which function is used to end a program?

A. break B. continue
C. exit () D. return

42. Which expression is used to end a function?

A. break B. continue

C. exit () D. return

43. How many times will the program print "Hello" at the screen?

1. #include <stdio.h>
2. int main()
3. {
4. int i, j;
5. for (i=0; i<3; i++)
6. {
7. for (j=0; j<3; j++)
8. {
9. printf("Hello\n");
10. if (i>1) break;
11. }
12. }
13. }

A. 3 B. 6 C. 7 D. 9

44. How many times will the program print "Hello" at the screen?

1. #include <stdio.h>
2. int main()
3. {
4. int i, j;
5. for (i=0; i<3; i++)
6. {
7. for (j=0; j<3; j++)
8. {
9. if (i>1) break;
10. printf("Hello\n");
11. }
12. }
13. }

A. 3 B. 6 C. 7 D. 9

45. How many times will the program print "Hello" at the screen?

1. #include <stdio.h>
2. int main()
3. {
4. int i, j;
5. for (i=0; i<3; i++)
6. {
7. for (j=0; j<3; j++)
8. {
9. printf("Hello\n");
10. }
11. if (i>1) break;
12. }
13. }

A. 3 B. 6 C. 7 D. 9

46. How many times will the program print "Hello" at the screen?
1. #include <stdio.h>
2. int main()
3. {
4. int i, j;
5. for (i=0; i<3; i++)
6. {
7. for (j=0; j<3; j++)
8. {
9. if (i>1) break;
10. }
11. printf("Hello\n");
12. }
13. }

A. 3 B. 6 C. 7 D. 9

47. How many times will the program print "Hello" at the screen?
1. #include <stdio.h>
2. int main()
3. {
4. int i, j;
5. for (i=0; i<3; i++)
6. {
7. for (j=0; j<3; j++)
8. {
9. printf("Hello\n");
10. if (i>1) continue;
11. }
12. }
13. }

A. 3 B. 6 C. 7 D. 9

48. Which of the following is the odd one out?


A. != B. = C. || D. ==

49. What is a pointer?


A. A variable that is used to store the address of other variables
B. An expression used to create variables
C. A variable that is used to store the address of a function
D. A keyword
50. Is it possible to run program without main () function?

A. Yes B. No C. Sometimes
B) Evaluate the following integrals:
𝜋
i. ∫0 sin 𝑥 𝑑𝑥
2 (h = π / 4)
𝜋
ii. ∫02 cos 𝑥 𝑑𝑥 (h = π / 4)
51
iii. ∫0 𝑑𝑥 (h = 2.5)
𝑥

Using the trapezoidal rule.


a) Solve the integrations manually
b) Write a C program code to solve these integrations.

C) Resolve the previous problem numerically using Simpson's 1/3 rule and
write a proper C code to solve the integrations.

D) use the bisection method to calculate the roots of the equations


i. 𝑓(𝑥) = x 3 + 3x – 5 x ϵ [1, 2]
ii. 𝑓(𝑥) = x 6 − x – 1 x ϵ [1, 2]
iii. 𝑓(𝑥) = e𝑥 − 1 x ϵ [-0.5, 1]
a) Solve the problems numerically.
b) Write a proper C program code to solve these problems.

E) Resolve the previous problem numerically using Newton-Raphson method


and write a proper C code.
F) You needed to calculate the result of the division operation (1/1.5), but you
found out that your calculator is not working well, as it can only add, subtract,
and multiply, but not divide. Can you utilize the equation (1/x = 1.5), the
Newton-Raphson Method, and your bad calculator to find the value to 8
decimal places? Write a c code to solve this problem.
G) Utilize Jacobi method to solve the following sets of equations:
i) 3 x + 2 y = 4 & x–3y=5
ii) 4 x – y =1 & -x + 2 y = 5
iii) 5 x + y = -2 & 2 x +4 y =10
iv) 3 x - y = -2 & x+2y=4
v) 2 x – y = 3 & x + 3 y = 12
vi) 3 x - y + z = 4 & x +4 y - z = 0 & x+2y+4z=5
a) Solve the problems numerically.
b) Write a proper C code to solve them.

H) The steady state 1-dimensional heat equation, with no heat generation is:
𝑑2𝑇
= 𝑍𝑒𝑟𝑜
𝑑𝑥 2
Use the equation to calculate the temperature distribution with in a solid slab
of length L =1 m and thermal conductivity k. Solve the problem analytically
and numerically (using finite difference technique) and compare the results.
Then, write a c programming code to solve the problem, for each of the
following cases.
a) T1 = 50°C & T2 = 30°C.
b) T1 = 70°C & T2 = 20°C.
c) T1 = 35°C & T2 = 30°C.
d) T1 = 20°C & T2 = 65°C.
e) T1 = 25°C & T2 = 80°C.
I) The steady state 2-dimensional heat equation, with no heat generation is:
𝑑2 𝑇 𝑑2 𝑇
+ = 𝑍𝑒𝑟𝑜
𝑑𝑥 2 𝑑𝑦 2

By assuming equal dx and dy, we can use the finite difference


technique to calculate the temperatures in the following figure at nodes a,b.
Thermal conductivity of the material is assumed to be constant and not
temperature dependent. Solve the problem numerically and write a C
programming code to solve the problem, for each of the following cases.
a) T1 = 500°C, T2 = 100°C, T3 = 200°C, and T4 = 100°C.
b) T1 = 500°C, T2 = 150°C, T3 = 100°C, and T4 = 100°C.
c) T1 = 200°C, T2 = 75°C, T3 = 500°C, and T4 = 300°C.
d) T1 = 125°C, T2 = 300°C, T3 = 500°C, and T4 = 300°C.
e) T1 = 150°C, T2 = 300°C, T3 = 200°C, and T4 = 400°C.

T1

a
T3

T2
J) Solve analytically and numerically:
a) 𝑦̀ = 4y + 2, y(0) = 5.
b) 𝑦̀ = 6y + 1, y(0) = 1.
c) 𝑦̀ = −3y + 5, y(0) = 1.
d) 𝑦̀ = 2y + 3, y(0) = 1.
e) 𝑦̀ = −3y + 1, y(0) = 1.
a) Solve analytically to get the exact solution to the previous ODEs.
b) Solve numerically using Euler approach from x=0 to x=1 with step
size h=0.5, and write the appropriate programming code.
c) Solve numerically using Rung-Kutta approach from x=0 to x=1
with step size h=0.5, and write the appropriate programming code.
d) compare the results with the exact solution.

K) By the least squares method find the value of the constants a, b that satisfies
the following equations for the data given in the table and write a C program
to evaluate these constants.
x 0.5 1 2 3
y 4 6 10 8

a) 𝑦 = 𝑎. 𝑥 + 𝑏
b) 𝑦 = 𝑎. 𝑥𝑦 + 𝑏
c) 𝑦 = 𝑏. 𝑒 𝑎𝑥
d) 𝑦 = 𝑏. 𝑥 𝑎
e) 𝑦 = 𝑙𝑛(𝑏. 𝑥)𝑎

You might also like