C program to print sum of row in right angle triangle - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Saturday, December 28, 2019

C program to print sum of row in right angle triangle - My CS Tutorial

C program code to print or create a pattern that find sum of row in right angle triangle.
In this tutorial we will learn how to write a c program to find or create a numerical pattern that print sum of row in right angle triangle.We will create a program that print a numerical right angle triangle.


C program code


#include<stdio.h>
#include<conio.h>
void main()
{
 int  a,b,num,sum;
 clrscr();
 printf("\n Enter the number of rows:\n ");
 scanf("%d",&num);
 printf("\n");
 for(a=1;a<=num;a++)
 {
  sum=0;
     for(b=1;b<=a;b++)
     {
      sum+=b;
      if(b!=a)
      {
       printf("%d + ",b);
      }
      else
      {
       printf("%d = ",b);
      }

     }
     printf(" %d",sum);
  printf("\n");
 }
 getch();
}


OUTPUT:




In this output,we will see that it is a right angle triangle that print the sum of rows also.
In the first we will enter the range of rows as 10.
Triangle have 10 rows of numbers.

In this output we can see that the range or size of triangle is 10 and the total lines of numbers in this triangle is 10.
we will enter the range(size) of the  triangle (rows) and press the enter button then the triangle will be print on to the screen.


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

No comments:

Post a Comment