Generation

code to explanationWed, 07 Dec 2022

#include <stdio.h> int main() { int n,sum; scanf("%d",&n); sum=nsum(n); printf("%d\n",sum); return 0; } int nsum(int n) int i,sum=0; for(i=1;i<=n;i++) { sum+=i; } return sum; }

The function nsum takes a argument n and returns the sum of the first n integers.

Questions about programming?Chat with your personal AI assistant