new to program writing

Write a program that uses a function to calculate the sum of all numbers from 1 to n then prints the result to the screen. The name of the function should be: sum. e.g. if n=5 then sum= 1+2+3+4+5
Here you are:)

inline int sum( int n ) { return ( n * ( n + 1 ) / 2 ); }
Topic archived. No new replies allowed.