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 6630719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:44+00:00 2026-05-25T22:26:44+00:00

M-File fprintf(‘\n\nn!\n’) for i=[1:length(timearray)] fprintf(‘%s \t %d \n’, stringarray{i},factorial(timearray(i))) end Output n! microsecond 1

  • 0

M-File

fprintf('\n\nn!\n')
for i=[1:length(timearray)]
    fprintf('%s \t %d \n', stringarray{i},factorial(timearray(i)))
end

Output

n!
microsecond      1 
minute       Inf 
hour         Inf 
day          Inf 
month        Inf 
year         Inf 
century      Inf 

I’m trying to calculate the number of steps an algorithm that runs at n! takes at the above intervals (assuming 1 step = 1 microsecond). However, I am unable to get fprintf to display meaningful results.

Switching to fprintf('%s \t %bu \n', stringarray{i},factorial(timearray(i))) gave me some numbers, but I suspect they are wrong.

%bu Output

n!
microsecond      04607182418800017408 
minute       09218868437227405312 
hour         09218868437227405312 
day          09218868437227405312 
month        09218868437227405312 
year         09218868437227405312 
century      09218868437227405312 

Disclaimer: I wrote this program to solve a homework problem, however the homework never specified to write a program.

Thanks for any help!

Mike

  • 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-05-25T22:26:45+00:00Added an answer on May 25, 2026 at 10:26 pm

    The problem is likely not with printing per se, but that the factorial computation itself is overflowing. Try just evaluating the value instead of printing it in the loop; you’ll find that the factorial function overflows after 170!.

    One simple way to circumvent this is by returning the log-factorial instead:

    log_factorial = @(n) sum(log(1:n));
    

    Then you can compare values on vastly different scales without worrying about overflow. Note: the above function is not vectorized so it will only work with a single value input; if you need to work with array values then there appear to be other solutions already available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

// File: foo.c static int var; void foo() { var++; } // end of
fprintf(file, %d %d %d, array[0], array[1], array[2]); for this statement to work i have
I have a vc++ method that uses fprintf to write values to a file
#include<stdio.h> #include<ctype.h> int main() { char a,b; FILE *fp; fp=fopen(lext.txt,w); fprintf(fp,PLUS); return 0; }
Is it possible to communicate with server via raw file IO functions like fprintf()
FILE *ExcelFile = fopen(testdata.csv,w); if (ExcelFile == NULL) return -1; fprintf(ExcelFile,1 2 3); fprintf(ExcelFile,\n);
I am using fprintf command for writing on the text file, but every time
int main(void) { char name[] = t2.txt; FILE *datei; datei = fopen(name, a+); fprintf(datei,
I have a macro as such #define PTF(A,y) fprintf(file,%s,A,y);printf(%s %d,A,y); so that it will
int main(int argc, char *argv[]) { FILE *fp = fopen(a.txt, wt); fprintf(fp, AAAA); //

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.