Check This code ( I only use cout and cin instead of scanf() and printf() )

Code:
#include <iostream>
#include <cstdlib>
#include <cctype>
using namespace std;

int valid_data(const char *data)
{
    int i=0;
    //TO Check -ve Number
    if(data[0] == '-')
        i++;
    //To check if only '-' sign is their
    if(data[i] == '\0' )
        return 1;
    while(data[i] != '\0')
    {
        if(!isdigit(data[i]))
            return 1;
        i++;
    }
    return 0;
}

int main()
{
	string n;
	cout<<"Enter Value of n : ";
	cin>>n;
	if(!valid_data(n.c_str()))
	{
	    int a = atoi(n.c_str());
        for(int i=1;i<=20;i++)
            cout<<a<<" X "<<i<<" = "<<a*i<<endl;
	}
    else
        cout<<"Invalid Value";
	return 0;
}
If you want a simpler code you read this about aoti() function
Quote:
About aoti(const char *)
On success, the function returns the converted integral number as an int value.
If no valid conversion could be performed, a zero value is returned.
If the correct value is out of the range of representable values, INT_MAX or INT_MIN is returned.
You can check whether returned value is zero or not. If it is zero then you can display message. "Invalid Value". But here we cannot check if user has entered zero (0) as value. If user has entered zero (0) as value then also your program will display "Invalid Value". Hence i do not suggest this.


Regards