Friday 22 March 2013

C PROGRAM TO MULTIPLY TWO MATRICES

#include<stdio.h>
int n,i,j,k,Mat1[4][4],Mat2[4][4],Mat3[4][4];
void main()
{
printf("Enter order of Matrix\n");
scanf("%d",&n);
printf("Enter the elements of Matrix1");
for(i=0;i for(j=0;j scanf("%d",&Mat1[i][j]);

printf("Enter the elements of Matrixt2");
for(i=0;i for(j=0;j scanf("%d",&Mat2[i][j]);

for(i=0;i {
for(j=0;j {
Mat3[i][j]=0;
for(k=0;k Mat3[i][j]=Mat3[i][j]+Mat1[i][k]*Mat2[k][j];
}
}
printf("Products of Matrix1 And Matrix2\n");
for(i=0;i {
for(j=0;j {
printf("\t%d",Mat3[i][j]);
}
printf("\n");
}
}

C PROGRAM TO FIND FACTORIAL OF N NUMBERS USING RECURSION

#include<stdio.h>
int fact(int n)
{
return n==0?1:n*fact(n-1);
}
void main()
{
int n;
printf("enter n value\n");
scanf("%d",&n);
printf("factorial of %d is %d",n,fact(n));
}

C program to convert binary to decimal number


#include
#include
main()
{
int bin=0,i=1,dec=0;
printf("enter bin num");
scanf("%d",&bin);
while(bin!=0)
{
dec=dec+(bin%10)*i;
i=i*2;
bin=bin/10;
}
printf("dec=%d",dec);
getch();
}

C PROGRAM TO COUNT THE NUMBER OF DIGITS IN A GIVEN NUMBER


C program to Count the binary digits in a given decimal number

Count the binary digits in a given decimal number

#include<stdio.h>
void main()
{
int n,count=1;
double t;
printf("Enter A Number\n");
scanf("%d",&n);
while(n>1)
{
n/=2;
count++;
}
printf("Number Of Digits=%d",count);
}

C PROGRAM TO FIND GCD OF (M,N) USING CONSECUTIVE INTEGER CHECKING

#include<stdio.h>

int gcd(int m,int n)
{
int t; if(m<n)
t=m;
else t=n;
while(t>0)
{
if(m%t==0)
{
if(n%t==0)
return t;
}
t--;
}
}
void main()
{
int m,n;
printf("ENTER THE TWO INTEGERS M AND N\n");
scanf("%d%d",&m,&n); printf("THE GCD OF (%d,%d)=%d",m,n,gcd(m,n));
}