10-10-2007, 08:30 PM
|
#1 (permalink)
|
|
Apprentice
Join Date: Feb 2007
Posts: 87
|
CHALLENGING C PROGRAM...-atleast for me
hey guys i needed ur help wid a c program.....
cud sm1 plzz post dis program 4 me...plzzzzz
d program is that....
it should accept any number between one and thousand and find the first non zero digit of the factorial of dat number from the right hand side.....
plz plz plz help me...
example:
enter a number : 5
The first non digit number from the right in its factorial is : 2
__________________
__________________
IF THIS HELPS PLEASE CLICK THE BALANCE UNDER MY ID............:wink: 8-)
Last edited by vinit suri; 10-10-2007 at 10:48 PM.
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
10-10-2007, 09:40 PM
|
#2 (permalink)
|
|
Wise Old Owl
Join Date: Feb 2007
Posts: 1,009
|
Re: CHALLENGING C PROGRAM...-atleast for me
srry ... i didnt understand wat u trying to say ... plz explain with any example ..
|
|
|
10-10-2007, 11:11 PM
|
#3 (permalink)
|
|
Hey here is the aks
Join Date: Jan 2006
Location: punjab
Posts: 805
|
Re: CHALLENGING C PROGRAM...-atleast for me
main()
{
long int a,fact;
scanf("%ld",&a);
fact=1;
for(int i=a;i>0;i--)
{
fact=fact*a;
}
while(fact>0)
{
fact=fact%10;
if(fact!=0)
{
printf("found");
exit();
}
else
{fact=fact/10;
}
getch();
}
i have made it in very little tiem so correct the little mistakes....just check the logic
__________________
yours truly
arun
The aks!!
have a nice day
Last edited by arunks; 11-10-2007 at 02:24 PM.
|
|
|
10-10-2007, 11:14 PM
|
#4 (permalink)
|
|
Console Junkie
Join Date: Jun 2006
Location: USA
Posts: 991
|
Re: CHALLENGING C PROGRAM...-atleast for me
^^ What he means is. Factorial of 5 is 120. So rightmost digit (LSB) is 0. After that is 2. So, the first non zero digit from right is the second one and that is two.
How to calculate this for factorials of 0 up to 1000.
As I pointed out in the C/C++ thread, it can be done, but might get messy.
I will try once my exams are over on Saturday.
__________________
--- Console Junkie
|
|
|
11-10-2007, 11:46 AM
|
#5 (permalink)
|
|
Wise Old Owl
Join Date: Feb 2007
Posts: 1,009
|
Re: CHALLENGING C PROGRAM...-atleast for me
@ arunks, i think ur logic is nt right ... check it again .......
i think its easy .........
i will not give u exact coding .... but little hints so that u can make it urself .......
1. first ask fr the desired no(take input)
2. Check if it is in the range (1-1000) , if yes then go to step 3 or goto step 1 again ..
3. Calculate Factorial
4. now logic
count =0;
rem=0;
while (rem==0)
{
rem=fact%10;
fact=fact/10;
count++;
}
cout<<"The first non zero digit from right side is "<<rem;
cout<<"\n And the Position is "<<count;
here rem is remainder and count is a counter to knw the position of the non zero digit.
example
if the factorial is 120
then wen while loop starts
count=0, rem=0 (by default)
rem = 120%10 = 0
fact=120/10=12
count++
nw as rem is stil 0,
next pass
count =1, rem =0
rem=12%10 = 2
fact= 12/10 =1
count++ (count = 2 now)
nw rem is nt 0 .. so it will exit from loop
and we have
rem =2 (first non zero digit from right )
count = 2 ( position of first non zero digit )
hope it works ..as i am nt feeling right nw to open TC .........
Last edited by harryneopotter; 11-10-2007 at 05:03 PM.
|
|
|
11-10-2007, 03:15 PM
|
#6 (permalink)
|
|
Console Junkie
Join Date: Jun 2006
Location: USA
Posts: 991
|
Re: CHALLENGING C PROGRAM...-atleast for me
^^ Then use devCPP
__________________
--- Console Junkie
|
|
|
11-10-2007, 05:01 PM
|
#7 (permalink)
|
|
Wise Old Owl
Join Date: Feb 2007
Posts: 1,009
|
Re: CHALLENGING C PROGRAM...-atleast for me
^ dear ... i dnt have Devcpp Installed on my system... and i was being lazy to type whole prog in TC .. tht y i said that...
|
|
|
11-10-2007, 06:03 PM
|
#8 (permalink)
|
|
Apprentice
Join Date: Feb 2007
Posts: 87
|
Re: CHALLENGING C PROGRAM...-atleast for me
hey harryneopotter thanks for the reply but my problem was not with findin the first non digit number from the right...thats pretty easy using mod function.....but if u notice the actual problem over here is with finding out the factorial ....there s no such datatype which can hlold 1000 factorial without getting overloaded....so cud u plzzz tell me how 2 do the program now...
__________________
IF THIS HELPS PLEASE CLICK THE BALANCE UNDER MY ID............:wink: 8-)
|
|
|
11-10-2007, 06:36 PM
|
#9 (permalink)
|
|
Wise Old Owl
Join Date: Feb 2007
Posts: 1,009
|
Re: CHALLENGING C PROGRAM...-atleast for me
402,387,260,077,093,773,543,702,433,923,003,985,71 9,374,864, 210,714,632,543,799,910,429,938,512,398,629,020,59 2,044,208, 486,969,404,800,479,988,610,197,196,058,631,666,87 2,994,808, 558,901,323,829,669,944,590,997,424,504,087,073,75 9,918,823, 627,727,188,732,519,779,505,950,995,276,120,874,97 5,462,497, 043,601,418,278,094,646,496,291,056,393,887,437,88 6,487,337, 119,181,045,825,783,647,849,977,012,476,632,889,83 5,955,735, 432,513,185,323,958,463,075,557,409,114,262,417,47 4,349,347, 553,428,646,576,611,667,797,396,668,820,291,207,37 9,143,853, 719,588,249,808,126,867,838,374,559,731,746,136,08 5,379,534, 524,221,586,593,201,928,090,878,297,308,431,392,84 4,403,281, 231,558,611,036,976,801,357,304,216,168,747,609,67 5,871,348, 312,025,478,589,320,767,169,132,448,426,236,131,41 2,508,780, 208,000,261,683,151,027,341,827,977,704,784,635,86 8,170,164, 365,024,153,691,398,281,264,810,213,092,761,244,89 6,359,928, 705,114,964,975,419,909,342,221,566,832,572,080,82 1,333,186, 116,811,553,615,836,546,984,046,708,975,602,900,95 0,537,616, 475,847,728,421,889,679,646,244,945,160,765,353,40 8,198,901, 385,442,487,984,959,953,319,101,723,355,556,602,13 9,450,399, 736,280,750,137,837,615,307,127,761,926,849,034,35 2,625,200, 015,888,535,147,331,611,702,103,968,175,921,510,90 7,788,019, 393,178,114,194,545,257,223,865,541,461,062,892,18 7,960,223, 838,971,476,088,506,276,862,967,146,674,697,562,91 1,234,082, 439,208,160,153,780,889,893,964,518,263,243,671,61 6,762,179, 168,909,779,911,903,754,031,274,622,289,988,005,19 5,444,414, 282,012,187,361,745,992,642,956,581,746,628,302,95 5,570,299, 024,324,153,181,617,210,465,832,036,786,906,117,26 0,158,783, 520,751,516,284,225,540,265,170,483,304,226,143,97 4,286,933, 061,690,897,968,482,590,125,458,327,168,226,458,06 6,526,769, 958,652,682,272,807,075,781,391,858,178,889,652,20 8,164,348, 344,825,993,266,043,367,660,176,999,612,831,860,78 8,386,150, 279,465,955,131,156,552,036,093,988,180,612,138,55 8,600,301, 435,694,527,224,206,344,631,797,460,594,682,573,10 3,790,084, 024,432,438,465,657,245,014,402,821,885,252,470,93 5,190,620, 929,023,136,493,273,497,565,513,958,720,559,654,22 8,749,774, 011,413,346,962,715,422,845,862,377,387,538,230,48 3,865,688, 976,461,927,383,814,900,140,767,310,446,640,259,89 9,490,222, 221,765,904,339,901,886,018,566,526,485,061,799,70 2,356,193, 897,017,860,040,811,889,729,918,311,021,171,229,84 5,901,641, 921,068,884,387,121,855,646,124,960,798,722,908,51 9,296,819, 372,388,642,614,839,657,382,291,123,125,024,186,64 9,353,143, 970,137,428,531,926,649,875,337,218,940,694,281,43 4,118,520, 158,014,123,344,828,015,051,399,694,290,153,483,07 7,644,569, 099,073,152,433,278,288,269,864,602,789,864,321,13 9,083,506, 217,095,002,597,389,863,554,277,196,742,822,248,75 7,586,765, 752,344,220,207,573,630,569,498,825,087,968,928,16 2,753,848, 863,396,909,959,826,280,956,121,450,994,871,701,24 4,516,461, 260,379,029,309,120,889,086,942,028,510,640,182,15 4,399,457, 156,805,941,872,748,998,094,254,742,173,582,401,06 3,677,404, 595,741,785,160,829,230,135,358,081,840,096,996,37 2,524,230, 560,855,903,700,624,271,243,416,909,004,153,690,10 5,933,983, 835,777,939,410,970,027,753,472,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000
it is the factorial of 1000....... and i dnt think any data int data type in c++ can handle it.
But may be u can use a char Pointer. but thn it will be an herculeaon task to calculate the first non zero digit ..... give it some time ......i will try again .. this time more seriously.
Last edited by harryneopotter; 11-10-2007 at 06:46 PM.
|
|
|
11-10-2007, 09:00 PM
|
#10 (permalink)
|
|
God of Mistakes...
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
|
Re: CHALLENGING C PROGRAM...-atleast for me
Quote:
|
Originally Posted by harryneopotter
402,387,260,077,093,773,543,702,433,923,003,985,71 9,374,864, 210,714,632,543,799,910,429,938,512,398,629,020,59 2,044,208, 486,969,404,800,479,988,610,197,196,058,631,666,87 2,994,808, 558,901,323,829,669,944,590,997,424,504,087,073,75 9,918,823, 627,727,188,732,519,779,505,950,995,276,120,874,97 5,462,497, 043,601,418,278,094,646,496,291,056,393,887,437,88 6,487,337, 119,181,045,825,783,647,849,977,012,476,632,889,83 5,955,735, 432,513,185,323,958,463,075,557,409,114,262,417,47 4,349,347, 553,428,646,576,611,667,797,396,668,820,291,207,37 9,143,853, 719,588,249,808,126,867,838,374,559,731,746,136,08 5,379,534, 524,221,586,593,201,928,090,878,297,308,431,392,84 4,403,281, 231,558,611,036,976,801,357,304,216,168,747,609,67 5,871,348, 312,025,478,589,320,767,169,132,448,426,236,131,41 2,508,780, 208,000,261,683,151,027,341,827,977,704,784,635,86 8,170,164, 365,024,153,691,398,281,264,810,213,092,761,244,89 6,359,928, 705,114,964,975,419,909,342,221,566,832,572,080,82 1,333,186, 116,811,553,615,836,546,984,046,708,975,602,900,95 0,537,616, 475,847,728,421,889,679,646,244,945,160,765,353,40 8,198,901, 385,442,487,984,959,953,319,101,723,355,556,602,13 9,450,399, 736,280,750,137,837,615,307,127,761,926,849,034,35 2,625,200, 015,888,535,147,331,611,702,103,968,175,921,510,90 7,788,019, 393,178,114,194,545,257,223,865,541,461,062,892,18 7,960,223, 838,971,476,088,506,276,862,967,146,674,697,562,91 1,234,082, 439,208,160,153,780,889,893,964,518,263,243,671,61 6,762,179, 168,909,779,911,903,754,031,274,622,289,988,005,19 5,444,414, 282,012,187,361,745,992,642,956,581,746,628,302,95 5,570,299, 024,324,153,181,617,210,465,832,036,786,906,117,26 0,158,783, 520,751,516,284,225,540,265,170,483,304,226,143,97 4,286,933, 061,690,897,968,482,590,125,458,327,168,226,458,06 6,526,769, 958,652,682,272,807,075,781,391,858,178,889,652,20 8,164,348, 344,825,993,266,043,367,660,176,999,612,831,860,78 8,386,150, 279,465,955,131,156,552,036,093,988,180,612,138,55 8,600,301, 435,694,527,224,206,344,631,797,460,594,682,573,10 3,790,084, 024,432,438,465,657,245,014,402,821,885,252,470,93 5,190,620, 929,023,136,493,273,497,565,513,958,720,559,654,22 8,749,774, 011,413,346,962,715,422,845,862,377,387,538,230,48 3,865,688, 976,461,927,383,814,900,140,767,310,446,640,259,89 9,490,222, 221,765,904,339,901,886,018,566,526,485,061,799,70 2,356,193, 897,017,860,040,811,889,729,918,311,021,171,229,84 5,901,641, 921,068,884,387,121,855,646,124,960,798,722,908,51 9,296,819, 372,388,642,614,839,657,382,291,123,125,024,186,64 9,353,143, 970,137,428,531,926,649,875,337,218,940,694,281,43 4,118,520, 158,014,123,344,828,015,051,399,694,290,153,483,07 7,644,569, 099,073,152,433,278,288,269,864,602,789,864,321,13 9,083,506, 217,095,002,597,389,863,554,277,196,742,822,248,75 7,586,765, 752,344,220,207,573,630,569,498,825,087,968,928,16 2,753,848, 863,396,909,959,826,280,956,121,450,994,871,701,24 4,516,461, 260,379,029,309,120,889,086,942,028,510,640,182,15 4,399,457, 156,805,941,872,748,998,094,254,742,173,582,401,06 3,677,404, 595,741,785,160,829,230,135,358,081,840,096,996,37 2,524,230, 560,855,903,700,624,271,243,416,909,004,153,690,10 5,933,983, 835,777,939,410,970,027,753,472,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,00 0,000,000, 000
it is the factorial of 1000....... and i dnt think any data int data type in c++ can handle it.
But may be u can use a char Pointer. but thn it will be an herculeaon task to calculate the first non zero digit ..... give it some time ......i will try again .. this time more seriously.
|
dude... gr8.... :-O
But, how u calculated that ??
|
|
|
11-10-2007, 09:28 PM
|
#11 (permalink)
|
|
Wise Old Owl
Join Date: Feb 2007
Posts: 1,009
|
Re: CHALLENGING C PROGRAM...-atleast for me
|
|
|
11-10-2007, 09:46 PM
|
#12 (permalink)
|
|
18 Till I Die............
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
|
Re: CHALLENGING C PROGRAM...-atleast for me
Have you tried searching anywhere? Google gives results to some discussions which point to some answers
http://www.dreamincode.net/forums/showtopic25176.htm
__________________
http://www.bash.org/?258908
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|