Hello There, Guest! Login Register
Advertise Here | Remove Ads

C Program to Find Sum of Natural Numbers

  • 0 Vote(s) - 0 Average
Thread Closed


02-03-2016, 07:04 PM #1
Sadness Offline MODERATOR MODERATORS
Posts:4,001 Threads:565 Joined:Sep 2014 Reputation: 13 Sex Female
FFUC: $0
Country: Bangladesh
Code:
#include <stdio.h>
int main()
{
    int n, count, sum=0;
    printf("Enter an integer: ");
    scanf("%d",&n);
    if ( n<= 0)
        printf("Error!!!!");
    else
    {
       for(count=1;count<=n;++count)  /* for loop terminates if count>n */
       {
          sum+=count;                    /* sum=sum+count */
       }
       printf("Sum = %d",sum);
    }
    return 0;
}

[Image: SeoClerks728x90.png]






Forum Jump:


Users browsing this thread:1 Guest(s)

Advertise Here | Remove Ads