I l @ ve RuBoard |
Assume all variables are of type int . Find the value of each of the following variables:
x = (2 + 3) * 6;
x = (12 + 6)/2*3;
y = x = (2 + 3)/4;
y = 3 + 2*(x = 7/2);
Assume all variables are of type int . Find the value of each of the following variables:
x = (int) 3.8 + 3.3;
x = (2 + 3) * 10.5;
x = 3 / 5 * 22.0;
x = 22.0 * 3 / 5;
You suspect that there are some errors in the next program. Can you find them?
int main(void) { int i = 1, float n; printf("Watch out! Here come a bunch of fractions!\n"); while (i < 30) n = 1/i; printf(" %f", n); printf("That's all, folks!\n"); return; }
Here's a first attempt at making min_sec interactive, but the program is not satisfactory. Why not? How can it be improved?
#include <stdio.h> #define S_TO_M 60 int main(void) { int sec, min, left; printf("This program converts seconds to minutes and "); printf("seconds.\n"); printf("Just enter the number of seconds.\n"); printf("Enter 0 to end the program.\n"); while (sec > 0) { scanf("%d", &sec); min = sec/S_TO_M; left = sec % S_TO_M; printf("%d sec is %d min, %d sec. \n", sec, min, left); printf("Next input?\n"); } printf("Bye!\n"); return 0; }
What will this program print?
#include <stdio.h> #define FORMAT "%s is a string\n" int main(void) { int num = 0; printf(FORMAT,FORMAT); printf("%d\n", ++num); printf("%d\n", num++); printf("%d\n", num--); printf("%d\n", num); return 0;
What will this program print?
#include <stdio.h> int main(void) { char c1, c2; int diff; float num; c1 = `D'; c2 = `A'; diff = c1 - c2; num = diff; printf("%c%c%c:%d %3.2f\n", c1, c2, c1, diff, num); return 0;
What will this program print?
#include <stdio.h> #define TEN 10 int main(void) { int n = 0; while (n++ < TEN) printf("%5d", n); printf("\n"); return 0;
Modify the last program so that it prints the letters a through g instead.
If the following fragments were part of a complete program, what would they print?
int x = 0; while (++x < 3) printf("%4d", x);
int x = 100; while (x++ < 103) printf("%4d\n",x); printf("%4d\n",x);
char ch = `s'; while (ch < `w') { printf("%c", ch); ch++; } printf("%c\n",ch);
What will the following program print?
#define MESG "COMPUTER BYTES DOG" #include <stdio.h> int main(void) { int n = 0; while ( n < 5 ) printf("%s\n", MESG); n++; printf("That's all.\n"); return 0;
Construct statements that do the following (or, in other terms, have the following side effects):
Increase the variable x by 10 .
Increase the variable x by 1 .
Assign twice the sum of a and b to c .
Assign a plus twice b to c .
Construct statements that do the following:
Decrease the variable x by 1 .
Assigns to m the remainder of n divided by k .
Divide q by b minus a and assign the result to p .
Assign to x the result of dividing the sum of a and b by the product of c and d .
I l @ ve RuBoard |