Write a program which accepts an ip address in decimal form and finds the class of the ip address.
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{ clrscr();
int n;
cout<<"\n Enter the first value of ip address in the decimal form:";
cin>>n;
if(n>=0&&n<=127)
cout<<"\n The CLASS is A.";
else if(n>=128&&n<=191)
cout<<"\n The CLASS is B.";
else if(n>=191&&n<=223)
cout<<"\n The CLASS is C.";
else if(n>=224&&n<=239)
cout<<"\n The CLASS is D.";
else if(n>=240&&n<=255)
cout<<"\n The CLASS is E.";
else
cout<<"\n Not the correct address!(between 0-255)";
getch();
}
OUTPUT
1.
Enter the first value of ip address in the decimal form:`1
Not the correct address!(between 0-255)
2.
Enter the first value of ip address in the decimal form:as12
Not the correct address!(between 0-255)
3.
Enter the first value of ip address in the decimal form:098
The CLASS is A.
4.
Enter the first value of ip address in the decimal form:129
The CLASS is B.
5.
Enter the first value of ip address in the decimal form:223
The CLASS is C.
6.
Enter the first value of ip address in the decimal form:238
The CLASS is D.
7.
Enter the first value of ip address in the decimal form:255
The CLASS is E.