## Friday, December 10, 2010

### C program for matrix multiplication of two matrix

Hello everybody I want to discuss the source code for matrix multiplication in c programming.

## Program Code

`//C program for multiplication of two matrix#include < stdio.h >#include < conio.h >void main(){ int a[3][3], b[3][3], c[3][3], i, j, k; clrscr(); printf("Enter the elements of first 3x3 matrix"); for (i = 0;i < 3; i++) {  for (j = 0; j < 3; j++)  {   scanf("%d",&a[i][j]);  } } printf("\nEnter the elements of second 3x3 matrix"); for(i = 0; i < 3; i++) {  for (j = 0; j < 3; j++)  {   scanf("%d", &b[i][j]);  } } printf("\nThe first matrix is :-\n"); for (i = 0; i < 3; i++) {  for (j = 0; j < 3; j++)  {   printf("\t%d", a[i][j]);  }  printf("\n"); } printf("\nThe second matrix is :-\n"); for (i = 0; i < 3; i++) {  for (j = 0; j < 3; j++)  {   printf("\t%d", b[i][j]);  }  printf("\n"); } printf("\nMultiplication of the two matrices is as follows:\n"); for (i = 0;i < 3; i++) {  printf("\n");  for (j = 0; j < 3; j++)  {   c[i][j]=0;   for(k=0;k<3;k++)   c[i][j] = c[i][j]+a[i][k] * b[k][j];   printf("\t%d", c[i][j]);  } } getch();}`

## Input :

Enter the elements of first 3x3 matrix

1
2
3
4
5
6
7
8
9
Enter the elements of second 3x3 matrix
1
2
3
4
5
6
7
8
9

## Output :

Multiplication of the two matrices is as follows

30 36 42
66 81 96
102 126 150

## Thursday, December 9, 2010

### Javascript for find greatest and smallest among three numbers

Hello I want to discuss the code for find greatest and smallest from 3 numbers using javascript.

## HTML CODE

`<html><head><title>Javascript Program to find greatest and smallest from 3 numbers<script language="javascript">function greater(){var num1=parseInt(document.f1.t1.value);var num2=parseInt(document.f1.t2.value);var num3=parseInt(document.f1.t3.value);if(num1>num2 && num1>num3){alert(num1 +"  is greatest number");}else if(num2>num1 && num2>num3){alert(num2 +"  is greatest number");}else{alert(num3 +"  is greatest number");}}function smaller(){var num1=parseInt(document.f1.t1.value);var num2=parseInt(document.f1.t2.value);var num3=parseInt(document.f1.t3.value);if(num1<num2 && num1<num3){alert(num1 +"  is smallest number");}else if(num2<num1 && num2<num3){alert(num2 +"  is smallest number");}else{alert(num3 +"  is smallest number");}}</script></head><body><h1 align="center"><font color="red">Javascript for find greatest and smallest</font></h1><form name=f1>num1: <input type="textbox" name=t1><br>num2: <input type="textbox" name=t2><br>num3: <input type="textbox" name=t3><br><br><br><input type="button" value="greatest" onclick="greater()" ><input type="button" value="smallest" onclick="smaller()"></form></body></html>`

## Wednesday, December 8, 2010

### Javascript program to find factorial of given number

Hello everybody I want to discuss the javascript code for find factorial of given number

## HTML CODE

<html>
<title>
Javascript program for find factorial of given number
</title>
<script type="text/javascript">
function fact(n)
{
var m=1;
while(n)
{
m=m*n;
n--;
}
alert("Factorial of given number :"+" "+ m);
}
</script>
<body>
<h1 align="center"><font color="green">Javascript Program for calculate factorial</font></h1>
<form name="frm1">
Enter any number :<input type="text" name="fact1"><br><br>
<input type="submit" value="calculate factorial" onclick="fact(frm1.fact1.value)">
</form>
</body>
</html>

## OUTPUT

### Form validation using javascript

In this page includes html code with javascript to validate the data of form.

## HTML Code

<html>
<title>
Form Validation Program
</title>
<script type="text/javascript">
function valid(v1,v2,v3,v4)
{
if(v1==""||v2==""||v3==""||v4=="")
{
}
}
function pass(p1)
{
if(p1.length<8)
}

