Advertisement
Anthei

Noted

May 28th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. int main()
  7. {
  8.     //All commented out declarations are to be omitted
  9.     //all FLAG variables to be initialized to 1 or 0 depending on later code
  10.     int number;
  11.     int count;
  12.     int add = 0;
  13.     int index;
  14.     //int count2;
  15.     //int index2;
  16.     //int count3;
  17.     //int index3;
  18.     //int isTrue;
  19.     //You cannot sqrt a number without first knowing what it is!
  20.     //do the calculations INSIDE the for loop
  21.     int squareRoot = (int)sqrt(number);
  22.     //int isRight = 0;
  23.     int repeatingFlag;
  24.     int checkZeroFlag;
  25.     int squareRootFlag;
  26.     char stringNumber[10];
  27.     char characterNumber;
  28.     int repeatingArray[10]
  29.     char numberPlaces[10];
  30.  
  31.     for (count = 111111111; count <= 999999999; count ++)
  32.     {
  33.         //converting to a string
  34.         for (index = 9; index >= 0; index --)
  35.         {
  36.             numberPlaces[index] = number % 10;
  37.             number = number / 10;
  38.             stringNumber[index] = numberPlaces[index] + 48;
  39.         }
  40.        
  41.         //setup the array to check for repeating
  42.         //reuse index, get rid of count2
  43.         for (count2 = 0; count2 < 10; count2 ++)
  44.         {
  45.             //replace: count2 with index
  46.             repeatingArray[count2] = 0;
  47.         }
  48.        
  49.         //checking each individual character and counting which one it is
  50.         //reuse index, get rid of index2
  51.         //you're mixing index2 and index here, reusing index will help lower confusion
  52.         for (index2 = 0; index < strlen(stringNumber); index2 ++)
  53.         {
  54.             //replace: index2 with index
  55.             characterNumber = stringNumber[index2];
  56.  
  57.             switch (characterNumber)
  58.             {
  59.                 case '0':
  60.                     repeatingArray[0]++;
  61.                     break;
  62.                 case '1':
  63.                     repeatingArray[1]++;
  64.                     break;
  65.                 case '2':
  66.                     repeatingArray[2]++;
  67.                     break;
  68.                 case '3':
  69.                     repeatingArray[3]++;
  70.                     break;
  71.                 case '4':
  72.                     repeatingArray[4]++;
  73.                     break;
  74.                 case '5':
  75.                     repeatingArray[5]++;
  76.                     break;
  77.                 case '6':
  78.                     repeatingArray[6]++;
  79.                     break;
  80.                 case '7':
  81.                     repeatingArray[7]++;
  82.                     break;
  83.                 case '8':
  84.                     repeatingArray[8]++;
  85.                     break;
  86.                 case '9':
  87.                     repeatingArray[9]++;
  88.                     break;
  89.                 default:
  90.                     break;
  91.             }
  92.         }
  93.        
  94.         //checking each array after counting
  95.         //replace count3 with index
  96.         for (count3 = 0; count3 < 10; count3++)
  97.         {
  98.             //replace: count3 with index
  99.             if(repeatingArray[count3] >= 2)
  100.             {
  101.                 repeatingFlag = 0;
  102.             }
  103.         }
  104.        
  105.         //checking for zeros
  106.         //repeat index3 with index
  107.         for (index3 = 0; index3 < 10; index3++)
  108.         {
  109.             //replace: index3 with index
  110.             characterNumber = stringNumber[index3];
  111.             if(characterNumber == '0')
  112.                 //replace: isTrue with checkZeroFlag
  113.                 isTrue = 0;
  114.         }
  115.        
  116.         //checking if perfect square
  117.         //PUT THE EQUATION HERE!!!
  118.         if((squareRoot * squareRoot) == number)
  119.             //replace: isRight with squareRootFlag
  120.             isRight = 1;
  121.         else
  122.             //replace: isRight with squareRootFlag
  123.             isRight = 0;
  124.  
  125.         if((checkZeroFlag(count) == 1) && (squareRootFlag(count) == 1) && (repeatingFlag(count) == 1))
  126.         {
  127.             add++;
  128.             printf("%d. %d\n", add, count);
  129.         }
  130.     }
  131.     //replace: count with 0
  132.     return count;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement