# C C++ program to generate series of odd numbers and find sum

## C C++ program to generate series of odd numbers and find sum

### Flowchart to generate series of odd numbers and find sum

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

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

### C program to generate series of odd numbers and find sum

``````#include<stdio.h>
int main()
{
int num=1,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 odd numbers and find sum

``````#include<iostream>
using namespace std;
int main()
{
int num=1,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 odd numbers and find sum

```Enter n: 10
1
3
5
7
9
Sum of series = 25```
```Enter n: 20
1
3
5
7
9
11
13
15
17
19
Sum of series = 100```

Share it to: