Friday, July 30, 2010

Java Assignment Solution

Here goes the solution for the Programming Paradigm assignment,


Download the Solution(2007 MS office or higher)

Download the Solution ( 2003 MS office or below)

Java Program for Matrix Multiplication

Here goes the Java Program to multiply Two matrices, written by me....Requires Scanner package to run this( available with new versions of Java JDK).

(Pls download the source code in case if it is not clear below)

import java.util.Scanner;
public class matrix_main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
int A_row,A_col,B_row,B_col;
System.out.println("Enter the number of rows in matrix A : ");
A_row=cin.nextInt();
System.out.println("Enter the number of columns in matrix A : ");
A_col=cin.nextInt();
System.out.println("Enter the number of rows in matrix B : ");
B_row= cin.nextInt();
System.out.println("Enter the number of columns in matrix B : ");
B_col=cin.nextInt();

if(A_col==B_row)
{
int matrix_A[][] =new int[A_row][A_col];
int matrix_B[][] =new int[B_row][B_col];
int mult_ans[][] =new int[A_row][B_col];
System.out.println("Enter the elements of matrix A : ");
for(int i=0;i for(int j=0;j {
matrix_A[i][j]=cin.nextInt();
}
System.out.println("Enter the elements of matrix B : ");
for(int i=0;i for(int j=0;j {
matrix_B[i][j]=cin.nextInt();
}
for(int i=0;i for(int j=0;j for(int k=0;k mult_ans[i][j] += matrix_A[i][k] * matrix_B[k][j];

System.out.println("\n\n The output is:");
for(int i=0;i {
for(int j=0;j {
System.out.print(mult_ans[i][j]+" ");
}
System.out.println();
}

}
else
{

System.out.print("!!! Can't multiply this matrixes !!! ");
}
}

}



Download The Source Code

Sunday, July 25, 2010

A New Google Group For Us

Hi fellas, i have created a new Google group for our 2008-12 batch...The address of the group is http://groups.google.co.in/group/veccse . The group is a restricted one and only its members can view the contents. I have invited around 25 members whose contact Id I knew, just in case i have missed someone, u can inform me so that I add you in that group.

Some of the features of Google Groups are,

  • Join in on what others are talking about.
  • Start a discussion in your own group.
  • Discuss online or over email.
  • Create web pages right inside your group
  • Build a knowledge base
  • Upload files
  • Learn more about each other

So guys just join it and make it an useful and a successful one. Hope that it is useful for you all....

Wednesday, July 14, 2010

UDP Echo Server Client Program

UDP - User Datagram Protocol

(To know more Click the below link)

http://en.wikipedia.org/wiki/User_Datagram_Protocol

TCP Vs UDP

TCP -
Reliable, Ordered, Heavyweight, Streaming.

UDP - Unreliable, Not Ordered, Lightweight, Datagrams.

Screenshot of the Output




Program


Server.c

#include "stdio.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "netinet/in.h"
#include "string.h"
#include "stdlib.h"
int main()
{
int len,sfd,connfd,i=0,r,b,l,port;
char buff[1024],str[1024],c;
struct sockaddr_in servaddr,cliaddr;
socklen_t clilen;
sfd=socket(AF_INET,SOCK_DGRAM,0);
if(sfd==-1)
{
perror("Socket");
exit(-1);
}
memset(servaddr.sin_zero,'\0',sizeof(servaddr.sin_zero));
printf("\n Enter the port no:");
scanf("%d",&port);
printf("\n Port No is %d",port);
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=INADDR_ANY;
servaddr.sin_port=htons(port);
b=bind(sfd,(struct sockaddr*)&servaddr, sizeof(servaddr));
if(b==-1)
{
perror("bind");
exit(-1);
}
clilen=sizeof(cliaddr);
r=recvfrom(sfd,buff,sizeof(buff),0,(struct sockaddr*)&cliaddr, &clilen);
buff[r]=0;
printf("\n Client:%s",buff);
printf("\n Server:%s",buff);
sendto(sfd,buff,sizeof(buff),0,(struct sockaddr*)&cliaddr,sizeof(cliaddr));
exit(0);
return 0;
}


Client.c

#include "stdio.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "netinet/in.h"
#include "string.h"
#include "stdlib.h"
int main()
{
int len,listenfd,connfd,i=0,r,co,port;
char buff[1024],c;
struct sockaddr_in servaddr,cliaddr;
socklen_t servlen;
listenfd=socket(AF_INET,SOCK_DGRAM,0);
if(listenfd==-1)
{
perror("socket");
exit(-1);
}
memset(servaddr.sin_zero,'\0',sizeof(servaddr.sin_zero));
printf("\n Enter the port no:");
scanf("%d",&port);
printf("\n Port No is : %d",port);
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=INADDR_ANY;
servaddr.sin_port=htons(port);
printf("\n Client:");
scanf("%s",buff);
sendto(listenfd,buff,sizeof(buff),0,(struct sockaddr*)&servaddr,sizeof(servaddr));
r=recvfrom(listenfd,buff,sizeof(buff),0,(struct sockaddr*)&servaddr, &servlen);
buff[r]=0;
printf("\n Server:%s\n",buff);
exit(0);
return 0;
}


Download The Source Code

UDP_Server.c

UDP_Client.c