wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CIS1101-programming practice2

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

What is the output of the following code snippet?
int int1=9, int2=3;
if (int1 == int2)
printf("%d", int1/int2);
else
printf("%d", int1%int2);

a)

3

b)

0

c)

9

d)

1

e)

2

2.

What is the output of the following code snippet?
int num=15;
if (num >= 0)
printf("%d\n", num*=2);
else
printf("%d\n", num%=2);

a)

20

b)

10

c)

50

d)

30

e)

40

3.

What is the output of the following code snippet?
int m=7,n=3;
if(m>n)
printf("%d", m%n);
else if(m<n)
printf("%d", m/n);
else
printf("%d", m*n);

a)

5

b)

4

c)

6

d)

3

e)

7

4.

What is the output of the following code snippet?
float PerHeight = 178.89;
if (PerHeight < 150.0)
printf("The person is Dwarf. \n");
else if ((PerHeight >= 150.0) && (PerHeight < 165.0))
printf("The person is average heighted. \n");
else if ((PerHeight >= 165.0) && (PerHeight <= 195.0))
printf("The person is taller. \n");
else
printf("Abnormal height.\n");

a)

The person is Dwarf

b)

The person is average heighted.

c)

The person is taller.

d)

Abnormal height

5.

What is the output of the following code snippet?
int num1=5, num2=9, num3=3;
if ((num1 > num2) && (num1 > num3))
printf("The 1st Number is the greatest among three. \n");
if ((num2 > num3) && (num2 > num1))
printf("The 2nd Number is the greatest among three \n");
if ((num3 > num1) && (num3 > num2))
printf("The 3rd Number is the greatest among three. \n");

a)

The 1st Number is the greatest among three.

b)

The 2nd Number is the greatest among three.

c)

The 3rd Number is the greatest among three.

d)

The 3 numbers are equal

6.

What is the output of the following code snippet?
int sidea=32, sideb=35, sidec=32;
if(sidea==sideb && sideb==sidec)
{ printf("This is an equilateral triangle.\n"); }
else if(sidea==sideb || sidea==sidec || sideb==sidec)
{ printf("This is an isosceles triangle.\n"); }
else
{ printf("This is a scalene triangle.\n"); }

a)

Equilateral

b)

Isosceles

c)

Scalene

7.

Debug the following code below to make it run:
int int1, int2
printf(Input the values for Number1 and Number2 : ");
scanf("%d %d, &int1, int2);
if (int1 == int2);
printf("Number1 and Number2 are equal\n");
else
printf("Number1 and Number2 are not equal\n")

a)

line 1: remove ;
line2: add open "
line 3: remove close " add & for int 2
line 4: remove ;
line 7: remove ;

b)

line 1: add ;
line2: add close "
line 3: add open " add & for int 2
line 4: add ;
line 7: add ;

c)

line 1: add ;
line2: add open "
line 3: add close " add & for int 2
line 4: remove ;
line 7: add ;

8.

Debug the following code below to make it run:
int int1 int2;
printf("Input the values for Number1 and Number2 : ")
scanf("d d", &int1, &int2);
if (int1 = int2)
printf("Number1 and Number2 are equal\n");
else
print("Number1 and Number2 are not equal\n");

a)

line 1: add ,
line2: add ;
line 3: add 2 % symbols before 2 d's
line 4: add =
line 7: add f in print

b)

line 1: remove ,
line2: add ;
line 3: remove 2 % symbols before d
line 4: add !
line 7: remove f in printf

c)

line 1: add ;
line2: add ,
line 3: add 1 % symbol before d
line 5: add =
line 7: add f in printf

9.

What is the output for the specified loop iteration?
for (i=1;i<=10;i++) {
printf("%d ", i);
}
(3rd iteration)

a)

5

b)

3

c)

4

10.

What is the output for the specified loop iteration?
int j, sum = 0;
for (j = 1; j <= 10; j++) {
sum = sum * j;
printf("%d ", sum);
}
(8th iteration)

a)

2

b)

1

c)

0