6 Replies - 18241 Views - Last Post: 27 February 2011 - 09:28 AM Rate Topic: -----

#1 iamosi  Icon User is offline

  • New D.I.C Head

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

Calculate and Print Product of odd integers

Post icon  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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • 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 ?
Was This Post Helpful? 0
  • +
  • -

#3 iamosi  Icon User is offline

  • New D.I.C Head

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

Re: Calculate and Print Product of odd integers

Posted 28 April 2008 - 08:30 PM

View Postmikeblas, 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.
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Whizzy*


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

Was This Post Helpful? 0

#5 iamosi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Jamil*


Reputation:

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!!

Was This Post Helpful? -2

#7 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • 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;
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1