google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to find the sum of first n natural numbers - 2nd puc computer science

Write a program to find the sum of first n natural numbers

Write a program to find the sum of first n natural numbers

#include<stdio.h>

#include<conio.h>

void main()

{

int n,sum=0,i=1;

clrscr();

printf("Enter the number: ");

scanf("%d",&n);

while(i<=n)

{

sum=sum+i;

i++;

}

printf("Sum=%d",sum);

getch();

}

Output:

Enter the number: 5

Sum=15                                    

Write a program to find the sum of first n natural numbers Write a program to find the sum of first n natural numbers Reviewed by Vision Academy on December 08, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.