Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8681509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:31:48+00:00 2026-06-12T21:31:48+00:00

For solving project euler problem 20 to find the sum of digits in 100!

  • 0

For solving project euler problem 20 to find the sum of digits in 100! i am running the following program , it is working for factorial of small numbers but not for 100.which data type should i use or is it necessary to use an array for storing the digits?

int rec(int);

void main()
{   
    int f=1,i=1,z,s=0,r,n;

    while(i<=100)
    {
        f=f*i;
        f=rec(f);
        i++;
    }
    n=f;

    while(n!=0)
    {
        r=n%10;
        n=n/10;
        s=s+r;
    }

    printf("\n%d",s);
}

int rec(int t)
{   
    if(t%10==0)
    {
        t=t/10;
        rec(t);
    }
    return t;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:31:51+00:00Added an answer on June 12, 2026 at 9:31 pm

    You should look for overflow, print the value after each iteration.

    Note that rec(t); doesn’t do anything as it doesn’t use the returned value… you want t = rec(t);.

    int is definitely too short, try long long… if that’s still overflowing, you need another data structure.. eg: GMP Library.

    Note: using some “proper” language for the job might give you some insight to the range you have to support… e.g. with python:

    >>> import math
    >>> math.factorial(100)
    93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000L
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to solving Project Euler Problem 14 . It asks to find the
I'm working on solving the Project Euler problem 25: What is the first term
I am currently solving, Project Euler problem 14 : The following iterative sequence is
I am solving problem 9 on the Project Euler . In my solution I
I am solving some problems of Project Euler in Haskell. I wrote a program
I'm currently working on a project Euler problem (www.projecteuler.net) for fun but have hit
Problem 17 on project euler states: If the numbers 1 to 5 are written
I'm playing with Haskell and Project Euler's 23rd problem. After solving it with lists
I'm working on problem 14 of Project Euler ( http://projecteuler.net/problem=14 ). I'm trying to
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.