Solution to linear equation using Jordan Elimination

#include < stdio.h>
#include < conio.h>
int b[10][10],n;
float a[10][10];
void min(int r1,int r2,float no);
void mul(int r1,float no);
main()
{
int i,j;
clrscr();
printf("\n\nEnter no of variables : ");
scanf("%d",&n);
printf("\nEnter the values as a00 x1+a01 x2+.......+a0n-1 xn=a0n\n");
for(i=0;i < n;i++)
{
for(j=0;j < n+1;j++)
{
printf(" a%d%d : ",i,j);
scanf("%d",&b[i][j]);
a[i][j]=b[i][j];
}
}

for(j=0;j < n;j++)
{
if(a[j][j]!=1.0)
mul(j,a[j][j]);
for(i=0;i < n;i++)
{
if(i!=j&&a[i][j]!=0)
{
min(i,j,a[i][j]);
}
}}
printf("\n\n");
for(i=0;i < n;i++)
{
printf("x%d = %f \n",i+1,a[i][n]);
}
getch();
}

void min(int r1,int r2,float no)
{
int i,j,k;
for(i=0;i < n+1;i++)
{
a[r1][i]=a[r1][i]-no*a[r2][i];
}
}

void mul(int r1,float no)
{
int i;
for(i=0;i < n+1;i++)
a[r1][i]=a[r1][i]/no;
}

Sub-String Deletion

Sub-String Deletion


#include< stdio.h>
#include< conio.h>
#include< string.h>
main()
{
clrscr();
int l,i,j=0,z=0,k=0;
char a[200]="",b[20];
printf("\n\n enter the string:");
for(i=0;a[i-1]!='\n';i++)
a[i]=getchar();
a[i]='$';
printf("\n\n enter the word to be found:");
scanf("%s",b);
l=strlen(b);
for(i=0;a[i]!='$';i++)
{
if(a[i]==b[0]||z==0)
{
j=0;
k=0;
z=1;
}
if(a[i]!=b[j])
{
k++;
i--;
}
j++;
if(k==0&&j==l)
break;

}
if(k==0)
{
for(i=w;a[i]!='$';i++)
a[i]=a[i+l];
a[i]='$';
}
else
printf("\n ###not found###");


printf("\n\n\tEdied String : ");
for(i=0;a[i]!='$';i++)
printf("%c",a[i]);
getch();
}

Matrix Multiplication

#include< stdio.h>
#include< conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j,k,m=0;
clrscr();
printf("enter the first matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
}
printf("enter the second matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&b[i][j]);
}
printf("answer\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
m=m+(a[i][k]*b[k][j]);
}
c[i][j]=m;
m=0;
}}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf(" %d ",c[i][j]);
printf("\n");
}
getch();
}

Sub-String Search

Sub-String Search

#include< stdio.h>
#include< conio.h>
#include< string.h>
main()
{
clrscr();
int l,i,j=0,z=0,k=0;
char a[200]="",b[20];
printf("\n\n enter the string:");
for(i=0;a[i-1]!='\n';i++)
a[i]=getchar();
a[i]='$';
printf("\n\n enter the word to be found:");
scanf("%s",b);
l=strlen(b);
for(i=0;a[i]!='$';i++)
{
if(a[i]==b[0]||z==0)
{
j=0;
k=0;
z=1;
}
if(a[i]!=b[j])
{
k++;
i--;
}
j++;
if(k==0&&j==l)
break;

}
if(k==0)
printf("\n ***found***");
else
printf("\n ###not found###");
getch();
}

decimal to octal,binary and Hexadecimal conversion

#include< stdio.h>
#include< conio.h>
void convrt(int a,int b);
void hexdec(int a);
main()
{
int a,c,r;
char cc;
do
{
clrscr();
printf("\n\n\n\t\tMenu");
printf("\n\n\tConvert decimal to");
printf("\n\n\t1.Binary\n\n\t2.Octal\n\n\t3.Hexadecimal\n\n\t4.Exit\n\n Enter your choice : ");
scanf("%d",&c);
if(c==4)
goto ent;
printf("\n\n Enter the decimal no : ");
scanf("%d",&a);
switch(c)
{
case 1:
convrt(a,2);
break;
case 2:
convrt(a,8);
break;
case 3:
hexdec(a);
break;
}
getch();
printf("\n\n Do you want to continue : ");
cc=getche();
}
while(cc=='y'||cc=='Y');
ent:
getch();
}

void convrt(int a,int b)
{
int n,i=1,p=0;
while(a!=0)
{
n=a%b;
p=p+n*i;
a=a/b;
i=i*10;
}
printf(" result= %d ",p);
}
void hexdec(int a)
{
char h[15];
int uu,r,i;
for(i=0;a!=0;i++)
{
r=a%16;
if(r<=9)
{
//printf("%d",48+r);
h[i]=char(48+r);
}
else if(r>9)
{
h[i]=char(55+r);
}
uu=i;
a=a/16;
}
for(i=uu;i>=0;i--)
printf("%c",h[i]);
}

LCM of Two Nos

#include < stdio.h>
#include < conio.h>
main()
{
int a,b,t,i=1;;
clrscr();
printf("Enter Two Nos : ");
scanf("%d%d",&a,&b);
if(b>a)
{
t=a;
a=b;
b=t;
}
for(i=1;i<=a;i++)
{
if((i*b)%a==0)
{
printf("LCM = %d",i*b);
break;
}
}
getch();
}

Programme to find HCF using Euclidean algorithm

A way of finding the highest common factor of two different numbers:
1) Divide the larger number by the smaller.
2) If the division can be done exactly then the HCF is the smaller number. If there is a remainder then the HCF is the same as the HCF of the remainder and the smaller number - so repeat step 1 with these two numbers.
For instance, to find HCF(17, 20):
20/17 = 1, with remainder 3
so the HCF is the same as HCF(17, 3):
17/3 = 6 with remainder 1
so the HCF is the same as HCF(3, 1):
3/1 = 3; this is exact, so the HCF is 1.

Programme

#include
#include
void hcf(int a,int b);
main()
{
int a,b,t;
clrscr();
printf("Enter two nos : ");
scanf("%d%d",&a,&b);
if(b>a)
{
t=a;
a=b;
b=t;
}
hcf(a,b);
}
void hcf(int a,int b)
{
int x;
x=a%b;
if(x==0)
{
printf("\n\t hcf = %d",b);
getch();
}
else
hcf(b,x);
}

Decimal to Binary

Write a program to convert decimal no to binary?

#include
#include
main()
int i,j,n,a[10];
clrscr();
printf("ENTER THE NO.:");
scanf("%d",&n);
printf("BINARY CODE IS ");
for(i=0;n!=0;i++)
{
a[i]=n%2;
n=n/2;
}
i--;
for(j=i;j>=0;j--)
printf("%d",a[j]);
getch();
}