• Now Online : 86
  • admin@codemyne.net

Introduction

The program shows the sum of n natural numbers. A number should be entered by the user, if 10 entered sum first 10 natural numbers can be calculated. By using the formula (n*(n+1))/2 sum of natural numbers can be calculated.

#include<stdio.h>
#include<conio.h>
        void main()
        {
            int a,n;
            printf("/n Enter a number");
            scanf("%d",&n);
            a=(n*(n+1))/2;
            printf("Sum of natural numbers upto %d is %d",n,a);
            getch();
        }

Comments/Suggestions are invited. Happy coding......!

Comments Post a Comment