-1

I'm new to C++. I have written a program that uses unsigned long long int data type.

I am not able to print the variable properly

here is the code:

#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;
}

Standard Input:

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

Expected output:

3
85
25
178
8
8
3
44

Observed output:

23191798
Aneesh K
  • 147
  • 2
  • 10
  • What did you observe´when stepping throu your code using a debugger? – πάντα ῥεῖ Feb 22 '15 at 13:22
  • I am writing the code in an online IDE. I can't use debugger there. Why the downvote? I'm still a begineer, maybe I'm missing something – Aneesh K Feb 22 '15 at 13:24
  • 1
    _"maybe I'm missing something "_ Yes, debugging. SO isn't an online debugging service. – πάντα ῥεῖ Feb 22 '15 at 13:25
  • I know SO is not an online debugging service. But I'd like to know what's wrong. I'm new to C++, if I were doing it for a year or so I wouldn't be posting this question. I'm learning C++ after using java for 4 years. I would appreciate if someone were to guide me to the solution – Aneesh K Feb 22 '15 at 13:29
  • 2
    You aren't printing any line breaks ('\n'). – Axalo Feb 22 '15 at 13:29
  • @Axalo : thank you. I guess I was used to `println` from java , i forgot to add line breaks – Aneesh K Feb 22 '15 at 13:33

1 Answers1

1

Unlike Java's println function, printf does not add a line break.
If you want it to do so add a '\n' to your string.

printf("some text\n");
Axalo
  • 2,953
  • 4
  • 25
  • 39