C C++ program to generate series of even numbers and find sum

C C++ program to generate series of even numbers and find sum

C Language के बारे में अधिक जानने के लिए देखें—Brief Introduction of C

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

Flowchart to generate series of even numbers and find sum

Generate series of even numbers and their sum flowchart

C program to generate series of even numbers and find sum

#include<stdio.h>
int main()
{
    int num=2,n,sum=0;
    printf("Enter n: ");
    scanf("%d",&n);
    while(num<=n)
    {
        printf("%d\n",num);
        sum=sum+num;
        num=num+2;
    }
    printf("Sum of series = %d",sum);
    return 0;
}

C++ program to generate series of even numbers and find sum

#include<iostream>
using namespace std;
int main()
{
    int num=2,n,sum=0;
    cout<<"Enter n: ";
    cin>>n;
    while(num<=n)
    {
        cout<<num<<"\n";
        sum=sum+num;
        num=num+2;
    }
    cout<<"Sum of series = "<<sum;
    return 0;
}

Output of C C++ program to generate series of even numbers and find sum

Enter n: 10
2
4
6
8
10
Sum of series: 30
Enter n: 10
2
4
6
8
10
12
14
16
18
20
Sum of series: 110

Important programs using loops in C C++

  1. Generate series of natural numbers (while, for, do while)
  2. Generate series of natural numbers and their sum
  3. Generate series of odd 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