Wednesday, December 8, 2010

Form validation using javascript

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




HTML Code



<html>
<head>
<title>
Form Validation Program
</title>
<script type="text/javascript">
function valid(v1,v2,v3,v4)
{
if(v1==""||v2==""||v3==""||v4=="")
{
alert("Fill all the fields");
}
}
function pass(p1)
{
if(p1.length<8)
alert("Password should be 8 charcters");
}

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>Password<td><input type="password" name="f4" onchange="pass(frm1.f4.value)"></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>




Output


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();
}

Input/Output


floyd triangle