Introduction

The main purpose of this blog is to share our experience with the world and get experience from the world. This will be a new venture for us and we are sure, we shall learn a lot with it. we will try to Explore our mind which will be very helpful for all us. As from its name, its a blog covering all the topics. we will try to post all the interesting topics and give our opinion. Do give your point of view in comments.


"NAVIGATE VIA BLOG ARCHIVE ON RIGHT TO GET WHAT YOU ARE LOOKING FOR"


Thursday, January 27, 2011

C CODE FOR COMPLETE SQUARE TRIANGLE

The following code will print upto 20 the triangle whos hypotenuse is a complete square. You can extend the limits by doing some changes in the code to your desire.

#include <stdio.h>  
#include <math.h>    // for sqrt root function
int main ()         
{
int b,p;             // initialization
int h;           // initialization
printf("All the Applicable Triangles are:\n");
printf("Base \t Perp \t   Hyp \n"); // to represent sides of triangle which are satisfied by pythagoras theorem
  for(b=1;b<=19;b++)   // first loop starts with one side from 1-19
     { for (p=1; p<=19;p++) // second loop starts with b=loop state untill p=19
             { for (h=sqrt((p*p)+(b*b));h==sqrt((p*p)+(b*b));h++) // 3rd loop takes the first input only and becomes false for nxt loop so no further execution occurs
               if (h>=20)   // if hyp is more than 20 sides wont be printed
               break;
               else  
               {printf(" %d \t  %d \t   %d \n",b,p,h); // sides printed if h^2=b^2+p^2 ans is integer
             } // end of third loop
      } // end of second loop
    } //end of first loop
return 0;
} //end main

No comments:

Post a Comment

Related Posts with Thumbnails