function mail()
{
var e1,e2,e3,e4;
e1= new String(frm1.f3.value);
e2=e1.indexOf("@");
e3=e1.indexOf(".");
e4=e1.lastIndexOf(".");

if(e2==0 || e3==0)
alert("Invalid email id!!!!\n@ and . cant be the first character.");

if(e2==-1)
alert("Invalid email id!!!!\n @ should be present.");

if(e3==-1)
alert("Invalid email id!!! \n . should be present.");

if(e2==e1.length-1 || e3==e1.length-1)
alert("Invalid email id!!!!\n@ and . cant be the last character.");

if(e2==e3-1 || e3==e2-1)
alert("Invalid email id!!!!\n@ and . cant be together.");

if(e4<e2)
alert("Invalid email id!!!!\\nOne . should be present after @")

}
</script>
<body>
<table>
<form name="frm1">
<tr><td>First Name<td><input type="text" name="f1"><br>
<tr><td>Last Name<td><input type="text" name="f2"><br>
<tr><td>Email Id<td><input type="text" name="f3" onchange="mail()" tabindex="1"></td><br>
<tr><td><input type="submit" value="submit" onclick="valid(frm1.f1.value,frm1.f2.value,frm1.f3.value,frm1.f4.value)"></td><br>
</form>
</table>
</body>
</html>

## Saturday, December 4, 2010

### C program to find the sum of two matrix

Program Code
`//C program to find the sum of two matrix#include < stdio.h >#include< conio.h >void main(){int a[3][3], b[3][3], c[3][3], i, j;clrscr();printf("Enter the elements of first 3x3 matrix");for (i = 0;i < 3; i++){  for (j = 0; j < 3; j++)  {   scanf("%d",&a[i][j]);  }}printf("\nEnter the elements of second 3x3 matrix");for (i = 0; i < 3; i++){  for (j = 0; j < 3; j++)  {   scanf("%d", &b[i][j]);  }}printf("\nSum of the two matrices is as follows:");for (i = 0;i < 3; i++){ printf("\n"); for (j = 0; j < 3; j++)  {   c[i][j] = a[i][j] + b[i][j];   printf("%d \t", c[i][j]);  }}getch();}`

Input :
Enter the elements of first 3x3 matrix
1
2
3
4
5
6
7
8
9
Enter the elements of second 3x3 matrix
1
2
3
2
3
1
3
1
2

Ouput :
Sum of the two matrices is as follows
2 4 6
6 8 7
10 9 11

### C program to find transpose of a matrix

Hello I want to discuss about the c program for transpose of the matrix.
Transpose matrix means interchange the rows with the columns and columns with the rows.

## Program Code

#include < stdio.h >
#include < conio.h >
void main()
{
int arr[3][3],i,j;
clrscr();
printf("Enter elements for the array \n");
for(i=0;i < 3;i++)
{
for(j=0;j < 3;j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("Original array entered by the user is \n");
for(i=0;i < 3;i++)
{
for(j=0;j < 3;j++)
{
printf("%d ",arr[i][j]);
}
printf("\n");
}
printf("\n Transpose of the array is \n");
for(i=0;i < 3;i++)
{
for(j=0;j < 3;j++)
printf("%d ",arr[j][i]);
printf("\n");
}
getch();
}

## Input:

Enter elements for the array
1
2
3
4
5
6
7
8
9

## Output:

Original array entered by the user is
1 2 3
4 5 6
7 8 9

Transpose of the array is
1 4 7
2 5 8
3 6 9

## Thursday, December 2, 2010

### C Program For Floyd's Triangle

What is a Floyd's Triangle
It is a pattern of numbers arranging in this format.
Format of numbers like
1
2 3
4 5 6
7 8 9 10

## Program Code

//C program to print Floyd’s triangle
#include < stdio.h>
#include < conio.h>
void main()
{
int i , j , r ;
int num=0 ;
clrscr();
printf(“How many rows you want in the triangle:”);
scanf(“%d”,&r);
for(i=1;i<=r;i++)
{
for(j=1;j<=i;j++)
{
printf(“\t%d”,++num);
}
printf(“\n”);
}
getch();
}