ex2-1.c
/* code: ex2-1.c (v1.20.00) */
#include <stdio.h>
int main () {
int x, y;
x = 500;
y = 300;
printf ("X = %d\n", x);
printf ("Y = %d\n", y);
if (x > y)
printf ("X is greater than Y.\n");
return 0;
}
ex2-2.c
/* code: ex2-2.c (v1.20.00) */
#include <stdio.h>
int main () {
int x, y;
x = 500;
y = 700;
printf ("X = %d\n", x);
printf ("Y = %d\n", y);
if (x > y)
printf ("X is greater than Y.\n");
else
printf ("X is less than or equal to Y.\n");
return 0;
}
ex2-3.c
/* code: ex2-3.c (v1.20.00) */
#include <stdio.h>
int main () {
char grade;
grade = 'B';
switch (grade) {
case 'A':
printf ("excellent\n");
break;
case 'B':
printf ("good\n");
break;
case 'C':
printf ("fair\n");
break;
case 'D':
printf ("barely passing\n");
break;
case 'F':
printf ("not passing\n");
break;
default:
printf ("ERROR: invalid character\n");
break;
}
printf ("Your grade is %c\n", grade);
return 0;
}
q2-1.c
/* code: q2-1.c (v1.20.00) */
#include <stdio.h>
int main () {
int x, y;
printf ("enter X: ");
scanf ("%d", &x);
printf ("enter Y: ");
scanf ("%d", &y);
printf ("X = %d\n", x);
printf ("Y = %d\n", y);
if (x > y) {
printf ("X is greater than Y.\n");
}
else {
printf ("X is less than or equal to Y.\n");
}
return 0;
}
q2-2.c
/* code: q2-2.c (v1.20.00) */
#include <stdio.h>
int main () {
char grade;
grade = 'b';
switch (grade) {
case 'a':
case 'A':
printf ("excellent\n");
break;
case 'b':
case 'B':
printf ("good\n");
break;
case 'c':
case 'C':
printf ("fair\n");
break;
case 'd':
case 'D':
printf ("barely passing\n");
break;
case 'f':
case 'F':
printf ("not passing\n");
break;
default:
printf ("ERROR: invalid character\n");
break;
}
printf ("Your grade is %c\n", grade);
return 0;
}
q2-3.c
/* code: q2-3.c (v1.20.00) */
#include <stdio.h>
int main () {
int a;
a = 3;
if (a == 0 || a == 1 || a == 2) {
printf ("A\n");
}
else if (a == 3 || a == 4) {
printf ("B\n");
}
else {
printf ("ERROR: invalid number\n");
}
return 0;
}
q2-3a.c
/* code: q2-3a.c (v1.20.00) */
#include <stdio.h>
int main () {
int a;
a = 3;
switch (a) {
case 0:
case 1:
case 2:
printf ("A\n");
break;
case 3:
case 4:
printf ("B\n");
break;
default:
printf ("ERROR: invalid number\n");
break;
}
return 0;
}
EOF