You are on page 1of 2

1.

What would the equivalent code, using a while loop, be for the example

for(i = 0; i < 10; i = i + 1)


printf("i is %d\n", i);

2. What is the numeric value of the expression 3 < 4 ?

3. Under what conditions will this code print ``water''?

if(T < 32)


printf("ice\n");
else if(T < 212)
printf("water\n");
else printf("steam\n");

4. What would this code print?

int x = 3;
if(x)
printf("yes\n");
else printf("no\n");

5. (trick question) What would this code print?

int i;

for(i = 0; i < 3; i = i + 1)
printf("a\n");
printf("b\n");

printf("c\n");

6. Write down the output of the program?

printf("On the ");


if(day == 1) printf("first");
else if(day == 2) printf("second");
else if(day == 3) printf("third");
else if(day == 4) printf("fourth");
else if(day == 5) printf("fifth");
else if(day == 6) printf("sixth");
else printf("%d", day);
printf(" day of Christmas, ");
printf("my true love gave to me\n");
7. Write down the output of the program?
#include <stdio.h>

int main()
{
int i, j;
for(i = 1; i <= 10; i = i + 1)
{
for(j = 1; j <= 10; j = j + 1)
{
if((i + j) % 2 == 0)
printf("* ");
else printf(" ");
}
printf("\n");
}
return 0;
}

8. Find out the error in the program.

#include<stdio.h>

int main(void)
{

  int cc;
  float price;
  double discount;

  printf("Enter your car cc:");


  scanf("%d",&cc);
  printf("Enter the price of your car:");
  scanf("%f",&price);

  if(cc=800)
     discount=price-(0.05*price);
  else
     discount=price-(0.08*price);
 return 0;
}

You might also like