triangle counting - count up with increasing intervals The program should read a
ID: 3728397 • Letter: T
Question
triangle counting - count up with increasing intervals The program should read a single integer value, which we'll refer to as n. It should then print out a series of integers as follows. The first value printed is 0 . The second value printed is 1 (0+1) The third value printed is 3 (0+1+2) The fourth value printed is 6 (0+1+2+3) The fifth value printed is 10 (0+1+2+3+4) . etc In other words, the first output value is 0, and each subsequent outpu value can be computed by adding increasing amounts (1, 2, 3,...) to the previous value. The program should print exactly n values. The values should be printed on a single line, separated by at least one space. So, for example, if the input value is 6, then the output of the program should be 0 1 3 6 10 15 Hints Consider using a for loop . Think about what loop variables will be necessaryExplanation / Answer
#include<conio.h>
#include <stdio.h>
void main()
{
int num,sum,i;
clrscr();
printf("Enter positive number ");
sum = 0;
i=0;
scanf ("%d", &num);
while (num > i)
{
sum += i;
printf ("%d ", sum);
i++;
}
getch();
}
Sample Output:
Enter positive number
7
0 1 3 6 10 15 21
Please Provide feedback thumbs up.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.