Aug 29, 2013 at 8:37pm Aug 29, 2013 at 8:37pm UTC
its giving runtime error..here i have to terminate the i/p by using end of file..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int main()
{
vector < int > str;
int a,p,b;
int j,i = 0;
while (scanf ("%d %d" ,&a,&b) != EOF)
{
p = b - a;
str.push_back(p);
i++;
}
for ( j = 0; j < i; j++ )
printf ("%d\n" ,str[j]);
return 0;
}
Last edited on Aug 29, 2013 at 10:45pm Aug 29, 2013 at 10:45pm UTC
Aug 29, 2013 at 8:41pm Aug 29, 2013 at 8:41pm UTC
"p" doesn't point to memory.
You should allocate it yourself, or use a std::vector.
Also, you're using both scanf and cout.
You should either stick to scanf and printf, or cout and cin.
You may also want to add a terminator between those two %d (like: "%d %d") or input them as a string and validate/split them yourself.
Aug 29, 2013 at 9:16pm Aug 29, 2013 at 9:16pm UTC
i have edit the code above, but according to "uva" online judge its giving wrong answer...here i just have to print the difference btween 2 numbers...
Aug 29, 2013 at 9:55pm Aug 29, 2013 at 9:55pm UTC
Why unsigned long long? They should just be int, %d means int.
Also maybe you meant p = a - b;
?
Aug 29, 2013 at 9:55pm Aug 29, 2013 at 9:55pm UTC
Why use long long here? If doing subtraction, is an unsigned type appropriate? Is %d
the correct character for an unsigned long long
?