Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void main(){
  4.     int input = 1;
  5.     int errors = 0;
  6.     int runCount = 0;
  7.     int input1 = 0, input2 = 0;
  8.     int isPerfect = 0, isGerman = 0, isLowerPair = 0, isPrime = 0, isPalindrome = 0;
  9.     int sum = 0;
  10.     int i, j;
  11.     while (input != 0 && errors < 5){
  12.         sum = 0;
  13.         isPerfect = isGerman = isLowerPair = isPrime = isPalindrome = 0;
  14.         if (input == 1 || input == 2){
  15.             printf("The menu:\n 0. Exit.\n 1. Print menu again.\n 2. Number details in range.\n 3. Layers square printing.\n Please enter your choice:\n");
  16.             scanf("%d", &input);
  17.             if (input == 1){
  18.  
  19.             } else if (input == 2){
  20.                 printf("Please enter the first int positive number (up to 8 digits):\n");
  21.                 scanf("%d", input1);
  22.                 while (input1 < 1 || input1 > 99999999){
  23.                     printf("Please enter the first int positive number (up to 8 digits):\n");
  24.                     scanf("%d", input1);
  25.                 }
  26.  
  27.                 while (input2 < input1 + 10 && input2 > input1 + 150){
  28.                     printf("Please enter the 2nd positive number between %d and %d:\n", input1 + 10, input1 + 150);
  29.                     scanf("%d", input2);
  30.                 }
  31.  
  32.                 for (i = input1; i <= input2; i++){
  33.                     for (j = 1; j < i; j++){
  34.                         if (i % j == 0){
  35.                             sum += j;
  36.                         }
  37.                     }
  38.  
  39.                     isGerman = 1;
  40.                     for (j = 2; j < 2 * i + 1; j++){
  41.                         if (i % j == 0){
  42.                             isGerman = 0;
  43.                             break;
  44.                         }
  45.                     }
  46.  
  47.                     isPrime = 1;
  48.                     for (j = 2; j < i; j++){
  49.                         if (i % j == 0){
  50.                             isPrime = 0;
  51.                             break;
  52.                         }
  53.                     }
  54.  
  55.                     isLowerPair = 1;
  56.                     if (isPrime){
  57.                         for (j = 2; j < i - 2; j++){
  58.                             if ((i - 2) % j == 0){
  59.                                 isLowerPair = 0;
  60.                                 break;
  61.                             }
  62.                         }
  63.                     }
  64.                 }
  65.             } else {
  66.                 errors++;
  67.             }
  68.         }
  69.         else if (input != 0 && errors < 5){
  70.             printf("Wrong input. please try again (enter 1 for re-printing the menu) :\n");
  71.             scanf("%d", &input);
  72.             if (input != 1 && input != 2){
  73.                 errors++;
  74.             }
  75.         }
  76.     }
  77.  
  78.    
  79.     printf("bye bye !!\n");
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement