Write a C Program to print triad numbers

Admin

Write a C Program to print triad numbers


#include<stdio.h>
int main(void)
{
    int m,n,p,num;
    int i,k,d1,d2,d3;
    for(num=100; num<=999/3; num++)
    {
        for(i=num; i<=3*num; i+=num )
        {
            k=i;
            d1=k%10; k/=10;
            d2=k%10; k/=10;
            d3=k%10; k/=10;
            if(d1==d2 || d2==d3 || d3==d1)
                goto nextnum;
        }/*End of loop B*/
        for(m=num; m>0; m/=10)
        {
            d1=m%10;
            for(n=num*2; n>0; n/=10)
            {
                d2=n%10;
                for(p=num*3; p>0; p/=10
                {
                    d3=p%10;
                    if(d1==d2 || d2==d3 || d1==d3)
                        goto nextnum;
                }
            }
        }
        printf("%d %d %d\n",num,num*2,num*3);
        nextnum:
        ;   
    }
    return 0;
}


Output



192 384 576
219 438 657
267 534 801
273 546 819
327 654 981

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.