Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Create a program that calculates and displays the first n numbers from the Tr

ID: 3722365 • Letter: 3

Question

3. Create a program that calculates and displays the first n numbers from the Triangular number series: (Challenge: Can you display the dots using printf() function?) Triangular Number The triangular number T is a figurate number that can be represented in the form of a triangular grid of points where the first row contains a single element and each subsequent row contains one more element than the previous one. This is illustrated above for T1 = 1, T2-3, The triangular numbers are therefore 1,1+21+2+3, 1 +2 +3 +4 , so for n=12 are 1, 3, 6, 10, 15, 21, More formally, a triangular number is a number obtained by adding all positive integers less than or equal to a given positive integer n, i.e., , the first few , n(n +1) (n +1

Explanation / Answer

//C program to calculate and display the first n element of traingular series

#include <stdio.h>

int main() {

//code

int ne; // no of element in the series

printf("Enter the no. of element of traingular series that you want to diplay.. ");

scanf("%d",&ne);

int i,j,n;// varibles the we have used in code

for(n=1;n<=ne;n++) //

{

printf("________________________________________________________________________________________ ");

printf("T%d :%d ",n,(n*(n+1))/2);

if(n%2==1) // this block display odd no. position's element

{

int x=n/2+1;

for(i=1;i<x;i++)

{

for(j=1;j<=i;j++)

printf(". ");

printf(" ");

for(j=1;j<=i;j++)

printf(" .");

printf(" ");

}

for(i=1;i<=x;i++)

printf(". ");

printf(" ");

for(i=x-1;i>=1;i--)

{

for(j=1;j<=i;j++)

printf(" .");

printf(" ");   

for(j=1;j<=i;j++)

printf(". ");

printf(" ");   

}

}

else // this code of block display even positions element of series

{

int x=n/2;

for(i=1;i<x;i++)

{

for(j=1;j<=i;j++)

printf(". ");

printf(" ");

for(j=1;j<=i;j++)

printf(" .");

printf(" ");   

}

for(i=1;i<=x;i++)

printf(". ");

printf(" ");

for(i=1;i<=x;i++)

printf(" .");

printf(" ");

for(i=1;i<=x;i++)

printf(". ");

printf(" ");   

for(i=x-1;i>=1;i--)

{

for(j=1;j<=i;j++)

printf(" .");

printf(" ");   

for(j=1;j<=i;j++)

printf(". ");

printf(" ");

}

  

}

printf(" ");

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote