You are on page 1of 10

/* (Binary Countdown) */

#include<stdio.h>
#include<conio.h>
#define size 30

void main()
{
char a[size];
char *str;
int i=0,j=0;
int w=0;
int x=0;
int y=0;
int z=0;
int count=0;
for(i=0;i<=size;i++)
{
a[i]='\0';
}
clrscr();
printf("\nEnter the 4-bit address of station A:");
scanf("%s",&(*str));
j=0;
for(i=0;i<4;i++)
{
a[i]=*(str+j);
j++;
}
count=j;
j=0;
printf("\nEnter the 4-bit address of station B:");
scanf("%s",&(*str));
j=0;
for(i=4;i<(count+count);i++)
{
a[i]=*(str+j);
j++;
}
count+=j;
j=0;
printf("\nEnter the 4-bit address of station C:");
scanf("%s",&(*str));
j=0;
for(i=8;i<(count+count);i++)
{
a[i]=*(str+j);
j++;
}
count+=j;
j=0;
printf("\nEnter the 4-bit address of station D:");
scanf("%s",&(*str));
j=0;
for(i=12;i<(count+count);i++)
{
a[i]=*(str+j);
j++;
}
for(i=0;i<4;i++)
{
if (a[i]=='1')
++w;
}
for(i=4;i<8;i++)
{
if(a[i]=='1')
++x;
}
for(i=8;i<12;i++)
{
if(a[i]=='1')
++y;
}
for(i=12;i<16;i++)
{
if(a[i]=='1')
++z;
}
if(w>=x && w>=y && w>=z)
printf("\nA station will transmit");
if(x>=w && x>=y && x>=z)
printf("\nB station will transmit");
if(y>=w && y>=x && y>=z)
printf("\nC station will transmit");
if(z>=w && z>=x && z>=y)
printf("\nD station will transmit");
getch();
}

OUTPUT:

Enter the 4-bit address of station A:1111

Enter the 4-bit address of station B:0111

Enter the 4-bit address of station C:0011

Enter the 4-bit address of station D:0001

A station will transmit


/* (Bit-stuffing) */

#include<stdio.h>
#include<conio.h>
#define size 100

void main()
{
char a[size],b[size],*str;
int i=0,j=0,k=0;
int len=0;
clrscr();
for(i=0;i<=size;i++)
{
a[i]='\0';
b[i]='\0';
}
i=0;
printf("\nEnter the data:");
scanf("%s",&(*str));
while(*(str+j)!='\0')
{
a[i]=*(str+j);
i++;
j++;
}
i=0;
while(a[i]!='\0')
{
if(a[i]=='1')
{
++len;
if(len==5)
{
b[k]=a[i];
k++;
b[k]='0';
len=0;
goto xy;
}
b[k]=a[i];
xy:
i++;
k++;
}
if(a[i]=='0')
{
len=0;
b[k]=a[i];
i++;
k++;
}
}
printf("\nThe data that will be transmitted is:");
for(i=0;b[i]!='\0';i++)
printf("%c",b[i]);
for(i=0;i<=size;i++)
a[i]='\0';
k=0;
len=0;
i=0;
while(b[i]!='\0')
{
if(b[i]=='1')
{
++len;
if(len==5)
{
a[k]=b[i];
k++;
i+=2;
a[k]=b[i];
len=0;
goto xy1;
}
a[k]=b[i];
xy1:
i++;
k++;
}
if(b[i]=='0')
{
a[k]=b[i];
len=0;
i++;
k++;
}
}
printf("\nThe data at the receiver is:");
for(i=0;a[i]!='\0';i++)
printf("%c",a[i]);
getch();
}

OUTPUT:

Enter the data:1101111011111011

The data that will be transmitted is:11011110111110011

The data at the receiver is:1101111011111011


// IP ADDRESS
import java.net.*;

public class InetDemo


{
public static void main(String args[])
{
try
{
InetAddress host =InetAddress.getLocalHost();
System.out.println("The IP Address of the local host is:"+host);
host=InetAddress.getByName(args[0]);
System.out.println("The IP address of "+args[0]+"is "+host);
}
catch(UnknownHostException ex)
{
System.out.println("There has been som error "+ex);
}
}
}

OUTPUT:

I:\javaprj\bin>javac InetDemo.java

I:\javaprj\bin>java InetDemo
The IP Address of the local host is:cado-1985comp/127.0.0.1
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at InetDemo.main(InetDemo.java:11)
// URL
import java.net.*;
import java.io.*;

