0

I am a novice to CP and while I was doing this problem of finding the second maximum among three numbers I wrote this code which however works for int but doesn't work for long even though they are the same data types.

Input Format:

  • The first line contains the number of triples, N.

  • The next N lines which follow each have three space separated integers.

Input Used:

3

1 2 3

10 15 5

100 999 500

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
       int n;
       cin >>n ;
       while(n--){
          long a,b,c,d;//if i change long to int output is correct  
          scanf("%i%i%i",&a,&b,&c);
          d=min(max(a,b),max(a,c));
          printf("%i\n",d);// outputs 1 \n 10 \n 100 \n(\n means new line)
     }
    return 0;
    }

1 Answers1

1

Perhaps because you're using the wrong specifier. %i is for ints, but %li is for longs.

frslm
  • 2,969
  • 3
  • 13
  • 26