#include <stdio.h> int main( void ) { int count; printf( "Odd numbers are \n\n"); for( count=1; count<=15; count=count+2 ){ printf( "%d\n", count ); } return 0; }

## 6 Replies - 38622 Views - Last Post: 27 February 2011 - 09:28 AM

### #1

# Calculate and Print Product of odd integers

Posted 28 April 2008 - 07:56 PM

I figured out how to print the odd number 1 to 15.. Now how do i calculate the product?? This is my last assignment, any help would be great.

##
**Replies To:** Calculate and Print Product of odd integers

### #2

## Re: Calculate and Print Product of odd integers

Posted 28 April 2008 - 08:25 PM

What is it that you want to compute? 1*3*5*7 * ... * 15 ?

### #3

## Re: Calculate and Print Product of odd integers

Posted 28 April 2008 - 08:30 PM

mikeblas, on 28 Apr, 2008 - 08:25 PM, said:

What is it that you want to compute? 1*3*5*7 * ... * 15 ?

Yes... That is what i want to do...

Assignment is to " Write a program that calculates and prints the product of the odd integers from 1 to 15."

So.. I have a for loop to give me the odd numbers from 1 to 15. I just don't know how to get the program to multiply the numbers each time it goes through the loop to give me a grand total.

### #4 Guest_Whizzy*

## Re: Calculate and Print Product of odd integers

Posted 28 April 2008 - 09:08 PM

#include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; int main( void ) { int count,product; int total,prod=1; printf( "Odd numbers are \n\n"); cout << "Start with number "<< prod << endl; for( count=1; count<=15; count=count+2 ){ // printf( "%d\n", count ); cout << "Multiply by "<< count <<" - "; product=prod*count; cout << "The temporary answer is "<<product<<endl; total=product; prod=total; } cout << "For a product of "<<total<<"\n\n"<<endl; system("PAUSE"); return EXIT_SUCCESS; }

That should get the job done. It's kind of a sloppy way to do it, but it's a quicky. It's enough to give you an idea anyway.

This post has been edited by **macosxnerd101**: 27 February 2011 - 09:08 AM

Reason for edit:: Added code tags

### #5

## Re: Calculate and Print Product of odd integers

Posted 28 April 2008 - 10:31 PM

Success!!!!!!!!!!!!!!11

Thanks wizzy

#include <stdio.h> int main( void ) { int count; int product=1; printf( "\nThe odd numbers 1-15 are\n\n"); for( count=1; count<=15; count+=2 ){ product =count*product; printf("%d\n", count); } printf( "\nProduct is \n%d", product); return 0; }

Thanks wizzy

### #6 Guest_Jamil*

## Re: Calculate and Print Product of odd integers

Posted 27 February 2011 - 08:43 AM

i made little corrections

#include <conio.h> int main( void ) { int count; long int product=1; clrscr(); printf( "\nThe odd numbers 1-15 are\n\n"); for( count=1; count<=15; count+=2 ) { product =count*product; printf("%d\n", count); } printf( "\nProduct is \n%ld", product); getch(); return 0; }

This post has been edited by **macosxnerd101**: 27 February 2011 - 09:09 AM

Reason for edit:: Please use code tags!!

### #7

## Re: Calculate and Print Product of odd integers

Posted 27 February 2011 - 09:28 AM

Those are corrections? Using non standard conio.h?

#include <stdio.h> int main( void ) { int count, product = 1; printf( "\nThe odd numbers 1-15 are\n\n"); for( count = 1; count <= 15; count += 2 ) { product *= count; printf( "%d\n", count ); } printf( "\nProduct is \n%d", product ); printf( "\nPress 'Enter' to continue ... " ); fflush( stdout ); getchar(); return 0; }

Page 1 of 1