You are on page 1of 9

Kingdom of Saudi Arabia ‫المملك ـ ـ ـ ــة العرب ـي ـ ــة السعودي ـ ــة‬

Ministry of Education ‫وزارة التع ـ ــليـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــم‬


University of Hail ‫ج ــامع ـ ـ ـ ـ ــة حائ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــل‬
College of Computer Science and Engineering ‫كليـ ـ ـ ـ ـ ـ ــة عل ـ ـ ـ ـ ـ ـ ـ ــوم وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب اآللـي‬
‫قس ـ ـ ـ ـ ـ ـ ــم علـ ـ ـ ـ ـ ـ ـ ـ ــوم الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة‬
Department of Computer Science and Software Engineering
‫الــبرمجيـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــات‬

Computer Programming in C– ics 103

Key
Answers
1
Prepared by: sabiha
1. Choose the correct answer for each question below:
1. When writing comments on multi lines, we use__________.
a) /* and */
b) //
c) <!

2. The result of the following arithmetic expression is__________.


y = 6 * 4 % 3 * 5;
a) 0
b) 9
c) 30

3. A preprocessor directive begins with a symbol __________.


a) <
b) @
c) #

4. Which of the following is a valid identifier?


a) 9X
b) 8+9
c) radius

5. What is the only function all C programs must contain?


1 ICS – 103 Home Work 1
Prepared by: Mrs. sabiha
Kingdom of Saudi Arabia ‫المملك ـ ـ ـ ــة العرب ـي ـ ــة السعودي ـ ــة‬
Ministry of Education ‫وزارة التع ـ ــليـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــم‬
University of Hail ‫ج ــامع ـ ـ ـ ـ ــة حائ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــل‬
College of Computer Science and Engineering ‫كليـ ـ ـ ـ ـ ـ ــة عل ـ ـ ـ ـ ـ ـ ـ ــوم وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب اآللـي‬
‫قس ـ ـ ـ ـ ـ ـ ــم علـ ـ ـ ـ ـ ـ ـ ـ ــوم الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة‬
Department of Computer Science and Software Engineering
‫الــبرمجيـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــات‬

a) start()
b) system()
c) main()

6. ____________ is the assignment operator in C.


a) ==
b) =
c) :=

7. The following program displays __________.


#include <stdio.h>
int main()
{
Printf(“1 + 2” );
return 0;
}
a) 1 + 2
b) 2
c) 3

8. The following program displays __________.


#include <stdio.h>
int main()
{
printf( "A");
printf( "B");
return 0;
}
a) A B
b) AB
c) B A

2 ICS – 103 Home Work 1


Prepared by: Mrs. sabiha
Kingdom of Saudi Arabia ‫المملك ـ ـ ـ ــة العرب ـي ـ ــة السعودي ـ ــة‬
Ministry of Education ‫وزارة التع ـ ــليـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــم‬
University of Hail ‫ج ــامع ـ ـ ـ ـ ــة حائ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــل‬
College of Computer Science and Engineering ‫كليـ ـ ـ ـ ـ ـ ــة عل ـ ـ ـ ـ ـ ـ ـ ــوم وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب اآللـي‬
‫قس ـ ـ ـ ـ ـ ـ ــم علـ ـ ـ ـ ـ ـ ـ ـ ــوم الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة‬
Department of Computer Science and Software Engineering
‫الــبرمجيـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــات‬

9. Every statement in C program should end with__________.


a)  A Comma (,)
b)  A Semicolon (;)
c)  A colon (:)

10. What is the exact output of the following code?


double area = 3.5;
printf( "area ");
printf( “%.1f”, area);
a) 3.5
b) 3.5 0
c) area 3.5

11. To assign a value 1 to variable x, you write__________.


a) 1 = x;
b) x = 1;
c) x == 1;

12. To declare an integer variable I and initialize it with 1, use__________.


a) int i=1;
b) int i(1);
c) int i == 1;

13. Which of the following declarations could store the number 5.5?
a) char num;
b) intnum;
c) double num;

14. What value would be stored in an integer variable "i" as a result of the following
calculation:
 int i, j;

