Академический Документы
Профессиональный Документы
Культура Документы
#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:
#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:
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
C:\>ipconfig/all
B)Using Automaticaly
C:\>ipconfig
C:\>ipconfig/all
Windows 2000 IP Configuration
C:\>ping localhost
C:\>ping 192.168.100.165