It\'s for C++ Write a program that calculates triangle numbers by using a recurs
ID: 3777376 • Letter: I
Question
It's for C++ Write a program that calculates triangle numbers by using a recursive function. A triangle number is the sum of all whole numbers from 1 to N, in which N is the number specified. For example, triangle(5) = 5 + 4 + 3 + 2 + 1. Instructions for submission: Each group uploads one set of files, including a word document and a zip file including the codes. Please write the group member names at the first line of the word document. The .zip file is the compressed file of four separate folders including the codes. The word file includes the screen captures of the four programs.Explanation / Answer
#include<bits/stdc++.h>
using namespace std;
int sum=0;
int traingle(int n)
{
if(n != 0)
return n + traingle(n-1);
else
return n;
}
int main(int argc, char const *argv[])
{
cout<<"Enter number ";
int n;
cin>>n;
cout<<traingle(n);
return 0;
}
=================================
akshay@akshay-Inspiron-3537:~/Chegg$ g++ tra.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Enter number
5
Traingle number is15
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.