Assignments » Flow Of Control » Set2 » Solution 2

Write a program to calculate the sum of first 10 natural number.

 

#include<iostream>
using namespace std;

int main()
{
	int i=1,sum=0;

	while(i<=10)
	{
		sum+=i;
		i++;
	}

	cout<<"Sum :"<<sum;

    
	return 0;
}

 

 

Sum : 55

 

«back