class URLDemo
{
public static void main(String args[])
throws
MalformedURLException
{
URL url=new URL("http://www.yahoo.co.in");
System.out.println(url);
String protocol=url.getProtocol();
int port=url.getPort();
String file=url.getFile();
System.out .println("File used : "+file);
System.out.println("protocol used : "+protocol);
System.out.println("port used: "+port);

try
{
URLConnection urlcon=url.openConnection();
String ct=urlcon.getContentType();
System.out.println("The content type of this html page is "+ct);
long exp=urlcon.getExpiration();
System.out.println("Expiration : "+exp);
int len=urlcon.getContentLength();
System.out.println("The length of the content is: "+len);
InputStream ip=urlcon.getInputStream();
boolean flag=true;
while(flag)
{
int a=ip.read ();
if (a==-1)
{
flag=false;
}
else
{
char c=(char)a;
System.out.print(c);
}
}
ip.close();
}
catch(Exception e)
{
System.out.println("There has been some Error "+e);
}
}
}

OUTPUT:

I:\javaprj\bin>javac URLDemo.java
I:\javaprj\bin>java URLDemo
http://www.yahoo.co.in
File used :
protocol used : http
port used: -1
The content type of this html page is null
Expiration : 0
The length of the content is: -1
There has been some Error java.net.UnknownHostException: www.yahoo.co.in

I:\javaprj\bin>java InetDemo
The IP Address of the local host is:cado-1985comp/127.0.0.1
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at InetDemo.main(InetDemo.java:11)
A)Using Manualy :

C:\>ipconfig

Windows 2000 IP Configuration

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :


IP Address. . . . . . . . . . . . : 192.168.100.165
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.100.98

C:\>ipconfig/all

Windows 2000 IP Configuration

Host Name . . . . . . . . . . . . : c7-12


Primary DNS Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Broadcast
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :


Description . . . . . . . . . . . : Realtek RTL8139(A)-based PCI Fast
Ethernet Adapter
Physical Address. . . . . . . . . : 00-0B-6A-BD-FD-66
DHCP Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.100.165
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.100.98
DNS Servers . . . . . . . . . . . :

B)Using Automaticaly

C:\>ipconfig

Windows 2000 IP Configuration

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :


IP Address. . . . . . . . . . . . : 0.0.0.0
Subnet Mask . . . . . . . . . . . : 0.0.0.0
Default Gateway . . . . . . . . . :

C:\>ipconfig/all
Windows 2000 IP Configuration

Host Name . . . . . . . . . . . . : c7-12


Primary DNS Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Broadcast
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :


Description . . . . . . . . . . . : Realtek RTL8139(A)-based PCI Fast
Ethernet Adapter
Physical Address. . . . . . . . . : 00-0B-6A-BD-FD-66
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 0.0.0.0
Subnet Mask . . . . . . . . . . . : 0.0.0.0
Default Gateway . . . . . . . . . :
DHCP Server . . . . . . . . . . . : 255.255.255.255
DNS Servers . . . . . . . . . . . :

C:\>ping localhost

Pinging c7-12 [127.0.0.1] with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<10ms TTL=128


Reply from 127.0.0.1: bytes=32 time<10ms TTL=128
Reply from 127.0.0.1: bytes=32 time<10ms TTL=128
Reply from 127.0.0.1: bytes=32 time<10ms TTL=128

Ping statistics for 127.0.0.1:


Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\>ping 192.168.100.165

Pinging 192.168.100.165 with 32 bytes of data:

Reply from 192.168.100.165: bytes=32 time<10ms TTL=128


Reply from 192.168.100.165: bytes=32 time<10ms TTL=128
Reply from 192.168.100.165: bytes=32 time<10ms TTL=128
Reply from 192.168.100.165: bytes=32 time<10ms TTL=128

Ping statistics for 192.168.100.165:


Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
-------------------------------------------------------
C:\>ping 192.168.100.152

Pinging 192.168.100.152 with 32 bytes of data:

Reply from 192.168.100.152: bytes=32 time<10ms TTL=128


Reply from 192.168.100.152: bytes=32 time<10ms TTL=128
Reply from 192.168.100.152: bytes=32 time<10ms TTL=128
Reply from 192.168.100.152: bytes=32 time<10ms TTL=128

Ping statistics for 192.168.100.152:


Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
-------------------------------------------------------
C:\>ping 192.168.100.164

Pinging 192.168.100.164 with 32 bytes of data:

Request timed out.


Request timed out.
Request timed out.
Request timed out.

Ping statistics for 192.168.100.164:


Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
-------------------------------------------------------

You might also like