write an algorithm to find the sum of first 50 natural numbers
Answers
Answered by
12
int s=0;i;
for(i=1;i<=50;i++)
{
s=s+i;
}
cout<<s;
Answered by
12
"algorithms to find sum of first 50 natural number
1/2×50×51
1.)Start
2.)Declare a variable of type int i=0 and sum =0
3.)Iteration
for i =0 and i<50
{
sum = sum + i
increment i = i + 1
}
4.)Print Sum
5.)Stop
C++ Syntax
#include<iostream.h>
using namespace std
int main()
{
int i=0;
sum =0;
for(i=0;i<50;++i) // for loop to iterate upto 50
{
sum + = i //sum = sum + i (C++ Shorthands)
}
cout<<”Sum of first 50 numbers : “<<sum;
return 0;
}
"
Similar questions