1. #include int main() { int x, y, i; char ch; do { scanf("%d", &x); ch = getchar(); if (ch != '-' && ch != ' ') { printf("Wrong input!\n"); exit(0); } if (ch == '-') { scanf("%d", &y); if (x > y) { printf("Wrong input!\n"); exit(0); } for (i=x; i<=y; i++) printf("%d ", i); ch = getchar(); // read in the next character } else // (ch == ' ') in this case printf("%d ", x); }while (ch != '\n'); putchar('\n'); return 0; } 2. This is the version that does not use array #include int main(void) { long int dec, oct=0, value=1; printf("Enter a decimal number:"); scanf("%d", &dec); printf("(%d)_10 = ", dec); // the following while loop implement the algorithm given in the hw2.txt // you can also use an array to keep the reminders while( dec != 0 ) { oct = oct + dec%8*value; dec = dec/8; value *= 10; } printf("(%d)_8\n", oct); return 0; } 3. #include int main() { int a, b, power=1, i; printf("Enter an integer a and a positive integer b:"); scanf("%d %d", &a, &b); if (b <= 0 ) printf("b = %d is not positive.\n", b); else { for (i=0; i int main(void) { int a, b, c; do { printf("Enter a binary value for a:"); scanf("%d", &a); if (a!=0 && a!=1) printf("Invalid value a = %d\n", a); }while ( a!=0 && a!=1); do { printf("Enter a binary value for b:"); scanf("%d", &b); if (b!=0 && b!=1) printf("Invalid value b = %d\n", b); }while ( b!=0 && b!=1); switch (2*a+b) { case 0: case 3: c = 0; break; case 1: case 2: c = 1; break; default: printf("This should never happen!\n"); } printf("c(%d,%d)=%d\n", a, b, c); return 0; }