thespeedracer38

Triad Fixed

Oct 8th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. //WAP TRIAD
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6. int check_rep(int n1,int n2 ,int n3)
  7. {
  8.     int all_one = 1;
  9.     // Changes here
  10.     // OLD: int i, dig;
  11.     // NEW:
  12.     int i; long dig;
  13.     int count[10];
  14.     // Changes here
  15.     // OLD: int num = (int)(n1 * 1e6 + n2 * 1e3 + n3);
  16.     // NEW:
  17.     long num = (long)(n1 * 1e6 + n2 * 1e3 + n3);
  18.     for(i = 0;i < 10;i++)
  19.     {
  20.         count[i] = 0;
  21.     }
  22.     while(num > 0)
  23.     {
  24.         dig = num % 10;
  25.         count[dig]++;
  26.         num = num / 10;
  27.     }
  28.    
  29.     for(i=1;i<10;i++)
  30.     {
  31.         if(count[i] != 1)
  32.         {
  33.             all_one = 0;
  34.             break;
  35.         }
  36.     }
  37.     return (count[0] == 0 && all_one);
  38. }
  39.  
  40. int main()
  41. {
  42.     int n1,n2,n3;
  43.     clrscr();
  44.     for(n1 = 100;n1 < 334;n1++)
  45.     {
  46.         n2 = 2 * n1;
  47.         n3 = 3 * n1;
  48.         if(check_rep(n1,n2,n3))
  49.         {
  50.             printf("%d\t%d\t%d\t\n",n1,n2,n3);
  51.         }
  52.     }
  53.     getch();
  54.     return 0;
  55. }
Add Comment
Please, Sign In to add comment