Q:

C Program to Find the Sum of first 10 Natural Numbers

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  • C Program to Find the Sum of first 10 Natural Numbers Using For Loop 
  • C Program to Find the Sum of first 10 Natural Numbers Using While Loop
  • C Program to Find the Sum of first 10 Natural Numbers Using Do While Loop
  • C Program to Find the Sum of first 10 Natural Numbers Using Array
  • C Program to Find the Sum of first 10 Natural Numbers Using Function
  • C Program to Find the Sum of first 10 Natural Numbers Using Recursion

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C Program to Find the Sum of first 10 Natural Numbers Using For Loop 

Algorithm

  • Program Start
  • Declaration of Variable
  • Calculating Sum of 1st 10 Naturals Numbers
  • Displaying the Sum first 10 Naturals Numbers
  • Program End

Program

//C Program to Find the Sum of first 10 Natural Numbers Using For loop

#include<stdio.h>
void main()
{
 //Declaring Variable
  int i, sum = 0;

  for(i=1;i<=10;i++)
  {
       sum = sum + i;
  }
  printf("\nSum of first 10 Natural Numbers is : %d", sum);
}

Output

Sum of first 10 Natural Numbers is : 55

 

C Program to Find the Sum of first 10 Natural Numbers Using While Loop 

Program

//C Program to Find the Sum of first 10 Natural Numbers Using While loop

#include<stdio.h>
void main()
{
 //Declaring Variable
  int i=1, sum = 0;

//Calculating Sum
  while(i<=10)
  {
       sum = sum + i;
       i++;

  }
  printf("\nSum of first 10 Natural Numbers is : %d", sum);
}

Output

Sum of first 10 Natural Numbers is : 55

 

C Program to Find the Sum of first 10 Natural Numbers Using Do While Loop 

Program

//C Program to Find the Sum of first 10 Natural Numbers Using While loop

#include<stdio.h>
int main()
{
 //Declaring Variable
  int i=1, sum = 0;

  do
  {
       sum = sum + i;
       i++;

  }while(i<=10);

  printf("\nSum of first 10 Natural Numbers is : %d", sum);
  
 return 0;
}

Output

Sum of first 10 Natural Numbers is : 55

 

C Program to Find the Sum of first 10 Natural Numbers Using Array

Program

//C Program to Find the Sum of first 10 Natural Numbers Using Array

#include<stdio.h>
void main()
{
 //Declaring Variable
  int i, sum = 0 , a[10]= {1,2,3,4,5,6,7,8,9,10};

//Calculating Sum
  for(i=0;i<10;i++)
  {
       sum = sum + a[i];

  }

//printing Sum
  printf("\nSum of first 10 Natural Numbers is : %d", sum);
}

Output

Sum of first 10 Natural Numbers is : 55

 

C Program to Find the Sum of first 10 Natural Numbers Using Function

Program

//C Program to Find the Sum of first 10 Natural Numbers Using Function

#include<stdio.h>
int sum();
int main()
{
 //Declaring Variable
  int s;
 
  s =sum();
  printf("\nSum of first 10 Natural Numbers is : %d", s);
  
 return 0;
}
int sum()
{
    int i, sum = 0;

  for(i=1;i<=10;i++)
  {
       sum = sum + i;
  }
  return (sum);

}

Output

Sum of first 10 Natural Numbers is : 55

 

C Program to Find the Sum of first 10 Natural Numbers Using Recursion

Program

//C Program to Find the Sum of 1st 10 Natural Numbers Using Recursion

#include<stdio.h>
int sum();
int main()
{
 //variable declaration
  int s;

  s=sum(10); //Calling Recursive Function 
  printf("\nSum of first 10 Natural Numbers is : %d", s);

 return 0;
}
int sum(int n)
{
    int s=0;

    if(n==1)
        return (n);

    s = n + sum(n-1);
     return (s);
}

Output

Sum of first 10 Natural Numbers is : 55

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program To Print Sum of Odd Numbers Between 1 To... >>
<< C Program to Find the Sum of first n even Numbers...