Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

PALINDROME STRING:

A String is called palindrome if string remains same if its characters are reversed.
EX: mom. If you reverse mom it still remain same. so it is called palindrome

#include <stdio.h>
#include <string.h>
void main()
{
char a[100], b[100];
printf("Enter the string : \n");
gets(a);
strcpy(b,a);
strrev(b);
if (strcmp(a,b) == 0)
printf(" It is a palindrome \n");
else
printf("It is not a palindrome \n");
}

OUTPUT:
Enter the string: MOM
It is a palindrome
or
Enter the string: san
It is not a palindrome

GCD OF TWO NUMBERS:


HCF is also called as greatest common divisor( gcd). HCF of two numbers can divide both
numbers without any remainder. EX: 4 & 8 is 4

#include<stdio.h>
void main()
{
int x,y,m,i;
clrscr();
printf("GCD OF TWO NUMBERS");
printf("Insert any two number: ");
scanf("%d%d",&x,&y);
if(x>y)
m=y;
else
m=x;
for(i=m;i>=1;i--)
{
if(x%i==0&&y%i==0)
{
printf("\nHCF of two number is : %d",i) ;
break;
}
}
}
OUTPUT:
GCD OF TWO NUMBERS
Insert any two number: 4
HCF of two number is : 4

BUBBLE SORT:
Arrange number in

proper order

#include <stdio.h>
void main()
{
int array[100], n, c, d, swap;
clrscr();
printf("BUBBLE SORT \n");
printf("Enter number of elements :\n");
scanf("%d", &n);
printf("Enter %d integers :\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1])
{
swap

= array[d];

array[d]

= array[d+1];

array[d+1] = swap;
}
}
}

printf("Sorted list in ascending order:\n");


for ( c = 0 ; c < n ; c++ )
printf("%d\n", array[c]);
}

OUTPUT:
BUBBLE SORT
Enter number of elements :
6
3
1
Sorted list in ascending order:
1
3
6

FIBONACCI SERIES:
The first two Fibonacci numbers are 0 and 1 then next
number is addition of previous two numbers.
#include<stdio.h>
void main()
{
int a= -1,b=1,c,i,n;
clrscr();
printf(FIBONACCI SERIES\n);
printf(Enter number: \n);
scanf(%d,&n);
for(i=0;i<n;i++)
{
c=a+b;
printf(%d,c);
a=b;
b=c;
}
}
OUTPUT:

FIBONACCI SERIES
Enter number: 4
0
1
1
2

LINEAR SEARCH:
Linear search is also known as sequential search. It is
a process that checks every element in the list
sequentially until the desired element is found.

#include<stdio.h>
void main()
{
int a[20];
int i,size,search;
clrscr();
printf( LINEAR SEARCH \n );
printf( Enter number of elements: \n);
scanf(%d,&size);
for(i=0;i<size;i++)
{
printf(Enter % d element : \n , i+1);
scanf(%d,&a[i]);
}
printf(Enter element to be searched :\n);
scanf(%d,& search);

for(i=0;i<size;i++)
{
if( search = = a [i])
{
printf(Element present in the list at position : %d,
i+1);
getch();
}
}
}
OUTPUT:
LINEAR SEARCH
Enter number of elements:

Enter 1 element : 4
Enter 2 element : 5
Enter 3 element:

Enter element to be searched:

Element present in the list at position:

NPR AND NCR:

#include<stdio.h>
long int fact(int x);
void main()
{
long int n,r,x;
clrscr();
printf(NPR AND NCR\n);
printf(Enter value for n and r:\n);
scanf(%d%d,&n,&r);
printf(The ncr value is :%d,fact(n)/(fact(r)*fact(n-r)));
printf(The npr value is :%d,fact(n)/fact(n-r));
getch();
}
long int fact(int x)
{
if(x==0)
return 1;
else
return(x*fact(x-1));
}
OUTPUT:
NPR AND NCR
Enter value for n and r:
5
2
The ncr value is:

10

The npr value is:

20

MATRIX ADDITION:

Two matrices may be added or subtracted only if they


have the same dimension, that is, they must have the
same number of rows & columns.
#include<stdio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j;
printf(MATRIX ADDITION\n);
printf(Enter First Matrix:\n);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf(%d,&a[i][j]);
printf(Enter Second Matrix:\n);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf(%d,&b[i][j]);
printf(The First Matrix is:\n);
for(i=0;i<3;i++)
{
printf(\n);
for(j=0;j<3;j++)
printf(%d\t,a[i][j]);
printf(The Second Matrix:\n);
for(i=0;i<3;i++)

{
printf(\n);
for(j=0;j<3;j++)
printf(%d\t,b[i][j]);
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
printf(The Addition of two matrix is :\n);
for(i=0;i<3;i++)
{
printf(\n);
for(j=0;j<3;j++)
printf(%d\t,c[i][j]);
}
}

OUTPUT:
Enter the First Matrix:
1 1 1

2 2 2
3 3 3
Enter the second Matrix:
1 1 1
2 2 2
3 3 3
The First Matrix is :
1 1 1
2 2 2
3 3 3
The Second Matrix is :
1 1 1
2 2 2
3 3 3
The Addition of two matrix is :
2 2 2
4 4 4
6 6 6

C PROGRAMMING
PRACTICAL BOOK
I B.COM CA

C PROGRAMMING INDEX
PAGE

S.N PROGRAM NAME


O

PAGE SIGN

1.
PALINDROME STRING

GCD OF TWO NUMBERS

BUBBLE SORT

3-4

FIBONACCI SERIES

LINEAR SEARCH

6-7

NPR & NCR

MATRIX ADDITION

9-11

MATRIX MULTIPLICATION

12-13

2.
3.
4.
5.
6.
7.
8.

You might also like