Its for C Write a program that calculates triangle numbers b

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.

Solution

#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

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site