Inactive Tutor answered 07/15/20
#include <stdio.h>
int main()
{
int N;
printf(" Please input the value of N :>");
scanf("%d",&N);
long n = N*(N+1)/2;
printf("The sum of the first N (positive or negative)integers is +or- %ld \n",n);
}
Zayn Q.
asked 07/15/20Write a C program that calculate the sum of first n natural numbers and sum of first n negative number. You need to get n value form user. Make a proper display for choice.
Hint:
1. Array
2. Decision Statement
Inactive Tutor answered 07/15/20
#include <stdio.h>
int main()
{
int N;
printf(" Please input the value of N :>");
scanf("%d",&N);
long n = N*(N+1)/2;
printf("The sum of the first N (positive or negative)integers is +or- %ld \n",n);
}
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.