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 main function takes the input n and calls the function nsum.The function nsum finds the sum of the first n natural numbers.

Questions about programming?Chat with your personal AI assistant