3 ICS – 103 Home Work 1


Prepared by: Mrs. sabiha
Kingdom of Saudi Arabia ‫المملك ـ ـ ـ ــة العرب ـي ـ ــة السعودي ـ ــة‬
Ministry of Education ‫وزارة التع ـ ــليـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــم‬
University of Hail ‫ج ــامع ـ ـ ـ ـ ــة حائ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــل‬
College of Computer Science and Engineering ‫كليـ ـ ـ ـ ـ ـ ــة عل ـ ـ ـ ـ ـ ـ ـ ــوم وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب اآللـي‬
‫قس ـ ـ ـ ـ ـ ـ ــم علـ ـ ـ ـ ـ ـ ـ ـ ــوم الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة‬
Department of Computer Science and Software Engineering
‫الــبرمجيـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــات‬

j=3;
i = 4 + 2 * j / ( j - 1 );
a) 1
b) 7
c) 9

15. What is the value of the following arithmetic expression as evaluated by a C compiler?
(3 + 4)/( 7 - 6%4)
a) 1
b) 1.4
c) 7

16. Which of the following is output statement in C?


a) write
b) printf
c) scanf

17. Which of the following is input statement in C?


a) scanf
b) input
c) none of above

18. The expression 7 % 3 evaluates to what value?


a) 2.5
b) 1.5
c) 1

19. The expression 5 % 2 evaluates to__________.


a) 2.5
b) 2
c) 1

4 ICS – 103 Home Work 1


Prepared by: Mrs. sabiha
‫‪Kingdom of Saudi Arabia‬‬ ‫المملك ـ ـ ـ ــة العرب ـي ـ ــة السعودي ـ ــة‬
‫‪Ministry of Education‬‬ ‫وزارة التع ـ ــليـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــم‬
‫‪University of Hail‬‬ ‫ج ــامع ـ ـ ـ ـ ــة حائ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــل‬
‫‪College of Computer Science and Engineering‬‬ ‫كليـ ـ ـ ـ ـ ـ ــة عل ـ ـ ـ ـ ـ ـ ـ ــوم وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب اآللـي‬
‫قس ـ ـ ـ ـ ـ ـ ــم علـ ـ ـ ـ ـ ـ ـ ـ ــوم الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة‬
‫‪Department of Computer Science and Software Engineering‬‬
‫الــبرمجيـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــات‬

‫‪20. What is result of 45 / 4?__________.‬‬


‫‪a) 11‬‬
‫‪b) 11.25‬‬
‫‪c) 12‬‬

‫‪5‬‬ ‫‪ICS – 103 Home Work 1‬‬


‫‪Prepared by: Mrs. sabiha‬‬
Kingdom of Saudi Arabia ‫المملك ـ ـ ـ ــة العرب ـي ـ ــة السعودي ـ ــة‬
Ministry of Education ‫وزارة التع ـ ــليـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــم‬
University of Hail ‫ج ــامع ـ ـ ـ ـ ــة حائ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــل‬
College of Computer Science and Engineering ‫كليـ ـ ـ ـ ـ ـ ــة عل ـ ـ ـ ـ ـ ـ ـ ــوم وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب اآللـي‬
‫قس ـ ـ ـ ـ ـ ـ ــم علـ ـ ـ ـ ـ ـ ـ ـ ــوم الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة‬
Department of Computer Science and Software Engineering
‫الــبرمجيـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــات‬

21. The output of printf("%6.4f\n", n); when n = 123.456 of type float is


a) 123.456
b) 123.46
c) 123.4560

22. To use the function scanf, we must use


a) #include<std.h>
b) #include<stdio.h>
c) #include<scanf.h>

23. How would you declare two double variables?


a) double x, y;
b) double x, double y;
c) double x ; y;

24. How would you declare a constant X with value 10?


a) #include X= 10
b) #define X 10
c) #define X =10

25. Which of the following is a correct declaration for a variable which takes value of 15.5?
a) int m =15.5;
b) double m =15.5
c) Double m=15.5

6 ICS – 103 Home Work 1


