📐 Day 7 – Checking for a Right-Angled Triangle in C
Hello readers,
I am Mayur Gund, a first-year Computer Science & Engineering student at Sanjivani College of Engineering. Through this blog series “Mayur’s Tech Journey”, I document my daily coding learnings and reflections as I strengthen my programming foundation.
📝 Today’s Program
On Day 7, I worked on a C program that checks whether a triangle is a right-angled triangle using the Pythagoras theorem.
Formula Recap
🖥️ C Code Snippet
#include <stdio.h>
int main()
{
double a, b, c; // sides of the triangle
double d, e, f; // squares of sides
printf("Enter the hypotenuse of a triangle: ");
scanf("%lf", &a);
printf("Enter one side of the triangle: ");
scanf("%lf", &b);
printf("Enter the other side of the triangle: ");
scanf("%lf", &c);
d = a * a;
e = b * b;
f = c * c;
if (d == e + f)
{
printf("The triangle is a right-angled triangle.\n");
}
else
{
printf("The triangle is not a right-angled triangle.\n");
}
return 0;
}
📌 Key Learnings Today
-
Correct use of format specifiers →
%lffordouble. -
Applying mathematical theorems (Pythagoras) in code.
-
Writing and understanding conditional logic (if–else).
-
Realizing the importance of data type accuracy for correct input/output
💡 Reflection
Today’s program connected my knowledge of mathematics and programming beautifully. It felt exciting to see the Pythagoras theorem come alive through code.
This exercise also taught me the importance of choosing the right data types and using the correct format specifiers in scanf. These small details make a big difference in whether a program runs smoothly or not.
Step by step, I’m learning how to translate real-world problems into programs. 🚀
✨ Step by step, building my coding journey 🚀
- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Comments
Post a Comment