Computer Science, asked by ankitray2926, 1 year ago

Write the algorithm to print first 50 number

Answers

Answered by prakhar70065
2

"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;

}

"

hope it helps you

Mark me as Brainlist

Answered by ravi9848267328
0

Answer:

Explanation:

C Code:

#include<stdio.h>

int  numPrint(int);

int main()

{

   int n = 1;

printf("\n\n Recursion : print first 50 natural numbers :\n");

printf("-------------------------------------------------\n");  

printf(" The natural numbers are :");

   numPrint(n);

   printf("\n\n");

   return 0;

}

int numPrint(int n)

{

   if(n<=50)

   {

        printf(" %d ",n);

        numPrint(n+1);

   }

}

Similar questions