1. Write a program that displays product of all odd numbers from 1 to 10 using for loop1. Write a program that displays product of all odd numbers from 1 to 10 using for loop
#include<iostream.h>
int main(){
// declare variable i to count and increment by 2 from each odd number starting from one
//declare variable productto store each product.
//desplay odd numbers and products
int product=1;
for(int i=1;i<=10;i=i+2){
product=product*i;
cout<<"odd numbers="<<i<<"\tproduct="<<product<<endl;
}
return 0;}
Comments
Leave a comment