A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to find sum of all natural numbers
Q:

C program to find sum of all natural numbers

0

 C program to find sum of all natural numbers.
Series: 1+2+3+4+..N

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*This program will print the sum of all natural numbers from 1 to N.*/
 
#include<stdio.h>
     
int main()
{
    int i,N,sum;
     
    /*read value of N*/
    printf("Enter the value of N: ");
    scanf("%d",&N);
     
    /*set sum by 0*/
    sum=0;
     
    /*calculate sum of the series*/
    for(i=1;i<=N;i++)
        sum= sum+ i;
     
    /*print the sum*/
     
    printf("Sum of the series is: %d\n",sum);
     
    return 0;
}
    Enter the value of N: 100
    Sum of the series is: 5050

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now