Sunday, 18 August 2019

combination of numbers - c programming


/*combination of numbers*/
#include<stdio.h>
#include<math.h>
void
main()
{
                int a,b,c,d,s;
                for(a=1;a<8;a++)
                {
                                for(b=1;b<8;b++)
                                {
                                                for(c=1;c<8;c++)
                                                {
                                                                for(d=1;d<8;d++)
                                                                {
                                                                s=(a*a)+(b*b)+(c*c)-(d*d);
                                                                if(s==0)
                                                                {
                                                                                printf("\n combination is %d %d %d %d",a,b,c,d);
                                                                }
                                                }
                                }
                }
}
}
Result:
 combination is 1 2 2 3
 combination is 2 1 2 3
 combination is 2 2 1 3
 combination is 2 3 6 7
 combination is 2 4 4 6
 combination is 2 6 3 7
 combination is 3 2 6 7
 combination is 3 6 2 7
 combination is 4 2 4 6
 combination is 4 4 2 6
 combination is 6 2 3 7
 combination is 6 3 2 7
Press any key to continue

No comments:

Post a Comment

Thanks for comment.