Rahul wants to display the n terms of odd natural number and calculate their sum. Help him
to develop a program in C to perform the task using for loop.
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int sum = 0;
for (int i = 1; i <= n; i++) {
sum = sum + i;
}
printf("%d", sum);
return 0;
}
Comments
Leave a comment