50 Program and Answers
50 Program and Answers
h>
1) Program To Print Welcome Message. int main()
#include <stdio.h> {
int main() struct date d;
{ getdate(&d);
printf("Current system date is %d / %d / %d",
printf( "Welcome to C Programming World. d.da_day, d.da_mon, d.da_year);
\n" ); getch();
getchar(); return 0;
return 0; }
} 7) Program To Swap Two Numbers Using
OUTPUT: Temporary Variables.
Welcome to C Programming World. #include <stdio.h>
2) Program To Accept & Display A Number. #include <conio.h>
#include <stdio.h> main()
#include <conio.h> {
main() int x, y, temp;
{ printf("Enter the value of x and y ");
int number; scanf("%d %d", &x, &y);
printf("Enter an integer "); printf("Before Swapping\nx = %d\ny =
scanf("%d", &number); %d\n",x,y);
printf("Integer that you have entered is temp = x;
%d",number); x = y;
getch(); y = temp;
return 0; printf("After Swapping\nx = %d\ny =
} %d\n",x,y);
OUTPUT: getch();
Enter an integer 9 return 0;
Integer you have entered is 9 }
3) Program To Add Two Numbers. OUTPUT:
4) Program To Perform Arithmetic Operations. Enter the value of x and y 2
5) Program To Print Sum Of Digits In A Number. 4
#include <stdio.h> Before Swapping
#include <conio.h> x=2
main() y=4
{ After Swapping
int num, sum = 0, rem; x=4
printf("Enter a number\n"); y=2
scanf("%d",&num); 8) Program To Swap Two Numbers Without
while( num != 0 ) Using Temporary Variables.
{ #include <stdio.h>
rem = num % 10; main()
sum = sum + rem; {
num = num / 10; int a, b;
} printf("Enter two numbers to swap ");
printf("Sum of digits of entered number = scanf("%d %d", &a, &b);
%d\n",sum);
getch(); a = a + b;
return 0; b = a - b;
} a = a - b;
printf("a = %d\nb = %d\n",a,b);
OUTPUT: return 0;
Enter a number }
36 OUTPUT:
Sum of digits of entered number = 9 Enter two numbers to swap 2
6) Program To Print The System Date. 4
#include <stdio.h> a=4
#include <conio.h> b=2
9) Program To Print First Ten(10) Natural printf( " \nArea of rectangle is : %f square
Numbers. units. ", area );
#include <stdio.h> return 0;
#include <conio.h> }
main() float area_rect ( float l, float b )
{ {
int c; float area;
for ( c = 1 ; c <= 10 ; c++ ) area = l * b;
printf("%d\n", c); return( area );
getch(); }
return 0; OUTPUT:
} Enter the length and breadth of the
OUTPUT: rectangle
1 6
2 4
3 Area of rectangle is : 24.000000 square
4 units.
5 12) Program To Find Factorial Of A Number.
6 #include <stdio.h>
7 #include <conio.h>
8 void main()
9 {
10 int n, i, fact=1;
10) Program To Find Area & Circumference Of A clrscr();
Circle. printf(" Enter any no: ");
#include <stdio.h> scanf("%d", &n);
#include <conio.h> for( i = n; i >= 1; i-- )
void main() {
{ fact = fact * i;
int r; }
float pi=3.14, area, ci; printf(" Factorial =%d",fact);
clrscr(); getch();
printf("Enter radius of circle: "); }
scanf("%d",&r);
area = pi * r * r; OUTPUT:
printf("Area of circle =%f",area); Enter any no: 5
ci = 2 * pi * r; Factorial = 120
printf("Circumference =%f",ci); 13) Program To Print Fibonacci Series Upto 100.
getch(); #include <stdio.h>
} #include <conio.h>
OUTPUT: void main()
Enter radius of circle: 5 {
Area of circle =78.500000 Circumference int a = 1, b = 1, c = 0, i;
=31.400002 clrscr();
11) Program To Find The Area Of A Rectangle printf(" %d\t %d\t ", a, b);
(Using Functions). for( i = 0; i <= 10; i++)
#include <stdio.h> {
#include <conio.h> c = a + b;
#include <math.h> if(c < 100)
float area_rect( float, float ); {
main() printf("%d\t",c);
{ }
clrscr(); a = b;
float l, b, area; b = c;
printf( " \nEnter the length and breadth of }
the rectangle " ); getch();
scanf( " %f %f ", &l, &b ); }
area = area_rect ( l , b ); OUTPUT:
1 1 2 3 5 8 13 21 34 55 89 else
14) Program To Calculate Simple Interest. printf(" Number is odd ");
#include <stdio.h> getch();
#include <conio.h> }
void main() OUTPUT:
{ Enter any number: 6
int p, r, t, si; Number is even
clrscr(); 17) Program To Find Greatest Among Three
printf(" Enter principle, rate of interest & Numbers.
time to find simple interest: "); #include <stdio.h>
scanf(" %d %d %d",&p, &r, &t); #include <conio.h>
si = ( p * r * t ) / 100; void main()
printf(" Simple interest = %d",si); {
getch(); int a, b, c;
} clrscr();
OUTPUT: printf(" Enter value of a, b & c: ");
Enter principle, rate of interest & time to scanf("%d %d %d",&a, &b, &c);
find simple interest: 1000 if( ( a>b ) && ( a>c ) )
2 printf(" a is greatest.");
5 if( ( b>c ) && ( b>a ) )
Simple interest = 100 printf(" b is greatest.");
15) Program To Check Whether A Number Is
Prime Or Not. if( ( c>a ) && ( c>b ))
#include <stdio.h> printf(" c is greatest.");
#include <conio.h> getch();
void main() }
{ OUTPUT:
int i, n ,r=0; Enter value of a, b & c: 2
clrscr(); 5
printf(" Enter any no: "); 10
scanf("%d",&n); c is greatest.
for( i = 2; i <= n - 1; i++ ) 18) Program To Compute The Reverse Of A
{ Number.
if( n % i == 0) #include <stdio.h>
r = 1; #include <conio.h>
break; void main()
} {
if( r == 0) int n, a, r=0;
printf(" Is prime "); clrscr();
else printf(" Enter any number to get its
printf(" Not prime "); reverse: ");
getch(); scanf("%d",&n);
} while(n>=1)
OUTPUT: {
Enter any no: 8 a = n % 10;
Not prime r = r * 10 + a;
16) Program To Check Whether A Number Is n = n / 10;
Even Or Not. }
#include <stdio.h> printf(" Reverse = %d",r);
#include <conio.h> getch();
void main() }
{ OUTPUT:
int n; Enter any number to get its reverse: 65
clrscr(); Reverse = 56
printf(" Enter any number: "); 19) Program To Convert Degree Celsius
scanf(" %d ",&n); Temperature To Fahrenheit.
if( n % 2 == 0) #include <stdio.h>
printf(" Number is even "); #include <conio.h>
void main() return(area);
{ }
float c, f; OUTPUT:
clrscr(); Enter the three sides of a triangle 2
printf(" Enter temp in centigrade: "); 2
scanf("%f",&c); 2
f = ( 1.8 * c ) + 32; Area of triangle is : 1.732051 square units.
printf(" Temperature in Fahrenheit = %f", f); 22) Program To Sort A Given Set Of Numbers In
getch(); Ascending Numbers.
} #include <stdio.h>
OUTPUT: #include <conio.h>
Enter temperature in centigrade: 25 swap (int*, int*);
Temperature in Fahrenheit = 77.000000 main()
20) Program To Accept Floating Point Numbers {
& Print Average. clrscr();
#include <stdio.h> int i, j;
#include <conio.h> int arr[10];
int main(void) int *a;
{ a=arr;
float a, b, c, d, avg=0; for ( i = 0; i < 10; i++ )
clrscr(); {
printf("\n Enter the four floating point printf (" Enter the number %d : ", i + 1 );
no's.\n"); scanf ( "%d", &arr[i] );
scanf(" %f %f %f %f " ,&a, &b, &c, &d); }
avg = ( a + b + c + d ) / 4; printf (" Before sorting:\n" );
printf("\n The average is = %10.5f",avg);
getch(); for ( i = 0; i < 10 ; i++ )
return 0; printf ( " %d " , arr[i] );
} printf ( "\n" );
OUTPUT: for ( i = 0; i < 10; i++ )
Enter the four floating point nos. for ( j = 0; j < 10 - i - 1; j++ )
2.1 if ( * ( arr + j ) > * ( arr + (j + 1) )
3.2 swap ( arr + j , arr + (j + 1) );
4.3 printf ( "After sorting :\n" );
5.4 for ( i = 0 ; i < 10 ; i++)
The average is = 3.75000 printf ( "%d ", arr [i] );
21) Program To Find The Area Of A Triangle. printf ( "\n" );
#include <stdio.h> return 0;
#include <conio.h> }
#include <math.h> swap(int *b,int *c )
float tri_area(float, float, float); {
main() int temp;
{ temp = *b;
clrscr(); *b = *c;
float s1, s2, s3, area; *c = temp;
printf("\nEnter the three sides of a return 0;
triangle"); }
scanf("%f %f %f" ,&s1, &s2, &s3); OUTPUT:
area = tri_area(s1, s2, s3); Enter the number 1 : 6
printf("\nArea of triangle is : %f square Enter the number 2 : 3
units.", area); Enter the number 3 : 2
return 0; Enter the number 4 : 10
} Enter the number 5 : 4
float tri_area(float a, float b, float c) Enter the number 6 : 2
{ Enter the number 7 : 8
float s, area; Enter the number 8 : 13
s = ( a + b + c ) / 2; Enter the number 9 : 7
area = sqrt ( s * (s - a) * (s - b) * (s - c) ); Enter the number 10 : 20
Before sorting: {
6 3 2 10 4 2 8 13 7 20 int a[50], i, n, s, t=0;
After sorting : clrscr( );
2 2 3 4 6 7 8 10 13 20 printf("\n\n Enter the number of elements
23) Program To Specify Size Of Commonly Used you want to enter ");
Data Types. scanf(" %d ",&n);
#include <stdio.h> printf("\n\n Enter the numbers you desire ");
#include <conio.h> for( i = 0; i < n; i++ )
main () scanf(" %d ", &a[i]);
{ printf(" Enter the element to be counted ");
clrscr(); scanf(" %d ", &s);
printf ("\n An int is %d bytes", sizeof (int)); for( i = 0; i < n; i++ )
printf ("\n A char is %d bytes", sizeof (char)); {
printf ("\n A short is %d bytes", sizeof (short)); if( s == a[i] )
printf ("\n A long is %d bytes", sizeof (long)); t++;
printf ("\n A float is %d bytes", sizeof (float)); }
printf ("\n A double is %d bytes", sizeof printf(" The number you entered has
(double)); occurred %d number of times ", t);
printf ("\n An unsigned char is %d bytes", getch( );
sizeof (unsigned char)); }
printf ("\n An unsigned int is %d bytes", sizeof OUTPUT:
(unsigned int)); Enter the number of elements you want to
return 0; enter: 3
} Enter the numbers you desire:
OUTPUT: 6
An int is 2 bytes 5
A char is 1 bytes 6
A short is 2 bytes Enter the element to be counted: 6
A long is 4 bytes The number you entered has occurred 2
A float is 4 bytes number of times
A double is 8 bytes 26) Program To Find The Roots Of A Quadratic
An unsigned char is 1 bytes Equation.
An unsigned int is 2 bytes #include <stdio.h>
24) Program To Accept Input & Multiply Two #include <conio.h>
Numbers. #include <math.h>
#include <stdio.h> void main()
#include <conio.h> {
void main() float a, b, c, d, realp, imgp, r1, r2;
{ clrscr();
clrscr(); printf(" Enter the 3 numbers\n ");
int a, b, c; scanf(" %f %f %f " ,&a, &b, &c);
printf(" Enter the numbers to be if ( a == 0 || b == 0 || c == 0 )
multiplied: "); {
scanf(" %d %d ", &a, &b); printf(" Error input only non zero
c = a * b; numbers\n ");
printf(" The product of the numbers is: %d }
",c); else
getch(); {
} d = b * b - 4 * a * c;
OUTPUT: if ( d == 0 )
Enter the numbers to be multiplied: 10 {
5 printf(" Roots are equal\n ");
The product of the numbers is: 50 r1 = r2 = - b / ( 2 * a );
25) Program To Count The Number Of Times A printf(" Root1 = %f, Root2 = %f ", r1,
Digit Occurs In A Number Array. r2 );
#include <stdio.h> }
#include <conio.h> else if(d>0)
void main( ) {
printf( "Roots are real & distinct\n" ); Occurences of Largest Digit 9 is = 2
r1 = ( - b + sqrt ( fabs ( d ) ) ) / ( 2 * a ); 28) Program To Print Number Of Vowels,
r2 = ( - b - sqrt ( fabs ( d ) ) ) / ( 2 * a ); Consonants, Characters, Words & Spaces In A
printf(" Root1 = %f, Root2 = %f", r1, Line Of Text.
r2); #include <stdio.h>
} #include <conio.h>
else #include <ctype.h>
{ main()
printf(" Roots are imaginary\n "); {
realp = - b / ( 2 * a ); clrscr();
imgp = sqrt ( fabs ( d ) ) / ( 2 * a ); char line[80], c;
printf(" Root1 = %f + i%f, Root2 = %f - int i, vow, cons, dig, word, whites, other;
i%f ",realp, imgp, realp, imgp); i = 0;
} vow = 0;
} cons = 0;
getch(); dig = 0;
} word = 0;
OUTPUT: whites = 0;
Enter the 3 numbers other = 0;
1 printf ( " Enter a line of text: \n" );
4 scanf ( " % [ ^ \n ] ", line);
2 while ( ( c = tolower ( line [ i++ ] ) ) ! = '\0' )
Roots are real & distinct {
Root1 = - 0.585786 , Root2 = - 3.414214 if ( c == 'a' || c == 'e' || c == 'i' || c == 'o'
27) Program To Count The Number Of Times || c == 'u' )
The Largest Digit Occurs In A Number. ++vow;
#include <stdio.h> else if ( c >= 'a' && c <= 'z' )
#include <conio.h> ++cons;
void main() else if ( c >= '0' && c <= '9' )
{ ++dig;
long int n, r, m, max = 0, count = 0; else if ( c == ' ' )
clrscr(); {
printf( "Enter the Number:" ); ++word;
scanf(" %ld ",&n); ++whites;
m = n; while ( ( line[i] == ' ' || line[i] ==
while( n > 0 ) '\t' ) )
{ {
r = n % 10; i++;
if( r > max ) whites++;
max = r; }
n = n / 10; }
} else
++other;
printf( " \nLargest Digit is = %ld ", max); }
while( m > 0) ++word;
{ printf ( " \n\n Total number of :\n " );
r = m % 10; printf( " Vowels = %d\n ", vow );
if( r == max ) printf( " Consonants = %d\n ", cons );
count++; printf( " Numeric digits = %d\n ", dig );
m = m / 10; printf( " Other characters = %d\n ", other );
} printf( " Words = %d\n ", word );
printf( "\n\nOccurences of Largest Digit %ld printf( " White spaces = %d\n ", whites );
is = %ld", max, count); return 0;
getch(); }
} OUTPUT:
OUTPUT: Enter a line of text:
Enter the Number: 22699 Thank you
Largest Digit is = 9 Total number of :
Vowels = 3 Enter the number 3: 3
Consonants = 5 Enter the number 4: 4
Numeric digits = 0 Enter the number 5: 5
Other characters = 0 Enter the number 6: 6
Words = 2 Enter the number 7: 7
White spaces = 1 Enter the number 8: 8
29) Program To Find The Sum Of N Numbers. Enter the number 9: 9
#include <stdio.h> Enter the number 10: 10
#include <conio.h> 1---2---3---4---5---6---7---8---9---10---
main() Total = 55
{ 31) Program To Check Whether A Number Is
int n, sum = 0, c, var; Armstrong Or Not.
printf( " Enter the number of integers you #include <stdio.h>
want to add\n " ); #include <conio.h>
scanf( " %d ", &n); main()
printf( " Enter %d numbers\n ", n ); {
for ( c = 1 ; c <= n ; c++ ) int n, sum = 0, temp, r;
{ printf( " Enter a number " );
scanf( " %d ", &var ); scanf( " %d ", &n);
sum = sum + var; temp = n;
} while( temp != 0 )
printf( " Sum of entered numbers = %d\n ", {
sum ); r = temp % 10;
getch(); sum = sum + r * r * r;
return 0; temp = temp / 10;
} }
OUTPUT: if ( n == sum )
Enter the number of integers you want to add: printf( " Entered number is an armstrong
3 number. " );
Enter 3 numbers 1 2 3 else
Sum of entered numbers = 6 printf( " Entered number is not an
armstrong number. " );
30) Program To Accept & Add Ten Numbers getch();
Using Pointers. return 0;
#include <stdio.h> }
#include <conio.h> OUTPUT:
void main () Enter a number6
{ Entered number is not an Armstrong number.
int i, total; 32) Program To Display The Days In A Week
int arr[10]; (Using Switch...Case Statement).
int *a; #include <stdio.h>
a = arr; #include <conio.h>
for ( i = 0; i < 10; i++ ) void main()
{ {
printf ( " Enter the number %d: ", i+1 ); char ch;
scanf ( " %d ", &arr[i] ); clrscr();
} printf(" Enter m for Monday\n t for
for ( i = 0; i < 10; i++ ) Tuesday\n w for Wednesday\n h for
{ Thursday\n f for Friday\n s for Saturday\n
printf ( " %d--- ", *a ); u for Sunday ");
total = total + *a; scanf(" %c ", &ch);
a = a + 1; switch(ch)
} {
printf ("\nTotal = %d \n",total); case 'm':
} case 'M':
OUTPUT: printf("The day is Monday");
Enter the number 1: 1 break;
Enter the number 2: 2 case 't':
case 'T': OUTPUT:
printf("The day is Tuesday"); Enter any number: 25
break; Square is : 625
case 'w': 34) Program To Find Gross Salary.
case 'W': #include <stdio.h>
printf("The day is Wednesday"); #include <conio.h>
break; void main()
case 'h': {
case 'H':
printf("The day is Thursday"); int gs, bs, da, ta;
break; clrscr();
case 'f': printf(" Enter basic salary: ");
case 'F': scanf("%d",&bs);
printf("The day is Friday"); da = ( 10 * bs ) / 100;
break; ta = ( 12 * bs ) / 100;
case 's': gs = bs + da + ta;
case 'S': printf(" Gross salary = %d ", gs);
printf("The day is Saturday"); getch();
break; }
case 'u': OUTPUT:
case 'U': Enter basic salary: 1000
printf("The day is Sunday"); Gross salary = 1220
break; 35) Program To Check Whether An Year Is A
default : Leap Year Or Not.
printf("Wrong input!"); #include <stdio.h>
break; #include <conio.h>
} void main()
getch(); {
} int n;
OUTPUT: clrscr();
Enter m for Monday printf(" Enter any year: ");
t for Tuesday scanf(" %d ", &n);
w for Wednesday if( n % 4 == 0 )
h for Thursday printf(" Year is a leap year ");
f for Friday else
s for Saturday printf(" Year is not a leap year ");
u for Sunday w getch();
The day is Wednesday }
33) Program To Find The Square Of A Number OUTPUT:
(Using Functions). Enter any year: 2004
#include <stdio.h> Year is a leap year
#include <conio.h> 36) Program To Print Sum Of Series 1 + 3 + 5 +
void main() . N.
{ #include <stdio.h>
int rev( int ); #include <conio.h>
int r, a; void main()
clrscr(); {
int n, i, sum = 0;
printf(" Enter any number: " ); clrscr();
scanf(" %d ", &a); printf(" Enter any number: " );
r = rev( a ); scanf(" %d ", &n);
printf(" Square is : %d ", r); for(i = 1; i<n; i = i + 2 )
getch(); {
} printf(" %d + ", i);
int rev(int x) sum = sum + i;
{ }
return( x * x ); printf(" %d ", n);
} printf(" \nSum = %d ", sum + n );
getch(); for( i = 1; i<=5; i++)
} {
OUTPUT: for( j = 1; j<=i; j++)
Enter any number: 9 printf(" * ");
1+3+5+7+9 printf(" \n ");
Sum = 25 }
37) Program To Add Complex Numbers. getch();
#include <stdio.h> }
#include <conio.h> OUTPUT:
#include <stdlib.h> *
struct complex **
{ ***
int real; ****
int img; *****
}; 39) Program To Print A Star Pyramid.
int main() #include <stdio.h>
{ #include <conio.h>
struct complex a, b, c; void main()
printf(" Enter a and b where a + ib is the first {
complex number. "); int row, c, n, temp;
printf(" \na = "); printf(" Enter the number of rows in
scanf(" %d ", &a.real); pyramid of stars you wish to see: ");
printf(" b = "); scanf(" %d ", &n);
scanf(" %d ", &a.img); temp = n;
printf(" Enter c and d where c + id is the for ( row = 1 ; row <= n ; row++ )
second complex number. "); {
printf(" \nc = "); for ( c = 1 ; c < temp ; c++ )
scanf(" %d ", &b.real); printf(" ");
printf(" d = "); temp--;
scanf(" %d ", &b.img); for ( c = 1 ; c <= 2 * row - 1 ; c++ )
c.real = a.real + b.real; printf(" * ");
c.img = a.img + b.img; printf(" \n ");
if ( c.img >= 0 ) }
printf(" Sum of two complex numbers = %d getch();
+ %di ", c.real, c.img); return 0;
else }
printf(" Sum of two complex numbers = %d OUTPUT:
%di ", c.real, c.img); Enter the number of rows in pyramid of stars
getch(); you wish to see 5
return 0; *
} ***
OUTPUT: *****
Enter a and b where a + ib is the first complex *******
number. *********
a=6 40) Program To Print Floyds Triangle.
b=2 #include <stdio.h>
Enter c and d where c + id is the second #include <conio.h>
complex number. main()
c=2 {
d=6 int n, i, c, number = 1;
Sum of two complex numbers = 8 + 8i printf(" Enter the number of rows of
38) Program to Display a Sequence Using Stars. Floyd's triangle you want " );
#include <stdio.h> scanf(" %d ", &n );
#include <conio.h> for ( i = 1 ; i <= n ; i++ )
void main() {
{ for ( c = 1 ; c <= i ; c++ )
int i, j; {
clrscr(); printf(" %d ", number );
number++; 1
} 2
printf(" \n " ); 3
} 4
getch(); Transpose of entered matrix :-
return 0; 1 3
} 2 4
OUTPUT: 42) Program To Add Two Matrices.
Enter the number of rows of Floyds triangle #include <stdio.h>
you want 6 #include <conio.h>
1 int main()
23 {
456 int m, n, i, j;
7 8 9 10 int first[10][10], second[10][10], sum[10][10];
11 12 13 14 15 printf(" Enter the number of rows and
16 17 18 19 20 21 columns of matrix ");
41) Program To Transpose A Matrix. scanf(" %d %d ", &m, &n);
#include <stdio.h> printf(" Enter the elements of first matrix\n
#include <conio.h> ");
int main() for ( i = 0 ; i < m ; i++ )
{ for ( j = 0 ; j < n ; j++ )
int m, n, i, j; scanf(" %d ", &first[i][j] );
int mat[10][10], trans[10][10]; printf("Enter the elements of second
printf(" Enter the number of rows and matrix\n");
columns of matrix "); for ( i = 0 ; i < m ; i++ )
scanf(" %d %d ", &m, &n); for ( j = 0 ; j < n ; j++ )
printf(" Enter the elements of matrix \n "); scanf(" %d ", &second[i][j] );
for( i = 0 ; i < m ; i++ ) for ( i = 0 ; i < m ; i++ )
{ for ( j = 0 ; j < n ; j++ )
for( j = 0 ; j < n ; j++ ) sum[i][j] = first[i][j] + second[i][j];
{ printf(" Sum of entered matrices:-\n ");
scanf(" %d ", &mat[i][j] ); for ( i = 0 ; i < m ; i++ )
} {
} for ( j = 0 ; j < n ; j++ )
for( i = 0 ; i < m ; i++ ) printf(" %d\t ", sum[i][j] );
{ printf(" \n ");
for( j = 0 ; j < n ; j++ ) }
{ getch();
trans[j][i] = mat[i][j]; return 0;
} }
} OUTPUT:
printf(" Transpose of entered matrix :-\n "); Enter the number of rows and columns of
for( i = 0 ; i < n ; i++ ) matrix 3
{ 3
for( j = 0 ; j < m ; j++ ) Enter the elements of first matrix
{ 1
printf(" %d\t ", trans[i][j] ); 2
} 3
printf(" \n "); 4
} 5
getch(); 6
return 0; 7
} 8
OUTPUT: 9
Enter the number of rows and columns of Enter the elements of second matrix
matrix 2 9
2 8
Enter the elements of matrix 7
6
5 printf("\n");
4 }
3 }
2 getch();
1 return 0;
Sum of entered matrices:- }
10 10 10 OUTPUT:
10 10 10 Enter the number of rows and columns of first
10 10 10 matrix 2
43) Program To Multiply Two Matrices. 2
#include <stdio.h> Enter the elements of first matrix
#include <conio.h> 1
int main() 5
{ 6
int m, n, p, q, i, j, k, sum = 0; 4
int first[10][10], second[10][10], mul[10][10]; Enter the number of rows and columns of
printf(" Enter the number of rows and second matrix 2
columns of first matrix " ); 2
scanf(" %d %d ", &m, &n ); Enter the elements of second matrix
printf(" Enter the elements of first matrix\n " ); 1
for ( i = 0 ; i < m ; i++ ) 2
for ( j = 0 ; j < n ; j++ ) 4
scanf(" %d ", &first[i][j] ); 6
printf(" Enter the number of rows and Product of entered matrices:-
columns of first matrix " ); 21 32
scanf(" %d %d ", &p, &q ); 22 36
44) Program To Find The Length Of A String.
if ( n != p ) #include <stdio.h>
printf(" Matrices with entered orders #include <conio.h>
can't be multiplied with each other." ); #include <string.h>
else main()
{ {
printf(" Enter the elements of second char a[100];
matrix\n " ); int length;
printf(" Enter a string to calculate it's
for ( i = 0 ; i < p ; i++ ) length ");
for ( j = 0 ; j < q ; j++ ) gets(a);
scanf(" %d ", &second[i][j] ); length = strlen(a);
for ( i = 0 ; i < m ; i++ ) printf(" Length of entered string is =
{ %d\n",length);
for ( j = 0 ; j < n ; j++ ) getch();
{ return 0;
for ( k = 0 ; k < p ; k++ ) }
{ OUTPUT:
sum = sum + first[ i ] [ k ] * Enter a string to calculate it's length: noon
second[ k ] [ j ]; Length of entered string is = 4
} 45) Program To Concatenate Two Strings.
mul[ i ] [ j ] = sum; #include <stdio.h>
sum = 0; #include <conio.h>
} #include <string.h>
} int main()
printf(" Product of entered matrices:-\n {
" ); char a[100], b[100];
for ( i = 0 ; i < m ; i++ ) printf(" Enter the first string " );
{ gets(a);
for ( j = 0 ; j < q ; j++ ) printf(" Enter the second string " );
printf(" %d \t ", mul[ i ] [ j ] ); gets(b);
strcat( a, b ); else
printf(" String obtained on concatenation is printf(" Entered strings are not equal.\n ");
%s\n ", a ); getch();
getch(); return 0;
return 0; }
}
OUTPUT: OUTPUT:
Enter the first string Team Enter the first string team
Enter the second string mates Enter the second string team
String obtained on concatenation is Teammates Entered strings are equal.
46) Program To Swap Two Strings. 48) Program To Check Whether A String Is
#include <stdio.h> Palindrome Or Not.
#include <conio.h> #include <stdio.h>
#include <malloc.h> #include <conio.h>
#include <string.h> #include <string.h>
int main()
main() {
{ char a[100], b[100];
char first[100], second[100], *temp; printf(" Enter the string to check if it is a
printf(" Enter the first string " ); palindrome ");
gets(first); gets(a);
printf(" Enter the second string " ); strcpy(b , a);
gets(second); strrev(b);
printf(" \nBefore Swapping\n " ); if (strcmp(a , b) == 0 )
printf(" First string: %s\n ", first ); printf(" Entered string is a palindrome.\n");
printf(" Second string: %s\n\n ", second ); else
temp = ( char* )malloc( 100 ); printf(" Entered string is not a
strcpy( temp, first ); pailndrome.\n");
strcpy( first, second ); getch();
strcpy( second, temp ); return 0;
printf(" After Swapping\n " ); }
printf(" First string: %s\n ", first ); OUTPUT:
printf(" Second string: %s\n ", second ); Enter the string to check if it is a
getch(); palindrome: noon
return 0; Entered string is a palindrome
} 49) Program To Print The Reverse Of A String.
OUTPUT: #include <stdio.h>
Enter the first string little #include <conio.h>
Enter the second string flower #include <string.h>
Before Swapping void main()
First string: little {
Second string: flower char arr[100];
After Swapping printf(" Enter a string to reverse\n ");
First string: flower gets(arr);
Second string: little strrev(arr);
47) Program To Compare Two Strings. printf(" Reverse of entered string is \n %s \n
#include <stdio.h> ", arr);
#include <conio.h> getch();
#include <string.h> return 0;
int main() }
{ OUTPUT:
char a[100], b[100]; Enter a string to reverse
printf(" Enter the first string: "); violet
gets(a); Reverse of entered string is
printf(" Enter the second string: "); teloiv
gets(b); 50) Program To Add Two Numbers Using
if( strcmp ( a , b ) == 0 ) Pointers.
printf(" Entered strings are equal.\n ");
#include <stdio.h>
#include <conio.h>
int main()
{
int x, y, *p, *q, sum;
printf(" Enter two integers to add " );
scanf(" %d %d ", &x, &y );
p = &x;
q = &y;
sum = *p + *q;
printf(" Sum of entered numbers = %d\n ",
sum );
getch();
return 0;
}
OUTPUT:
Enter two integers to add 3
6
Sum of entered numbers = 9