Prepared by: Mrs. sabiha
Kingdom of Saudi Arabia ‫المملك ـ ـ ـ ــة العرب ـي ـ ــة السعودي ـ ــة‬
Ministry of Education ‫وزارة التع ـ ــليـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــم‬
University of Hail ‫ج ــامع ـ ـ ـ ـ ــة حائ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــل‬
College of Computer Science and Engineering ‫كليـ ـ ـ ـ ـ ـ ــة عل ـ ـ ـ ـ ـ ـ ـ ــوم وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب اآللـي‬
‫قس ـ ـ ـ ـ ـ ـ ــم علـ ـ ـ ـ ـ ـ ـ ـ ــوم الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة‬
Department of Computer Science and Software Engineering
‫الــبرمجيـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــات‬

2. What is the output of the following program?


int main()
Answer:
{
inta,b,c; a = 4, b = 3, c=7

a= 1;
b= 2;
c= 3;
a = a + 3;
b = b + 1;
c = a + b;
printf(“ a = %d, b=%d, c=%d” , a, b, c);
system("pause");
return 0;
}

3. The output of printf("%6.2f\n", n); when n = 659.458 is:

6 5 9 . 4 6

4. What #include statement do you put at the top of a program that does uses printf or
scanf?

#include <stdio.h>

5. Declare an integer variable N and initialize it to 10.

int N=10;

6. Evaluate 4+5*3

19

7. Evaluate 7*3+2

7 ICS – 103 Home Work 1


Prepared by: Mrs. sabiha
Kingdom of Saudi Arabia ‫المملك ـ ـ ـ ــة العرب ـي ـ ــة السعودي ـ ــة‬
Ministry of Education ‫وزارة التع ـ ــليـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــم‬
University of Hail ‫ج ــامع ـ ـ ـ ـ ــة حائ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــل‬
College of Computer Science and Engineering ‫كليـ ـ ـ ـ ـ ـ ــة عل ـ ـ ـ ـ ـ ـ ـ ــوم وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب اآللـي‬
‫قس ـ ـ ـ ـ ـ ـ ــم علـ ـ ـ ـ ـ ـ ـ ـ ــوم الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة‬
Department of Computer Science and Software Engineering
‫الــبرمجيـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــات‬

23

8. Evaluate 7*(3+2)

35

9. Evaluate the following expressions that use thearithmetic operators where i = 10, j = 2,
and k = 3.
Expression Result
i-j*k i-j*k
10-2*3
10-6
4
i-i/j i-i/j
10-10/2
10-5
5
i%k+j i%k+j
10 % 3 + 2
1+2
3
i%2*k i%2*k
10 % 2 * 3
0*3
0
i+j*k-i/j i+j*k-i/j
10 + 2 * 3 - 10 / 2
10+6- 10 / 2
10+6-5
16-5
11

8 ICS – 103 Home Work 1


Prepared by: Mrs. sabiha
Kingdom of Saudi Arabia ‫المملك ـ ـ ـ ــة العرب ـي ـ ــة السعودي ـ ــة‬
Ministry of Education ‫وزارة التع ـ ــليـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــم‬
University of Hail ‫ج ــامع ـ ـ ـ ـ ــة حائ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــل‬
College of Computer Science and Engineering ‫كليـ ـ ـ ـ ـ ـ ــة عل ـ ـ ـ ـ ـ ـ ـ ــوم وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب اآللـي‬
‫قس ـ ـ ـ ـ ـ ـ ــم علـ ـ ـ ـ ـ ـ ـ ـ ــوم الحـ ـ ـ ــاس ـ ـ ـ ـ ـ ـ ــب وه ـنـ ـ ـ ـ ـ ـ ــدسـ ـ ـ ـ ــة‬
Department of Computer Science and Software Engineering
‫الــبرمجيـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ـ ــات‬

10.Which of the following are valid C identifiers?


_amoun
y=z xyz123 Bill return Sue's two-way int 2ndclass
t
invalid valid valid invalid invalid invalid invalid invalid invalid

9 ICS – 103 Home Work 1


Prepared by: Mrs. sabiha

You might also like