Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- int main()
- {
- //All commented out declarations are to be omitted
- //all FLAG variables to be initialized to 1 or 0 depending on later code
- int number;
- int count;
- int add = 0;
- int index;
- //int count2;
- //int index2;
- //int count3;
- //int index3;
- //int isTrue;
- //You cannot sqrt a number without first knowing what it is!
- //do the calculations INSIDE the for loop
- int squareRoot = (int)sqrt(number);
- //int isRight = 0;
- int repeatingFlag;
- int checkZeroFlag;
- int squareRootFlag;
- char stringNumber[10];
- char characterNumber;
- int repeatingArray[10]
- char numberPlaces[10];
- for (count = 111111111; count <= 999999999; count ++)
- {
- //converting to a string
- for (index = 9; index >= 0; index --)
- {
- numberPlaces[index] = number % 10;
- number = number / 10;
- stringNumber[index] = numberPlaces[index] + 48;
- }
- //setup the array to check for repeating
- //reuse index, get rid of count2
- for (count2 = 0; count2 < 10; count2 ++)
- {
- //replace: count2 with index
- repeatingArray[count2] = 0;
- }
- //checking each individual character and counting which one it is
- //reuse index, get rid of index2
- //you're mixing index2 and index here, reusing index will help lower confusion
- for (index2 = 0; index < strlen(stringNumber); index2 ++)
- {
- //replace: index2 with index
- characterNumber = stringNumber[index2];
- switch (characterNumber)
- {
- case '0':
- repeatingArray[0]++;
- break;
- case '1':
- repeatingArray[1]++;
- break;
- case '2':
- repeatingArray[2]++;
- break;
- case '3':
- repeatingArray[3]++;
- break;
- case '4':
- repeatingArray[4]++;
- break;
- case '5':
- repeatingArray[5]++;
- break;
- case '6':
- repeatingArray[6]++;
- break;
- case '7':
- repeatingArray[7]++;
- break;
- case '8':
- repeatingArray[8]++;
- break;
- case '9':
- repeatingArray[9]++;
- break;
- default:
- break;
- }
- }
- //checking each array after counting
- //replace count3 with index
- for (count3 = 0; count3 < 10; count3++)
- {
- //replace: count3 with index
- if(repeatingArray[count3] >= 2)
- {
- repeatingFlag = 0;
- }
- }
- //checking for zeros
- //repeat index3 with index
- for (index3 = 0; index3 < 10; index3++)
- {
- //replace: index3 with index
- characterNumber = stringNumber[index3];
- if(characterNumber == '0')
- //replace: isTrue with checkZeroFlag
- isTrue = 0;
- }
- //checking if perfect square
- //PUT THE EQUATION HERE!!!
- if((squareRoot * squareRoot) == number)
- //replace: isRight with squareRootFlag
- isRight = 1;
- else
- //replace: isRight with squareRootFlag
- isRight = 0;
- if((checkZeroFlag(count) == 1) && (squareRootFlag(count) == 1) && (repeatingFlag(count) == 1))
- {
- add++;
- printf("%d. %d\n", add, count);
- }
- }
- //replace: count with 0
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement