Programming with C

CSCI 3133

Sample!

PART I. Answer “True” or “False”

1. A Personal Computer is an example of Personal Computing Environment

2 In Time-Sharing Environment many users are connected to one or more computers in shared environment.

3.  A Linker translates symbolic languauge into machine language, they soon became Assembly Language.

4.  Pseudocode is steps to accomplish the task in graphical symbols .

5.  Parallelogram denotes a decision point (if/then/else) in Flowchart diagram. .

6.  Boolean can represent only two values, referred to as true and false.

7. 

8.  C supports logical type through Boolean type or the integer type , any nonzero represent false and zero represent

9.  char a, int i, float tax, void x are valid variable declarations.

10.  The keyboard is called Standard output file

11.  The standard output function is scanf

12. 

13. 

PART II Trace the following program

38. 

And write down their outputs.

1. Which is the error in the given code.

#include <stdio.h>

int x;

int main ()

{

x = 7.5 % 3;

return 0;

}

3 . Write the output for the following code

#include <stdio.h>

int main (void) /* example of Postfix increment*/

{

int a;

a = 5;

printf("%d", --a );

return 0;

}

4. Write the output for the following code

#include <stdio.h>

int main (void)

{

int a;

a = 5;

printf("%d", a++);

return 0;

}

5. . Write the output for the following code

#include <stdio.h>

int main (void) /* example of Postfix increment*/

{

int a;

a = 5;

a++;

printf("%d", a);

return 0;

}

6. Write the output for the following code

#include <stdio.h>

int main (void)

{

int a = 2;

int b = 3;

int c = 4;

int d= a * b + c;

printf ("%d",d );

return 0;

}

7. Write the output for the following code

#include <stdio.h>

int main (void)

{

int a = 2;

int b = 3;

int c = 4;

int d=2;

int e= a * b + c/d;

printf ("%d",e );

return 0;

}

8. Write the output for the following code

#include <stdio.h>

int main (void)

{

int a = 2;

int b = 3;

int c = 4;

int d=2;

int e= a * b % c/d;

printf ("%d", e );

return 0;

}

9. Write the output for the following code

#include <stdio.h>

int main (void)

{

int a = 2;

int b = 3;

int c = 4;

int d=2;

int e= a +=b *=c -=5;

printf ("%d", e );

return 0;

}

10. Write the output for the following code

#include <stdio.h>

int main (void)

{

int a = 9;

int b = 3;

double c;

c=(double)(a/b);

printf ("%0.2f", c );

return 0;

}

11. Write the output for the following code

#include<stdio.h>

int main ( )

{

int option_select = 3, int num1=4, num2=2;

switch(option_select)

{

case 1:

printf("%d", num1+num2);

break;

case 2:

printf("%d\n", num1+num2);

case 3:

printf("%d\n", num1-num2);

case 4:

printf("%d\n", num1*num2);

break;

default:

printf("%d\n", num1/num2);

}

12. Write the output for the following code

}

#include <stdio.h>

int main ( )

{

int count =1;

while (count < 10)

{

printf("%d ", count);

count += 2;

}

}

Part III

  1. Which of the following expression will generate error?
  1. x = x +2;
  2. x-=x;
  3. x+2=x
  4. x%=2

2  Which of the following are not postfix operators.

a. x++

b. ++x

c. x*y

d. x--

4.  Which of the following are not postfix operators

a. x++

b. ++x

c. x*y

d.  x- -

5.  Which of the following is not a valid identifier ?

a.  _table

b.  student-info

c.  else

d. 4carInventory

Assume all variables are of type int and each expression is independent of other one. Find the value of y for the following expressions :

a=3, b=5, c=6 , d = -6 , y=0;

25. y= a++ * ++d + ++c; ------

26. y= --a/++b + d--/2; ------

27. y -= c; ------

28. y = a +c/a; ------

29. y = d – 3 * b +2; ------

30. y += c ; ------

Indicate where the error is for the following function definitions.

void fun ( float x, float y)

{

x = 2.0;

y = 3.0

y += x;

return y;

}

Indicate where the error is for the following function definitions.

void (void a, void b)

{

a = b;

return;

}

What value gets printed in the following program?

#include <stdio.h>

void printOne (int x);

int main (void)

{

int a;

a = 5;

printOne (a);

printf("%d\n", a);

return 0;

}

void printOne (int x)

{

x =2;

return;

}

What value gets printed in the following program?

#include <stdio.h>

int printOne (int x);

int main (void)

{

int a,y;

a = 5;

y=printOne (a);

printf("%d\n", y);

return 0;

}

int printOne (int x)

{

x *=2;

return x;

}

What value gets printed in the following program?

#include <stdio.h>

int printOne (int *x);

int main (void)

{

int a,y;

a = 5;

printOne (&a);

printf("%d\n", a);

return 0;

}

int printOne (int *x)

{

*x =*x+2;

return x;

}

What values get printed in the following program?

#include <stdio.h>

int main (void)

{

int num = 5;

while (num > 0)

{

printf(" %d", --num);

}

return 0;

}

What values get printed in the following program?

#include <stdio.h>

int main (void)

{

int i;

for ( i=5; i > 0; i--)

{

printf(" %d", i);

}

return 0;

}

What values get printed in the following program?

#include <stdio.h>

int main (void)

{

int i;

for ( i=0; i <5; i+=2)

{

printf(" %d", i);

}

return 0;

Write a program – 20%

7