Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //WAP TRIAD
- #include <stdio.h>
- #include <conio.h>
- int check_rep(int n1,int n2 ,int n3)
- {
- int all_one = 1;
- // Changes here
- // OLD: int i, dig;
- // NEW:
- int i; long dig;
- int count[10];
- // Changes here
- // OLD: int num = (int)(n1 * 1e6 + n2 * 1e3 + n3);
- // NEW:
- long num = (long)(n1 * 1e6 + n2 * 1e3 + n3);
- for(i = 0;i < 10;i++)
- {
- count[i] = 0;
- }
- while(num > 0)
- {
- dig = num % 10;
- count[dig]++;
- num = num / 10;
- }
- for(i=1;i<10;i++)
- {
- if(count[i] != 1)
- {
- all_one = 0;
- break;
- }
- }
- return (count[0] == 0 && all_one);
- }
- int main()
- {
- int n1,n2,n3;
- clrscr();
- for(n1 = 100;n1 < 334;n1++)
- {
- n2 = 2 * n1;
- n3 = 3 * n1;
- if(check_rep(n1,n2,n3))
- {
- printf("%d\t%d\t%d\t\n",n1,n2,n3);
- }
- }
- getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment