Sunday, August 2, 2009

Ten points to help me alter this c++ program, thank you!!!?

#include "stdafx.h"


#include "simpio.h"


#include "genlib.h"





int main()


{


int n;


long factorial;


printf("Compute the factorial of what number? ");


scanf("%d", %26amp;n);


factorial = 1L;


while(n %26gt; 0)


factorial *= n--;


printf("The factorial is %ld\n", factorial);


return 0;


{


register int count;


int n;


long factorial;


printf("Compute the factorial of what number? ");


scanf("%d", %26amp;n);


factorial = 1L;


count = 1;


while(count %26lt;= n)


factorial *= count++;


printf("%d! = %ld\n", n, factorial);


return 0;


{


register int count;


int n;


long factorial;


printf("Compute the factorial of what number? ");


scanf("%d", %26amp;n);


for(factorial = 1L, count = 1; count %26lt;= n; count++)


factorial *= count;


printf("%d! = %ld\n", n, factorial);


return 0;


}


}


}





This program computes the factorial of any given factorial. I need to change the program so that it computes all the factorials from 1 to 10 and shows them on the output like this:


1! = 1


2! =2


3! = 6


etc.


Please help me!!

Ten points to help me alter this c++ program, thank you!!!?
Why bother assign those things to a register? Yes, it makes the program somewhat faster, but not really necessary and it makes it complicated (especially if windows denies the access of two registers). ANYWAY. I suggest you simply modify a char line with sprintf.





For example, once you have your factorial amount, just do this:





char line[100];


sprintf(line,"%d! = %d", computednumber, factorialamount)


cout %26lt;%26lt; line %26lt;%26lt; endl;





it should come out like this #! = # . The first # will be whatever the computednumber is and the second will be your factorial.





As for printing ALL of the factorials 1 - 10, just make an integer at 0 and do a for loop





for (n= 0; n %26lt; 11 ; n++)


{


insert factorial computation here


insert sprintf line here


{





then it'll compute the factorial using n, and then print it, then increment, and start again. This way it'll go 1 - 10 and then stop.
Reply:thats really easy you just:





2374629834cbndh


sdfiu';'ze984so9


dj bcsukfh'';'sdfusdifnsfhsfsdu8fy


=oryhoiuer;'ew384495


f9472023';/'29r\40


ru9384624ojr


03989024384-5


56'45


6


5


7676


879k9hnl.;/


[


'[-9[0[806ro68o6


7ilo.[7i[p.iy


lu89mt6rsr57


nm679,9











and there you have it.
Reply:`3!= 6` seems to be accumulated value, i.e. (1! + 2! + 3!). Try using For...Next loop instead of sequential.

mothers day flowers

No comments:

Post a Comment