i hardly can get a correct output solutions here. please help me it's urgent.

regards,

kckc314

/****************************************************************************** * Description: Assign in all possible ways a digit to each of the letters * * that occur in the words ONE, TWO, SEVEN and NINE, so that: * * - different digits are assigned to different letters; * * - the digit assigned to the first letter of each word * * is not zero; * * - the equality ONE + ONE = TWO holds; * * - SEVEN is a prime number; * * - NINE is a perfect square. * * * ******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <math.h> int main(void) { int O, N, E, T, W, S, V, I, x, y, z; int i, j, k, l, m, n, o, p; unsigned int ONE, TWO, SEVEN, NINE, root; /* Assign a digit to each of the letters that occur in the words * * ONE, TWO, SEVEN and NINE. Different digits are assigned to * * different letters. The digit assigned to the first letter of * * each word is not zero. */ /*for (i = 100; i <= 999; i++) { O = i / 100; for (j = 100; j <= 999; j++) { N = j / 100; E = (i / 10) % 10; for (k = 100; k <= 999; k++) { T = k / 100; W = (k / 10) % 10; for (l = 100; l <= 999; l++) { S = l / 100; V = (l / 10) % 10; I = (j / 10) % 10;*/ for (i = 1; i <= 9; i++) { O = i; for (j = 1; j <= 9; j++) { N = j; for (k = 0; k <= 9; k++) { E = k; for (l = 1; l <= 9; l++) { T = l; for (m = 0; m <= 9; m++) { W = m; for (n = 1; n <= 9; n++) { S = n; for (o = 0; o <= 9; o++) { V = o; for (p = 0; p <= 9; p++) { I = p; /* To verify that different digits are assigned to different * * letters. Then evaluation is performed to assign into variable * * ONE and TWO. */ if ((O != N) && (N != E) && (O != E) && (T != W) && (W != O) && (T != O) && (S != E) && (E != V) && (V != N) && (S != V) && (S != N) && (N != I) && (I != E) && (S != T) && (S != W) && (S != O) && (E != T) && (E != W) && (V != T) && (V != W) && (V != O) && (N != T) && (N != W) && (I != O) && (I != T) && (I != W) && (I != S) && (I != V)) { ONE = (O * 100) + (N * 10) + E; TWO = ONE + ONE; /* To compute NINE is a perfect square with distinct digits. * * The lowest possible value for NINE is 1012, and the square * * root of 1012 is 31.81. To round it up is equal to 32. * * The highest possible value for NINE is 9897, and the * * square root of 9897 is 99.48. To round it down is equal to * * 99. The loop will take from the lowest value 32 until the * * highest value 99 then it terminates. From the result break * * into single digit from the 4 digits number and assign them * * into letters N, I, N, E for comparison check later. */ for (y = 32; y <= 99; y++) { N = (y * y) / 1000; I = ((y * y) % 1000) / 100; N = (((y * y) % 1000) % 100) / 10; E = ((((y * y) % 1000) % 100) % 10) / 1; if ((N != I) && (I != E) && (N != E) && (N != O) && (N != T) && (N != W) && (N != S) && (N != V) && (I != O) && (I != T) && (I != W) && (I != S) && (I != V) && (E != O) && (E != T) && (E != W) && (E != S) && (E != V)) NINE = y * y; } /* To compute SEVEN is a prime number with distinct digits. */ SEVEN = (S * 10000) + (E * 1000) + (V * 100) + (E * 10) + N; bool isPrime = true; root = sqrt(SEVEN); for (z = 2; z <= root; z++) if (SEVEN % z == 0) { isPrime = false; break; } if (isPrime = true) printf("one = %u, two = %u, seven = %u and nine = %u is a solution.\n", ONE, TWO, SEVEN, NINE); } } } } } } } } } system("PAUSE"); return EXIT_SUCCESS; }

This post has been edited by **kckc314**: 05 April 2008 - 05:47 PM