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.
matrix-multiplication

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


matrix-multiplication

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>

OUTPUT




javascript

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>
<head>
<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>
</head>
<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>
<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

Sunday, November 28, 2010

C Program For Fibonacci Series

Hello everybody I want to discuss about How to generate a Fibonacci series in C programming.

What is Fibonacci Series?


The first two Fibonacci numbers are 0 and 1 then next number is addition of previous two numbers.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.....
In mathematics it is defined by recurrence relation.

Program Code


  


//C Program for generate Fibonacci series
#include "stdio.h"
#include "conio.h"
void main()
{
int a,b,c,i,n;
clrscr();
a=0;
b=1;
printf("\n enter n for how many times generate series");
scanf("%d",&n);
printf("\n FIBONACCI SERIES\n");
printf("\t%d\t%d",a,b);
for(i=0;i<n;i++)
{
c=a+b;
a=b;
b=c;
printf("\t%d",c);
}
getch();
}

Input\Output



Saturday, November 27, 2010

Digital Clock in C Prgramming

Hello this is program for how to generate a digital clock in c programming.

Program Code


//simulate a digital clock
#include "stdio.h"
#include "conio.h"
#include "dos.h"
void main()
{
int h,m,s;
h=0;
m=0;
s=0;
while(1)
{

if(s>59)
{
m=m+1;
s=0;
}
if(m>59)
{
h=h+1;
m=0;
}
if(h>11)
{
h=0;
m=0;
s=0;
}
delay(1000);
s=s+1;
clrscr();
printf("\n DIGITAL CLOCK");
printf("\n HOUR:MINUTE:SECOND");
printf("\n%d:%d:%d",h,m,s);
}

}

Output


Monday, November 15, 2010

c program to check number is prime or not

Program Code


// Check whether given number is prime number and not prime number
#include "stdio.h"
#include "conio.h"
void main()
{
int num,i,z;
printf("enter the value of num");
scanf("%d",&num);
i= 2;
while (i less then num)
{
if(num%i==0)
{
z=1;
}
i=i+1;
}
printf("After checking the result is");
if(z== 1)
{
printf("given number is not prime number");
}
else
{
printf("given number is prime number");
}
getch();
}

Input/Output


enter the value of num 7
After checking the result is
given number is prime number


What is Prime Number?


Prime number is a natural number which is divisible by 1 and itself.
Example 7

First 25 Prime Number :-
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97

Thursday, November 11, 2010

C Program to check number is palindrome or not



C Program Code


//Check number is palindrome of not
#include "stdio.h"
#include "conio.h"
void main()
{
int num,rev=0,m,r;
clrscr();
printf("enter any number");
scanf("%d",&num);
m=num;
while(num>0)
{
r=num%10;
rev=rev*10+r;
num=num/10;
}
if(rev==m)
printf("given number is palindrome");
else
printf("given number is not palindrome");
getch();
}

Input/Output


enter any number 121
given number is palindrome

enter any number 423
given number is not palindrome

What is Palindrome No?


when we read a number. If backward read is as same as forward read then number is palindrome.

Wednesday, November 10, 2010

C Program to calculate factorial of given number

You write this code into any c compiler and get factorial of given number by run this code.

C Program Code
//factorial of a number
#include "stdio.h"
#include "conio.h"
void main()
{
int fact=1,n;
clrscr();
printf("enter any number");
scanf("%d",&n);
while(n>0)
{
fact=fact*n;
n--;
}
printf("\n factorial of given number= %d",fact);
getch();
}




Input/Output
enter any number 4
factorial of given number= 24


Factorial of 4 = 4*3*2*1 =24

Tuesday, September 7, 2010

How to Redirect in html

To redirect in html here is the simple one line meta tag code:

< meta HTTP-EQUIV="REFRESH" content="0;
url=http://sampleexamples.com/" >


Add this code in html < head > tag.
you can specify time interval like:

content="5; url=http://sampleexamples.com/"

Here 5 represents 5 seconds means it will redirect after 5 sec. to sampleexample.com.