#include<stdio.
h>
main()
{
int n1,n2;
printf("enter the two numbers\n");
scanf("%d%d",&n1,&n2);
int a=n1,b=n2;
while(a!=b)
{
if(a>b)
a=a-b;
else if(a<b)
b=b-a;
else
break;
}
printf("HCF=%d,LCM=%d of(%d,%d)",a,(n1*n2)/a,n1,n2);
}
OUTPUT
enter the two numbers
556
338
HCF=2,LCM=93964 of(556,338)
#include<math.h>
#include<stdio.h>
void primes(int);
void fibs(int);
int main()
{
int I;
printf("\n enter the limit\n");
scanf("%d",&I);
printf("\nprime series is \t");
primes(I);
printf("\n fibonacci series is\t");
fibs(I);
}
void primes(int I )
{
int c=0;
int d,n;
for(n=2;n<1000;n++)
{
for(d=2;d<=n/2;d++)
{
if(n%d==0)
break;
}
if(d>n/2)
{
c=c+1;
if(c>I)
return;
printf("%d\t",n);
}
}
}
void fibs(int I)
{
int a=0,b=1,c,count=1;
c=a+b;
while(count<=I)
{
count++;
printf("%d\t",a);
a=b;
b=c;
c=a+b;
}
}
OUTPUT
enter the limit
20
prime series is
37
41
fibonacci series is
89
144
2
43
0
233
3
47
1
377
5
53
1
610
#include<stdio.h>
#include<string.h>
char *toBaseN(long num, int base,char *n);
long toDec(char *n,int base);
void main()
{
char n[50],m[50];
int base,newbase;
long numDec;
char *strres;
printf("enter number,base\n");
scanf("%s %d",n,&base);
printf("enter new base\n");
scanf("%d",&newbase);
printf("original:%s",n);
numDec=toDec(n,base);
printf("\n decimal:%ld",numDec);
strres=toBaseN(numDec,newbase,m);
printf("\nconverted:%s",strres);
}
char *toBaseN(long num,int base,char*n)
7
59
2
987
11
61
3
1597
13
67
5
2584
17
19
71
8
13
4181
23
29
31
21
34
55
{
int d,len;
int i=0;
char t;
while (num>0)
{
d=num%base;
if(base==16&&d>9)
n[i]=55+d;
else
n[i]=48+d;
num/=base;
i++;
}
n[i]='\0';
len=strlen(n);
for(i=0;i<=((len/2)-1);i++)
{
t=n[i];
n[i]=n[len-i-1];
n[len-i-1]=t;
}
return n;
}
long toDec(char*n,int base)
{
int i=0;
int pos=1;
long num=0;
for(i=strlen(n)-1;i>=0;i--)
{
if (n[i]>=48&& n[i]<=57)
num=num+(n[i]-48)*pos;
else if(n[i]>=65&&n[i]<=70);
{
if(base==16)
num=num+(n[i]-55)*pos;
}
pos=pos*base;
}
return num;
}
OUTPUT
enter number,base
ADEF23 16
enter new base
2
original:ADEF23
decimal:11398863
converted:101011011110111011001111
#include<stdio.h>
void readmatrix(int A[20][20],int r,int c);
void showmatrix(int A[20][20],int r,int c);
void main()
{
int r1,r2,c1,c2,i,j,k;
int A[20][20],B[20][20],C[20][20];
printf("enter rowsand colomns of first matrix:\n");
scanf("%d%d",&r1,&c1);
printf("enter rowsand colomns of second matrix:\n");
scanf("%d%d",&r2,&c2);
if(c1!=r2)
{
printf("matrix multiplication is impossible......\n");
return;
}
printf("enter thr elements of first matrix\n");
readmatrix(A,r1,c1);
printf("enter thr elements of second matrix\n");
readmatrix(B,r2,c2);
for(i=0;i<=r1-1;i++)
{
for(j=0;j<=c2-1;j++)
{
C[i][j]=0;
for(k=0;k<=r2-1;k++)
{
C[i][j]=C[i][j]+A[i][k]*B[k][j];
}
}
}
printf("the given matrices are:\n");
showmatrix(A,r1,c1);
printf("\n");
showmatrix(B,r2,c2);
printf("the product matrix is:\n");
showmatrix(C,r1,c2);
}
void readmatrix(int A[20][20],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&A[i][j]);
}
}
}
void showmatrix (int A[20][20],int r,int c)
{
int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",A[i][j]);
}
printf("\n");
}
}
OUTPUT
enter rows and colomns of first matrix:
34
enter rowsand colomns of second matrix:
45
enter thr elements of first matrix
567786547898
enter thr elements of second matrix
23423457876985456789
the given matrices are:
5
6
7
7
8
6
5
4
7
8
9
8
2
3
4
2
4
5
7
8
6
9
8
5
5
6
7
8
the product matrix is:
111 150 167 149
90
123 142 121
140 190 212 187
3
7
4
9
148
122
185