Header Ads Widget

Write a C++ program that print first 10 odd numbers using loop

 

Write a C++ program that print first 10 odd numbers using loop

Given a number , write a program to find the factorial of a given numbers .

Sample output:

1 3 5 7 9 11 13 15 17 19 

 Write a C++ program to calculate the factorial of a number using loop

The objective of the code is to find the factorial of  number. Value of n is given by user .

 Code(C++):-

#include <iostream>
using namespace std;
int main()
{
int i=1;
printf("First 10 Odd numbers are \n");
while(i<=20)
{
if(i%2!=0)
printf("%d ",i);
i+=1;
}
return(0);
}

Output:-

First 10 Odd numbers are
1 3 5 7 9 11 13 15 17 19

By using do-while :

#include <iostream>
using namespace std;
int main()
{
int i=1;
printf("First 10 Odd numbers are \n");
do
{
if(i%2!=0)
printf("%d ",i);
i+=1;
}while(i<=20);
return(0);
}

Output:-

First 10 Odd numbers are
1 3 5 7 9 11 13 15 17 19


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-