You are on page 1of 5

Palindrome :

#include<stdio.h>
#include<conio.h>
void main()
{
int n,s=0,m,r;
clrscr();
printf("enter any no");
scanf("%d",&n);
m=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(s == m) // This is important step
printf("the no is palindrome");
else
printf("no is not palindrome");
getch();
}

#include<stdio.h>
#include<string.h>
#define size 26

void main()
{
char strsrc[size];
char strtmp[size];

clrscr();
printf("\n Enter String:= "); gets(strsrc);

strcpy(strtmp,strsrc);
strrev(strtmp);

if(strcmp(strsrc,strtmp)==0)
printf("\n Entered string \"%s\" ispalindrome",strsrc);
else
printf("\n Entered string \"%s\" is not 
palindrome",strsrc);
getch();
}
 
Fibonnaci :

#include<stdio.h>

int main()
{
    unsigned int i=0,j=0,sum=1,num;
    printf("nEnter the limit for the series ");
    scanf("%d",&num);
    while(sum<num)
    {
       printf("%d ",sum);
        i=j;
        j=sum;
        sum=i+j;
                       
    }
    
   
  getch();   
}

Matrix multiplication :

# include "stdio.h"
main()
{
int m1[10][10],i,j,k,m2[10][10],mult[10][10],r1,c1,r2,c2;
printf("Enter number of rows and columns of first matrix (less than 10)\n");
scanf("%d%d",&r1,&c1);
printf("Enter number of rows and columns of second matrix (less than 10)\n");
scanf("%d%d",&r2,&c2);
if(r2==c1)
{
printf("Enter rows and columns of First matrix \n");
printf("Row wise\n");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
printf("First Matrix is :\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[i][j]);
printf("\n");
}
printf("Enter rows and columns of Second matrix \n");
printf("Row wise\n");
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
printf("Second Matrix is:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[i][j]);
printf("\n");
}
printf("Multiplication of the Matrices:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
mult[i][j]+=m1[i][k]*m2[k][j];
printf("%d\t",mult[i][j]);
}
printf("\n");
}
}
else
{
printf("Matrix multiplication cannot be done");
}
return 0;

Inverse of matrix :
#include <stdio.h>
#include <stdlib.h>

int main ()
{
void printMatrix (char name, double **matrix, int n);

int input, entries, i, j;


double **A, **B, temp;
printf("Enter dimension of square matrix:");
scanf ("%d", &input);
entries = input * input;
printf ("Enter the %d entries of the matrix:", entries);

A = (double **) malloc (input* sizeof (double *));


for (i=0; i<input; i++)
{
A[i] = (double *) malloc (input* sizeof (double));
}

B = (double **)malloc (input* sizeof (double *));


for (j=0; i<input; i++)
{
B[i] = (double *) malloc (input* sizeof (double));
}

for (i=0; i<input; i++)


{
for (j=0; j<input; j++)
{
scanf("%lf", &A[i][j]);
}
}

for (i=0; i<input; i++)


{
for (j=0; j<input; j++)
{
if ( i == j)
B[i][j] = 1;
else
B[i][j] = 0;
}
}

if (A[0][0]==0)
{
for(i=0;i<input;i++)
{
temp=A[0][i];
A[0][i]=A[1][i];
A[1][i]=temp;

temp=B[0][i];
B[0][i]=B[1][i];
B[1][i]=temp;
}
}

temp = A[0][0];

for(i=0;i<input;i++)
{
for(j=0;j<input;j++)
{
A[i][j]/=temp;
B[i][j]/=temp;
}
}

for (i=1;i<input;i++)
{
temp = A[i][0];
for(j=0;j<input;j++)
{
A[i][j]-=A[0][j]*temp;
B[i][j]-=B[0][j]*temp;
}
}
for (i=0; i<input; i++)
{
printf ("\n");
for (j=0; j<input; j++)
{
printf("%f ", A[i][j]);
}
}

for (i=0; i<input; i++)


{
printf ("\n");
for (j=0; j<input; j++)
{
printf("%f ", B[i][j]);
}
}

return 0;
}

You might also like