c - 有没有办法在运行时间方面优化这个C程序

标签 c linux performance performance-testing

其目标是打印直到第 93 位的所有斐波那契数

#include<stdio.h>

void main(){
  unsigned long long first=0,second=1,sum;
  printf("%llu,%llu",first,second);
  unsigned char hops=1;
  while (hops<93) {
    sum=first+second;
    printf(",%llu",sum);
    first=second;
    second=sum;
    hops++;
  }
  printf("\n");
}

最佳答案

当然可以。只需打印预先计算的数字字符串。

#include <stdio.h>
int main()
{
    puts("0,1,1,2,3,5,...");
    return 0;
}

关于c - 有没有办法在运行时间方面优化这个C程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49238588/

相关文章:

c - 使用数组的段错误

C99 可变长度数组维基百科示例

linux - Linux下文件名转换的Shell脚本

linux - Bash 并行处理 - 限制总运行时间

ios - C/XCode : sh: ./child : No such file or directory. 命令在终端中运行,但不在 XCode 中运行

c - 如何用C语言实现快速I/O?

linux - GhostScript - 错误的字体替换(错误的字符)

javascript - 网页中的多个不同背景

performance - 如何使用 SELECT DISTINCT 提高 Oracle 中的性能

python - 使用 cython 对 python 中的小数组进行高效的数学操作