#include <stdio.h> main() { int number, right_digit; printf("Enter your number\n"); scanf("%d",&number); while (number !=0) { right_digit = number % 10; printf("%d",right_digit); number /= 10; } /*return cursor to next line*/ printf("\n"); }
#include <stdio.h> #define max 100 #define min 1 main() { int number; number = 0; while ( number < min || number > max) { printf("Enter a number in the range 1 to 100\n"); scanf("%d",&number); } printf("the number is in range\n"); }
#include <stdio.h> main() { char letter; printf("Press Y to continue\n"); do { letter = getchar(); } while (letter != 'y' && letter != 'Y'); printf("program execution will continue\n"); }
#include <stdio.h> main() { float inches,centimetres; /* print table header*/ printf("inches\et centimetres\n"); /*calculate and print table entries*/ for (inches = 1; inches <=10 ; inches += 0.5) { centimetres = 2.54 * inches; printf("%6.2f %7.2f\n",inches,centimetres); } }
Back to Main Page for Lecture 4 |