-1

我是 C++ 新手。我编写了一个使用unsigned long long int数据类型的程序。

我无法正确打印变量

这是代码:

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h> 
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int t ;
    int x = scanf("%d",&t);

     unsigned long long int a,b,c;
     unsigned long long int counter,n ,mod = pow(10,9)+7;

    while (t>0){
        int y = scanf("%llu,%llu,%llu",&a,&b,&n); 
        //printf("%llu\n",a);
         if (n == 1){
                printf("%llu",b);
            }else if (n == 0){
                printf("%llu",a);
            }else{
                 c = 0;
             counter =2;
            while (counter <= n){
                c = a+b;
                a = b;
                b = c;
                ++counter;
            }
            if (c>mod)
                c=c-mod;
            printf("%llu",c);
         }
        --t;
    }    
    return 0;
}

标准输入:

8
2 3 1
9 1 7
9 8 3
2 4 9
1 7 2
1 8 1
4 3 1
3 7 5

预期输出:

3
85
25
178
8
8
3
44

观察到的输出:

23191798
4

1 回答 1

1

不像Java的println函数,printf不加换行符。 如果您希望它这样做,请在您的字符串中添加一个'\n' 。

printf("some text\n");
于 2015-02-22T13:37:40.527 回答