run time error

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
"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.
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...
Why unsigned long long? They should just be int, %d means int.
Also maybe you meant p = a - b; ?
Why use long long here? If doing subtraction, is an unsigned type appropriate? Is %d the correct character for an unsigned long long?
Topic archived. No new replies allowed.