Write a C C++ program to generate series of natural numbers

Write a C C++ program to generate series of natural numbers

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

Flowchart to generate series of natural numbers

Generate series of natural numbers flowchart

C program to generate series of natural numbers using while loop

#include<stdio.h>
int main()
{
    int num=1;
    while(num<=5)
    {
        printf("%d\n",num);
        num++;
    }
    return 0;
}

C program to generate series of natural numbers using for loop

#include<stdio.h>
int main()
{
    int num;
    for(num=1; num<=5; num++)
    {
        printf("%d\n",num);
    }
    return 0;
}

C program to generate series of natural numbers using do while loop

#include<stdio.h>
int main()
{
    int num=1;
    do
    {
        printf("%d\n",num);
        num++;
    }while(num<=5);
    return 0;
}

C++ program to generate series of natural numbers using while loop

#include<iostream>
using namespace std;
int main()
{
    int num=1;
    while(num<=5)
    {
        cout<<num<<"\n";
        num++;
    }
    return 0;
}

C++ program to generate series of natural numbers using for loop

#include<iostream>
using namespace std;
int main()
{
    int num;
    for(num=1; num<=5; num++)
    {
        cout<<num<<"\n";
    }
    return 0;
}

C++ program to generate series of natural numbers using do while loop

#include<iostream>
using namespace std;
int main()
{
    int num=1;
    do
    {
        cout<<num<<"\n";
        num++;
    }while(num<=5);
    return 0;
}

Output of C C++ program to generate series of natural numbers using while, for and do while loops

1
2
3
4
5

Other looping programs in C C++

  1. Generate series of natural numbers and their sum
  2. Generate series of odd numbers and find their sum
  3. Generate series of even numbers and find their sum
  4. Generate table of given number
  5. Find factorial of given number
  6. Find power of given number
  7. Generate multiplication table of given number
  8. HCF and LCM of two numbers
  9. Generating Fibonacci series
  10. Checking prime number
  11. Generating series of prime numbers
  12. Sum of digits of given number
  13. Reverse of digits of given number
  14. Checking palindrome number
  15. Checking Armstrong number
  16. Generating series of Armstrong numbers
  17. Convert decimal to binary
  18. Convert binary to decimal
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer