# Calculate and Print Product of odd integers

Page 1 of 1

## 6 Replies - 48446 Views - Last Post: 27 February 2011 - 09:28 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=50451&amp;s=9c5b796859a255253d5e841b5833eb0d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 iamosi

Reputation: 0
• Posts: 6
• Joined: 11-April 08

# 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.

```#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;

}

```

Is This A Good Question/Topic? 0

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

### #2 mikeblas

• D.I.C Regular

Reputation: 44
• Posts: 390
• Joined: 08-February 08

## 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 iamosi

Reputation: 0
• Posts: 6
• Joined: 11-April 08

## 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.

Reputation:

## 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");
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 iamosi

Reputation: 0
• Posts: 6
• Joined: 11-April 08

## Re: Calculate and Print Product of odd integers

Posted 28 April 2008 - 10:31 PM

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

```#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

Reputation:

## Re: Calculate and Print Product of odd integers

Posted 27 February 2011 - 08:43 AM

```#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 David W

• DIC supporter

Reputation: 298
• Posts: 1,839
• Joined: 20-September 08

## 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;
}
```