You are on page 1of 48

Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

SarvodayKelavaniSamaj, Rajkot
Sanchalit
Shree ManibhaiVirani& Smt. NavalbenVirani Science College
(Autonomous)
[ Re-accredited at ‘A’ level by NAAC & ‘STAR’ College by MST-DBT
Accredited at the G-AAA ‘A-1’ level by KCG Govt. of Gujarat
A College with Potential for Excellence by UGC]
YogidhamGurukul

DEPARTMENT OF MATHEMATICS
CERTIFICATE
This is to certify that experiments for the course
Course Code: 21UMTCC507
Core Practical: 5 Problem Solving using Programming
duly recorded and initiated in this Journal were performed to my
satisfaction by
Mr./ Miss. _____________________________________
of class
B.Sc. Semester -5 (Mathematics)
during the first term in the academic Year 2023 – 2024 in the
Computer laboratory.
His/her Roll No.: - ____________
Practical Given Performed

Programming in C 24

Date: - Lab In Charge


Exam. Seat No.: -__________

Examiner’s Signature Head of the Department

-1–
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
B.Sc.Mathematics SEMESTER - 5
Core Practical: 5 Problem Solving using Programming
INDEX
Practical Page
Objective of Practical Date Signature
number No.
Write a program to find area of a circle
1 5
when radius is given.

Write a program to calculate the area of


2 a triangle when base and height of the 6
triangle are given.

Write a program to find value of one


3 7
number raised to another number.

Write a program to determine whether


4 8
given number is an even or odd number.

Write a program to find largest of three


5 9
given numbers.

Write a program to find largest of four


6 10
given numbers.

Write program to find net salary when


7 basic salary and other required details 11
are given.

Write a program to solve the quadratic


8 13
equation

Write a program to reverse an integer


9 15
with FIVE digits.

Write a program to verify a number


10 16
whether it is palindrome or not.

Write a program to find sum of the digits


11 17
of an integer with FIVE digits.

Write a program to print Armstrong


12 18
numbers between1 to 999.

Write a program to generate arithmetic


13 19
and geometric progressions.

Write a program to find nPr and nCr for


14 21
given value of +ve integers n and r.

Write a program to find compound interest


15 23
for given years.

Write a program to count even, odd,


16 positive and negative number entered by 25
keyboard.

Write a program to find factorial of a


17 27
given number.

Write a program using UDF with an


18 28
argument and a return value.

-2–
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
Write a program that utilizes a UDF two
19 find prime numbers between two integers 30
entered through key-board.

Write a program to solve the equation by


20 32
N-R method. (Use of preprocessor)

Write a program to find value of the


determinant of 2X2 matrices and a program
21 to find transpose, diagonal and 34
determinant of given 3x3 matrix entered
through keyboard.

Write a program to find inverse of a 2X2


22 38
matrix.

Write a program to find trace of a 3X3


23 40
matrix entered through key-board.

Write a program to find the sum,


24 deference, and multiplication of two 3X3 42
matrices entered through key-board.

-3–
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

PROGRAMMINGwith

C
-4–
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 1
/* Date :- - -2023 */
/* OBJECTIVE:- Write a program to find area of a circle when radius is given. */

//PROGRAM CODE:-
/* OBJECTIVE:- Write a program to find area of a circle when radius is given. */

//PROGRAM CODE:-
#include<stdio.h>
#include<conio.h>
void main()
{ float radius, area;
fflush(stdin); clrscr();

printf("\n\t Please enter the value of radius\t: ");


scanf("%f", &radius);

area = 3.1415*radius*radius;

printf("\n\t Area of the circle with radius %f \t = \t %f \n", radius, area);

printf(“\n\n\n\n\n\n”); getch(); return 0;


} //main over //

/*OUTPUT*/

Please enter the value of radius : 7.5


Area of the circle with radius 7.500000 = 176.709381

Please enter the value of radius : 10


Area of the circle with radius 10.000000 = 314.149994

Please enter the value of radius : 77


Area of the circle with radius 77.000000 = 18625.95312

Sign of Lecturer:-_______________

-5–
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 2
/* Date :- - -2023 */
/* OBJECTIVE:- Write a program to find area of a Triangle when base and height
are given. */

//PROGRAM CODE: -
/* OBJECTIVE:- Write a program to find area of a Triangle when base and height
are given. */
#include<stdio.h>
#include<conio.h>
void main()
{ float base, height, area;
fflush(stdin); clrscr();
printf("\n\t Please enter the value of Base\t: ");
scanf("%f", &base);
printf("\n\t Please enter the value of Height\t: ");
scanf("%f", &height);

area = 0.5*base*height;

printf("\n\t Area of the triangle with base %f & height %f\t=\t%f\n", base, height, area);

printf(“\n\n\n\n\n\n”); getch(); return 0;

} //main over //

/*OUTPUT*/

Please enter the value of Base: 10

Please enter the value of Height: 5

Area of the triangle with base 10.000000 & height 5.000000 = 25.000000

Please enter the value of Base: 35

Please enter the value of Height: 49

Area of the triangle with base 35.000000 & height 49.000000 = 857.500000

Sign of Lecturer:-_______________

Practical no :- 3
-6–
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/* Date :- - -2023 */
/* OBJECTIVE:- Write a program to find value of one number raised to another
number. */

//PROGRAM CODE: -
/* OBJECTIVE:- Write a program to find value of one number raised to another
number. */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{ float a, m, value;
fflush(stdin); clrscr();
printf("\n\t Please enter the value of Base number\t: ");
scanf("%f", &a);
printf("\n\t Please enter the value of power\t: ");
scanf("%f", &m);

value = pow(a, m);

printf("\n\t Value of %f raised to %f \t = \t %f \n", a, m, value);

printf(“\n\n\n\n\n\n”); getch(); return 0;

} //main over //

/*OUTPUT*/

Please enter the value of Base number: 2

Please enter the value of power: 5

Value of 2.000000 raised to 5.000000 = 32.000000

Please enter the value of Base number: 5

Please enter the value of power : 7

Value of 5.000000 raised to 7.000000 = 78125.000000

Please enter the value of Base number: 3.5

Please enter the value of power: 1.3

Value of 3.500000 raised to 1.300000 = 5.096693

Sign of Lecturer:-_______________

-7–
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :-4
/* Date :- - -2023 */
/* OBJECTIVE:-
Write a program to determine whether given number is an even or odd number. */

//PROGRAM CODE: -
/* OBJECTIVE:- Write a program to determine whether given number is an even or
odd number. */
#include<stdio.h>
#include<conio.h>

void main()
{ int no;
fflush(stdin); clrscr();
printf("\n\t Please enter an integer\t: ");
scanf("%d", &no);

if(no%2 == 0)
printf("\n\t %d is an EVEN number\n" , no);
else
printf("\n\t %d is an ODD number\n" , no);

getch(); return 0;

} //main over //

/*OUTPUT*/

Please enter an integer : 45


45 is an ODD number

Please enter an integer : 8


8 is an EVEN number

Please enter an integer : 101


101 is an ODD number

Please enter an integer : 108


108 is an EVEN number

Sign of Lecturer:-_______________

-8–
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 5
/* Date :- - -2023 */
/* OBJECTIVE:- Write a program to find largest of THREE given numbers. */

//PROGRAM CODE: -
/* OBJECTIVE:- Write a program to find largest of three given numbers. */
#include<stdio.h>
#include<conio.h>
void main()
{ float a, b, c;
fflush(stdin); clrscr();
printf("\n\t Please enter three real numbers\t: ");
scanf("%f%f%f", &a, &b, &c);
if(a>=b)
{
if(a>=c)
{printf("\n\t %f is a largest number \n ", a);}
else
{printf("\n\t %f is a largest number \n ", c);}
}
else
{
if(b>=c)
{printf("\n\t %f is a largest number \n ", b);}
else
{printf("\n\t %f is a largest number \n ", c);}
}
printf(“\n\n\n\n\n\n”); getch(); return 0;
} //main over //

/*OUTPUT*/

Please enter three real numbers : 9 5 2


9.000000 is a largest number

Please enter three real numbers : 5 9 2


9.000000 is a largest number

Please enter three real numbers : 5 2 9


9.000000 is a largest number

Please enter three real numbers : 9 2 5


9.000000 is a largest number

Please enter three real numbers : 2 9 5


9.000000 is a largest number

Please enter three real numbers : 2 5 9


9.000000 is a largest number

Please enter three real numbers : 2 2 5


5.000000 is a largest number

-9–
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 6
/* Date :- - -2023 */
/* OBJECTIVE: Write a program to find largest of FOUR given numbers. */

//PROGRAM CODE: -
/* OBJECTIVE:- Write a program to find largest of four given numbers. */
#include<stdio.h>
#include<conio.h>
void main()
{ float no, big;
int i;
fflush( stdin); clrscr();
printf("\n\t Please enter FOUR real numbers\t");
printf("\n\t Your number 1 is \t:\t");
scanf("%f", &no);
big = no;
for(i=2; i<=4; i++)
{
printf("\n\t Your number %d\t:\t", i);
scanf("%f", &no);
if(big<no)
big = no;
}
printf("\n\t The largest of the FOUR given numbers is %f", big);

getch(); return 0;

} //main over //

/*OUTPUT*/

Please enter FOUR real numbers


Your number 1 is: 5

Your number 2 : 9

Your number 3 : 2

Your number 4 : 7

The largest of FOUR given numbers is 9.000000

Please enter FOUR real numbers

Your number 1 is: 2

Your number 2 : 5

Your number 3 : 7

Your number 4 : 9

The largest of the FOUR given numbers is 9.000000

- 10 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 7
Date :- - -2023 */
/* OBJECTIVE: Write program to find net salary when basic salary and other required
details are given. */

/* OBJECTIVE:-Calculation of net salary and gross salary */


/*Details of problem:- In a company an employee is paid as under
If his basic salary is less than Rs. 15000,
then HRA = 10% of basic salary and
DA = 90% of basic salary.
If his salary is either equal to or above Rs. 15000, then
HRA = Rs. 5000 and DA = 98% of basic salary.
The income tax is deducted as 30% of gross salary and
10% of basic salary P.F. is deducted.
If the employee's salary is input through the keyboard
write a program to find his gross salary and net salary */

#include<stdio.h>
#include<conio.h>
void main()
{
float bs, gs, da, hra, it, pf, ns;
clrscr(); fflush(stdin);

printf ( "\n\t Please enter basic salary\t:\t" );


scanf ( "%f", &bs );

if ( bs< 15000 )
{
hra = bs * 0.10;
da = bs * 0.90;
}
else
{
hra = 5000;
da = bs * 0.98;
}

gs = bs + hra + da;
printf ( "\n\t \Gross salary \t = Rs. %.0f", gs );

it = gs*(0.30);
pf = bs*(0.10);
ns = gs - it - pf;

printf ( "\n\t Net salary \t = Rs. %.0f", ns );

getch(); return 0;
} // main over

- 11 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/*OUTPUT*/

Please enter basic salary : Rs. 12000

Gross salary = Rs. 24000


Net salary = Rs. 15600

Please enter basic salary : Rs. 15000

Gross salary = Rs. 34700


Net salary = Rs. 22790

Please enter basic salary : Rs. 10000

Gross salary = Rs. 20000


Net salary = Rs. 13000

Please enter basic salary : Rs. 5000

Gross salary = Rs. 10000


Net salary = Rs. 6500

Sign of Lecturer:-_______________

- 12 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 8
/* OBJECTIVE:-Write a program to solve the quadratic equation */
Date :- - -2023 */

/* OBJECTIVE:- (a)A program to solve the quadratic equation */


#include<stdio.h>
#include<conio.h>
#include<math.h>

void main( )
{double a, b, c, delta, x1, x2, x, real1, im1, real2, im2;

clrscr( );
fflush(stdin);

printf("\n\n\t Please enter value of a, b & c respectively\t:\t");


scanf("%lf %lf %lf", &a, &b, &c);

if(a==0)
{
printf("\n\n\t a=0?");
printf("\n\n\t -->This is not a quadratic equation!<--");
}
else
{ delta=b*b-4*a*c;
if (delta<0) printf( "\n\t NO REAL SOLUTION");
if(delta>0)
{ x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("\n\t Two distinct real roots");
printf("\t x1=%lf", x1);
printf("\t x2=%lf", x2);
}
else
{ if(delta==0)
{ x=-b/(2*a);
printf("\n\t Unique Real Solution is");
printf("\t x=%lf", x);
}
}
}

getch(); return 0;
}

- 13 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/*OUTPUT*/

Please enter value of a, b & c respectively : 1 -5 6


Two distinct real roots x1=3.000000 x2=2.000000

Please enter value of a, b & c respectively : 0 2 3


a=0?
-->This is not a quadratic equation!<-

Please enter value of a, b & c respectively : 1 1 1


NO REAL SOLUTION

Please enter value of a, b & c respectively : 1 -4 4


Unique Real Solution is x=2.000000

Please enter value of a, b & c respectively : 4 20 16


Two distinct real roots x1= -1.000000 x2=-4.000000

Please enter value of a, b & c respectively : 2 9 7


Two distinct real roots x1= -1.000000 x2=-3.500000

- 14 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 9
/* Date :- - -2023 */
/* OBJECTIVE:- To write a C – program to obtain the REVERSED NUMBER. of a FIVE
digit numberentered through keyboard. */

//PROGRAM CODE: -
/* OBJECTIVE:-(a)A C - program to reverse the number. */
#include<stdio.h>
#include<conio.h>
void main()
{ long int sum, no, d1, d2, d3, d4, d5, number;
fflush(stdin);
clrscr();
printf("\n\t Please enter an integer with FIVE digits\t: ");
scanf("%ld", &number);
no=number;
d1=no%10;
no=no/10;
d2=no%10;
no=no/10;
d3=no%10;
no=no/10;
d4=no%10;
no=no/10;
d5=no%10;
sum=d1*10000+d2*1000+d3*100+d4*10+d5;
printf("\n\t Reversed number is %ld\n", sum);

getch(); return 0;
} //main over //

/*OUTPUT*/

Please enter an integer with FIVE digits : 15951


Reversed number is 15951

Please enter an integer with FIVE digits : 14789


Reversed number is 98741

Sign of Lecturer:-_______________

- 15 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 10
/* /*Date :- - -2023 */
/* OBJECTIVE:-Program to decide whether the number entered is Palindrome or not*/
#include<stdio.h>
#include<conio.h>
void main()
{ long int sum, i, m, no, d1, d2, d3, d4, d5, number;
fflush(stdin); clrscr();
printf("\n\t Please enter an integer with FIVE digits\t: ");
scanf("%ld", &number);
no=number;
d1=no%10;
no=no/10;
d2=no%10;
no=no/10;
d3=no%10;
no=no/10;
d4=no%10;
no=no/10;
d5=no%10;
sum=d1*10000+d2*1000+d3*100+d4*10+d5;
printf("\n\t Reversed number is %ld\n", sum);
if (number==sum)
{
printf("\n\t %ld is a Palindrome number\n", number);
}
else
{
printf("\n\t %ld is NOT a Palindrome number\n", number);
}
getch(); return 0;

} //main over //

/*OUTPUT*/

Please enter an integer with FIVE digits : 15951

Reversed number is 15951

15951 is a Palindrome number

Please enter an integer with FIVE digits : 14789

Reversed number is 98741

14789 is NOT a Palindrome number

Sign of Lecturer:-_______________

- 16 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 11
/* Date :- - -2023 */
/* OBJECTIVE:- To write a C - program to calculate sum of digits of the
given number. */

//PROGRAM CODE: -
/* OBJECTIVE:-This program calculates sum of digits of the given number */

#include<stdio.h>
#include<conio.h>

void main()
{ int sum, i, rem, no, number;
clrscr();
fflush(stdin);

printf("\n\t Please enter any number between -32768 to 32767\t:\t");


scanf("%d", &number);

no=number;
sum=0;
for(i=1;i<=9;i++)
{
rem=no%10;
no=no/10;
sum=sum+rem;
if(no==0)break;
}
printf("\n\t Sum of digit=%d", sum);
getch(); return 0;
}// main over //

/*OUTPUT*/

Please enter any number between -32768 to 32767 : 15946

Sum of digit=25

Please enter any number between -32768 to 32767 : 23487

Sum of digit=24

Please enter any number between -32768 to 32767 : 31576

Sum of digit=22

Please enter any number between -32768 to 32767 : 22222

Sum of digit=10

Please enter any number between -32768 to 32767 : 4569


Sum of digit=24

Sign of Lecturer:-_______________

- 17 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 12
/* Date :- - -2023 */
/* OBJECTIVE:A program to find all the ARMSTRONG NUMBERS */

//PROGRAM CODE: -
/* OBJECTIVE:- (a)A program to find all the ARMSTRONG NUMBERS */

# include<stdio.h>
# include<conio.h>
void main( )
{
int sum, i, m, no, d1, d2, d3, d4, d5, number;

fflush(stdin);
clrscr();

printf("\n\t Please enter a number with three digits\t:\t");


scanf("%d", &number);

printf("\n\Armstrong numbers are:\n");


for(i=100; i<=number; i++)
{ no=i;
d1=no%10;
no=no/10;
d2=no%10;
no=no/10;
d3=no%10;
sum=d1*d1*d1+d2*d2*d2+d3*d3*d3;
if(sum==i)
{ printf("\n\t %d", i); }
}
getch(); return 0;
}

/*OUTPUT*/

Please enter a number with three digits : 999

Armstrong numbers are:

153
370
371
407

- 18 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 13
/* Date :- - -2023 */
/* OBJECTIVE: (a) A program to construct ARITHMETICprogression for given a and d
(b) A program to construct GEOMETRICprogression for given a and d */
/* OBJECTIVE:-(a) A program to construct ARITHMETICprogression for given a &d */

#include<stdio.h>
#include<conio.h>
void main()
{ int a, d, n, term, i;
clrscr(); fflush(stdin);
printf("\n\n\t Please enter first term and common difference and n of AP \t\n: ");
scanf("%d%d%d", &a, &d, &n);
printf("\n\t first term a=%d\n\t common difference d=%d", a, d);
printf("\n\t Arithmetic Progression up to %dth term\n", n);
term = a;

for(i = 1; i <= n; i++ )


{
printf("\t%d, ", term);
term = term+d;
}
getch(); return 0;
} // main over //

/*OUTPUT*/

Please enter first term and common difference and n of AP: 2 7 100

first term a=2


common difference d=7
Arithmetic Progression up to 100th term
2, 9, 16, 23, 30, 37, 44, 51, 58,
65, 72, 79, 86, 93, 100, 107, 114, 121, 128,
135, 142, 149, 156, 163, 170, 177, 184, 191, 198,
205, 212, 219, 226, 233, 240, 247, 254, 261, 268,
275, 282, 289, 296, 303, 310, 317, 324, 331, 338,
345, 352, 359, 366, 373, 380, 387, 394, 401, 408,
415, 422, 429, 436, 443, 450, 457, 464, 471, 478,
485, 492, 499, 506, 513, 520, 527, 534, 541, 548,
555, 562, 569, 576, 583, 590, 597, 604, 611, 618,
625, 632, 639, 646, 653, 660, 667, 674, 681, 688,
695

- 19 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/* OBJECTIVE:- (b) A program to construct GEOMETRICprogression for
given a and d */

#include<stdio.h>
#include<conio.h>
void main()
{ int a, r, n, i;
long term;
clrscr(); fflush(stdin);
printf("\n\n\t Please enter first term and common ratio and n of GP \t\n: ");
scanf("%d%d%d", &a, &r, &n);
printf("\n\tFirst term a\t=\t%d\n\tcommon ratio d\t=\t%d", a, r);
printf("\n\t Geometric Progression up to %dth term\n", n);
term = a;
for(i = 1; i <= n; i++ )
{
printf("\t %ld, ", term);
term = term*r;
}
getch(); return 0;
} // main over //

/*OUTPUT*/

Please enter first term and common ratio and n of GP: 2 3 15

First term a = 2
common ratio d = 3
Geometric Progression up to 15th term

2, 6, 18, 54, 162, 486,


1458, 4374, 13122, 39366, 118098, 354294,
1062882, 3188646, 9565938

Sign of Lecturer:-_______________

- 20 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 14
/*Date :- - -2023 */
/*OBJECTIVE: To write a C – program to find the value of nPr and nCr for given
n and r entered through keyboard. */

/* OBJECTIVE:- A program to find the value of nPr for given values of n and r*/
#include<stdio.h>
#include<conio.h>
void main()
{
double value;
int i, n, r;
clrscr();
fflush(stdin);

printf("\n\t Please enter non-negative value of N less than 100\t:\t");


scanf("\n\t %d", &n);
printf("\t Please enter non-negative value of R less than 99\t:\t");
scanf("%d", &r);
printf("\n\t n=%d\n\tR=%d", n, r);
value=1;
for(i=n;i>=n-r+1;i--)
{ value=value*i; }
printf("\n\t nPr=%dP%d=%.0lf", n, r, value); getch(); return 0;

/*OUTPUT*/
N=7
R=2
nPr=7P2= 42

Please enter non-negative value of N less than 100 : 15


Please enter non-negative value of R less than 99 : 4

N=15
R=4
nPr=15P4= 32760

Please enter non-negative value of N less than 100 : 100


Please enter non-negative value of R less than 99 : 52

N=100
R=52
nPr=100P52= 7.517870952824667160000000000000000000000e+96

Please enter non-negative value of N less than 100 : 25


Please enter non-negative value of R less than 99 : 5

N=25
R=5
nPr=25P5= 6375600

Sign of Lecturer:-_______________

- 21 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/*OBJECTIVE: To write a C – program to find the value of nPr and nCr for given
n and r entered through keyboard. */

/* OBJECTIVE:- A program to find the value of nCr for given values of n and r*/
#include<stdio.h>
#include<conio.h>

void main()
{
double value, fact;
float i, n, r;
clrscr();fflush(stdin);

printf("\n\t Please enter a non-negative value of N less than 100\t:\t");


scanf("%f", &n);
printf("\n\tPlease enter a non-negative value of R less than N\t:\t");
scanf("%f", &r);

printf("\n\t N=%3.0f \n\t R=%3.0f", n, r);


value=1;
fact=0;
for(i=n; i >= r+1; i-- )
{
fact=fact+1;
value=value*(i/fact);
};

printf("\n\tnCr=%3.0fC%3.0f=%30.0lf", n, r, value);

getch(); return 0;

/*OUTPUT*/

Please enter a non-negative value of N less than 100 : 5


Please enter a non-negative value of R less than N : 5
N = 5
R = 5
nCr = 5C5 = 1

Please enter a non-negative value of N less than 100 : 9


Please enter a non-negative value of R less than N : 0
N = 9
R = 0
nCr = 9C0 = 1

Please enter a non-negative value of N less than 100 : 99


Please enter a non-negative value of R less than N : 23
N = 99
R = 23
nCr = 99C23 = 19146258135816089900000

Sign of Lecturer:-_______________

- 22 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 15
Date :- - -2023 */
/* OBJECTIVE: To write a C – programto find compound interest for given years.*/

#include<stdio.h>
#include<conio.h>
void main()
{
float a, i, j, p, p1, n, r;
fflush(stdin); clrscr();
printf("\n\t Please enter principle\t: \tRs. ");
scanf("%f", &p);

printf("\n\t Please enter rate of interest\t: \t ");


scanf("%f", &r);

printf("\n\t Please enter number of years\t: \t ");


scanf("%f", &n);

p1 = p;
for(j=1; j<=n; j++)
{
i = (p1*r)/100.0;
p1 = p1+i;
printf("\n\t j = %.0f\t Interest = Rs.%.2f\t p = Rs.%.2f", j, i, p1 );
}

printf("\n\t Principle\t\t: \t Rs.\t%.2f", p);


printf("\n\t Rate of interest\t:\t%.2f", r);
printf("\n\t Number of years\t\t:\t%.0f years", n);
printf("\n\t Compound Interest\t:Rs.\t%.2f", i);
printf("\n\t Amount on maturity\t:Rs.\t%.2f", p1);

getch(); return 0;
} //main over //

- 23 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/*OUTPUT*/

Please enter principle : = Rs. 100000

Please enter rate of interest : 8

Please enter number of years : 25

j = 1 Interest = Rs. 8000.00 p = Rs. 108000.00


j = 2 Interest = Rs. 8640.00 p = Rs. 116640.00
j = 3 Interest = Rs. 9331.20 p = Rs. 125971.20
j = 4 Interest = Rs. 10077.70 p = Rs. 136048.91
j = 5 Interest = Rs. 10883.91 p = Rs. 146932.81
j = 6 Interest = Rs. 11754.62 p = Rs. 158687.44
j = 7 Interest = Rs. 12695.00 p = Rs. 171382.44
j = 8 Interest = Rs. 13710.59 p = Rs. 185093.03
j = 9 Interest = Rs. 14807.44 p = Rs. 199900.47
j = 10 Interest = Rs. 15992.04 p = Rs. 215892.50
j = 11 Interest = Rs. 17271.40 p = Rs. 233163.91
j = 12 Interest = Rs. 18653.11 p = Rs. 251817.02
j = 13 Interest = Rs. 20145.36 p = Rs. 271962.38
j = 14 Interest = Rs. 21756.99 p = Rs. 293719.38
j = 15 Interest = Rs. 23497.55 p = Rs. 317216.94
j = 16 Interest = Rs. 25377.36 p = Rs. 342594.28
j = 17 Interest = Rs. 27407.54 p = Rs. 370001.81
j = 18 Interest = Rs. 29600.14 p = Rs. 399601.97
j = 19 Interest = Rs. 31968.16 p = Rs. 431570.12
j = 20 Interest = Rs. 34525.61 p = Rs. 466095.75
j = 21 Interest = Rs. 37287.66 p = Rs. 503383.41
j = 22 Interest = Rs. 40270.67 p = Rs. 543654.06
j = 23 Interest = Rs. 43492.32 p = Rs. 587146.38
j = 24 Interest = Rs. 46971.71 p = Rs. 634118.06
j = 25 Interest = Rs. 50729.45 p = Rs. 684847.50

Principle : Rs. 100000.00


Rate of interest : 8.00
Number of years : 25
Compound Interest : Rs. 50729.45
Amount on maturity : Rs. 684847.50

- 24 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 16
Date :- - -2023 */

/* OBJECTIVE: Write a program to count even, odd, positive and


negative number entered by keyboard (Use of ternary
operator) */

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()

{
int n, no, rem, even_count=0, odd_count=0, neg_count=0, pos_count=0, i =0;

clrscr(); fflush(stdin);

printf("\n\t How many numbers=? " );


scanf("%d", &n);

for(i=1;i<=n;i++)
{
printf("\tNumber=");
scanf("%d", &no);
rem=no%2;
(rem==0)?(even_count++):(odd_count++);
(no!=abs(no))?(neg_count++):(pos_count++);
}

printf("\n\tNumber of EVEN numbers\t:%d", even_count);


printf("\n\tNumber of ODD numbers\t:%d", odd_count);
printf("\n\tNumber of POSITIVE numbers\t:%d", pos_count);
printf("\n\tNumber of NEGATIVE numbers\t:%d", neg_count);

getch(); return 0;

- 25 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

/*OUTPUT*/

How many numbers=? 10

Number = -54
Number = 658
Number = 35941
Number = 3548
Number = 5
Number = -489
Number = -32
Number = 65
Number = -48
Number = -35

Number of EVEN numbers : 5


Number of ODD numbers : 5
Number of POSITIVE numbers : 4
Number of NEGATIVE numbers : 6

Sign of Lecturer:-_______________

- 26 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 17
/* Date :- - -2023 */
/* OBJECTIVE:- Write a program to find factorial of a given number. */

//PROGRAM CODE: -
/* OBJECTIVE:- Write a program to find factorial of a given number. */
#include<stdio.h>
#include<conio.h>

void main()
{ float i, no, fact;
fflush(stdin); clrscr();
printf("\n\t Please enter an integer\t: ");
scanf("%f", &no);

fact = 1;
for(i=1; i<=no; i++)
{
fact = fact*i;
}

printf("\n\t The value of the %.0f! \t=\t %f\t\n", no, fact);

getch(); return 0;

} //main over //

/*OUTPUT*/

Please enter an integer : 5


The value of the 5! = 120.000000

Please enter an integer : 7


The value of the 7! = 5040.000000

Please enter an integer : 25


The value of the 25! = 15511211079246240700000000.000000

Please enter an integer 9


The value of the 9! = 362880.000000

Sign of Lecturer:-_______________

- 27 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :-18
/* Date :- - -2023 */
/* OBJECTIVE:- Write a program using UDF with an argument and a return value.
A programme to determine whether a number entered through key-
board is a prime number or not. */

//PROGRAM CODE: -
/* OBJECTIVE:- Write a program using UDF with an argument and a return value. */
/* This programme will determine whether a number entered through key-board is a
prime number or not.*/

#include<stdio.h>
#include<conio.h>

int Prime(int n);

int main()
{
int n, code;
fflush(stdin); clrscr();
printf("\n\t Enter a positive integer\t:\t");
scanf("%d", &n); // n is passed to the Prime() function
code = Prime(n); // The value returned from the
// function is assigned to code variable
if(code==1)
printf("\n\t %d is not a prime number\t\n", n);
else
printf("\n\t %d is a prime number\t\n", n);
getch(); return 0;
return 0;
}

// This is UDF with an argument and a return value.


// An integer sent and an integer is
// returned from the function ( UDF Prime() )

int Prime(int n)
{
/* Integer value is returned from function Prime() */
int i;

for(i=2; i <= n/2; ++i)


{
if(n%i == 0)
return 1;
}

return 0;
}

- 28 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/*OUTPUT*/

Enter a positive integer : 2


2 is a prime number

Enter a positive integer : 30


30 is not a prime number

Enter a positive integer : 221


221 is not a prime number

Enter a positive integer : 11111


11111 is not a prime number

Enter a positive integer : 37


37 is a prime number

Enter a positive integer : 13


13 is a prime number

Enter a positive integer : 19


19 is a prime number

Sign of Lecturer:-_______________

- 29 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :-19
/* Date :- - -2023 */

/* OBJECTIVE:-Write a program that utilizes a UDF two find prime


numbers between two integers entered through key-board. */

/* Write a program that utilizes a UDF two find prime numbers between
two integers entered through key-board. */
/*This programme will demonstrate use of functions in C*/
# include <stdio.h>
# include <conio.h>

void main( )
{ long n1, n2, i;
double prime(long), p;
clrscr( ); fflush (stdin);

printf ("\n\t Primes between which two numbers?\t:\t");


scanf ("%ld%ld", &n1, &n2);
printf("\n\tPrime numbers between %ld and %ld are \t:\t\n", n1, n2);

for(i=n1; i<=n2; i++)


{ p=prime(i);
if(p!=0)
printf("\t %.0lf", p);
}
getch( );
}

/* UDF prime() with one argument and a return value */


double prime(long k)
{ long m, j, rem;
m =(k+1)/2;
for(j=2; j<=m; j++)
{ rem=k%j;
if(rem == 0)break;
}
if(rem != 0)
{ return k; }
else
{ return 0; }
}

/*OUTPUT*/

- 30 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Primes between which two numbers? : 101 1000

Prime numbers between 101 and 1000 are :


101 103 107 109 113 127 131 137 139
149 151 157 163 167 173 179 181 191 193
197 199 211 223 227 229 233 239 241 251
257 263 269 271 277 281 283 293 307 311
313 317 331 337 347 349 353 359 367 373
379 383 389 397 401 409 419 421 431 433
439 443 449 457 461 463 467 479 487 491
499 503 509 521 523 541 547 557 563 569
571 577 587 593 599 601 607 613 617 619
631 641 643 647 653 659 661 673 677 683
691 701 709 719 727 733 739 743 751 757
761 769 773 787 797 809 811 821 823 827
829 839 853 857 859 863 877 881 883 887
907 911 919 929 937 941 947 953 967 971
977 983 991 997

Sign of Lecturer:-_______________

- 31 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 20
/* Date :- - -2023 */
/* OBJECTIVE:-Write a program to solve the equation by N-R method. (Use of
preprocessor) */

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define EPSLON .0000001
#define n 100
#define f(x) 3*x-exp(x)
#define fd(x) 3-exp(x)
// #define f(x) x*x*x-3*x*x+7*x-8
// root=1.67411
// #define fd(x) 3*x*x-6*x+7
void main()
{int count;
float x0, xn, fx, fdx;
clrscr(); fflush(stdin);

printf("\n\n\t Please enter x0 \t : \t");


scanf("%f", &x0);
count=1;
while(1)
{
fx=f(x0);
fdx=fd(x0);
xn=x0-fx/fdx;

if(fabs((xn-x0)/xn)<EPSLON||count > n)
{ break; }
else
{ x0=xn; }
count=count+1;
}

if(count>n)
{ printf("\n\t Divergent solution!\n"); }
else
{ printf("\n\t Root \t = \t %f", xn);}
getch(); return 0;

} // main over

- 32 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/*OUTPUT*/

Please enter x0 : 2
Root=1.512135

Please enter x0 : 3
Root=1.512135

Please enter x0 : 4
Root=1.512135

Please enter x0 : 5
Root=1.512135

Please enter x0 : 0
Root=0.619061

Please enter x0 : 10
Root=-0.000000

Please enter x0 : 25
Root=-NAN

Please enter x0 : 67
Divergent solution!

Sign of Lecturer:-_______________

- 33 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :-21
/* Date :- - -2023 */
/* OBJECTIVE:-Write a program to find value of the determinant of 2X2 and 3X3
matrices. */

/* OBJECTIVE:- Write a program to find value of the determinant of


2X2 matrices. */
#include<stdio.h>
#include<conio.h>
void main()
{ float a, b , c, d, det;

clrscr(); fflush(stdin);
printf("\n\t Please enter the 2x2 matrix\t:\t" );
printf("\n***************Input****************\n");
printf("\n\t a=?\t:\t");
scanf("%f", &a);

printf("\n\t b=?\t:\t");
scanf("%f", &b);

printf("\n\t c=?\t:\t");
scanf("%f", &c);

printf("\n\t d=?\t:\t");
scanf("%f", &d);

printf("\n***************Output****************\n");
printf("\n*****************Matrix A*************\n");

printf("\t %f\t%f\t\n", a, b);


printf("\t %f \t %f\t\n", c, d);

det = a*d -b*c;

printf("\n********* Determinant of the 2x2 Matrix A is ********\n");


printf("\n\t Determinant of the Matrix A \t = \t %f", det);
getch(); return 0;
}

- 34 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/*OUTPUT*/

Please enter the 2x2 matrix :


***************Input****************

a=? : 16

b=? : 9

c=? : 6

d=? : 4

***************Output****************

*****************Matrix A************

16.000000 9.000000
6.000000 4.000000

***************** Determinant of the 2x2 Matrix A is


*************

Determinant of the Matrix A = 10.000000

Sign of Lecturer:-_______________

- 35 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/* Date :- - -2023 */

/* OBJECTIVE:- A program to find transpose, diagonal and determinant


of given 3x3 matrix entered through keyboard. */

#include <stdio.h>
#include <conio.h>
void main( )
{ int a[3][3], det, i, j;
clrscr( ); fflush(stdin);

printf("***************Input****************\n");

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


{ for(j=0; j<=2; j++)
{ printf("\t A[%d, %d] = ", i, j );
scanf("%d", &a[i][j] ); }
}

det = a[0][0]*((a[1][1]*a[2][2]) - (a[2][1]*a[1][2]))


-a[0][1]*(a[1][0]*a[2][2] - a[2][0]*a[1][2])
+ a[0][2]*(a[1][0]*a[2][1] - a[2][0]*a[1][1]);

printf("\n******You entered the 3x3 Matrix*******\n A= ");


for( i=0; i<=2; i++)
{ for (j=0; j <=2; j++ )
{ printf("\t %d", a[i][j] ); }
printf("\n"); }

printf("\n****Transpose of the matrix A ****\nTran(A)=\n");


for( i=0; i<=2; i++)
{ for (j=0; j <=2; j++ )
{ printf("\t %d", a[j][i] ); }
printf("\n"); }

printf("\n****Diagonal of the matrix A ****\nDiag(A)=");


for( i=0; i<=2; i++)
{ for (j=0; j <=2; j++ )
{ if(i==j) printf("\t %d", a[j][i] ); }
}

printf("\n\n\t Thederminant of the matrix A \t = \t %d ", det);


getch( );
}

/*OUTPUT*/

- 36 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

A[0, 0] = 1
A[0, 1] = 5
A[0, 2] = 9
A[1, 0] = 7
A[1, 1] = 8
A[1, 2] = 6
A[2, 0] = 4
A[2, 1] = 3
A[2, 2] = 2

******You entered the 3x3 Matrix*******


A= 1 5 9
7 8 6
4 3 2

****Transpose of the matrix A ****


Tran(A)=
1 7 4
5 8 3
9 6 2

****Diagonal of the matrix A ****

Diag(A)= 1 8 2

The determinant of the matrix A = -51

Sign of Lecturer:-_______________

- 37 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 22
/* Date :- - -2023 */
/* OBJECTIVE:- Write a program to find inverse of a 2X2 matrix.*/

/* OBJECTIVE:- Write a program to find inverse of a 2X2 matrix.*/


#include<stdio.h>
#include<conio.h>
void main()
{ float a, b , c, d, det;

clrscr(); fflush(stdin);
printf("\n\t Please enter the 2x2 matrix\t:\t" );
printf("\n***************Input****************\n");
printf("\n\ta=?\t:\t");
scanf("%f", &a);

printf("\n\t b=?\t:\t");
scanf("%f", &b);

printf("\n\t c=?\t:\t");
scanf("%f", &c);

printf("\n\t d=?\t:\t");
scanf("%f", &d);

printf("\n***************Output****************\n");
printf("\n*****************Matrix A*************\n");

printf("%f\t %f\t\n", a, b);


printf("%f\t %f\t\n", c, d);

det = a*d -b*c;

a = d/det; b = -b/det; c = -c/det; d = a/det;


printf("\n\n*********** Inverse OF THE Matrix A is ********\n\n");
printf("\n\t Inverse of A = \n\t\t %f\t%f\n\t\t%f\t %f", a, b, c, d );
getch(); return 0;
}

- 38 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/*OUTPUT*/

Please enter the 2x2 matrix :


***************Input****************

a=? : 16

b=? : 9

c=? : 6

d=? : 4

***************Output******************

*****************Matrix A**************
16.000000 9.000000
6.000000 4.000000

***** Inverse OF THE Matrix A is *****

Inverse of A =

0.400000 -0.900000
-0.600000 0.040000

Sign of Lecturer:-_______________

- 39 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :- 23
/* Date :- - -2023 */

/* OBJECTIVE:- Write a program to find trace of a 3X3 matrix entered


through key-board. */
/* OBJECTIVE:- Write a program to find traceof a 3X3 matrix entered
through key-board. */
#include<stdio.h>
#include<conio.h>
void main()
{ float sum = 0, a[3][3];
int i, j, k;
clrscr(); fflush(stdin);
printf("\n\t Please enter the 3x3 matrix\t:\t" );
printf("\n***************Input****************\n");

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


{
for(j=0; j<=2; j++)
{
printf("\t A[%d, %d] = ", i, j );
scanf("%f", &a[i][j] );
}
}

printf("\n***************Output*****************\n");
printf("\n*****************Matrix A*************\n");
for(i=0; i<=2; i++)
{
printf("\n");
for (j=0; j <=2; j++ )
{
printf("%f\t", a[i][j] );
}
}

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


{
for (j=0; j <=2; j++ )
{
if(i==j) sum = sum + a[i][j];
}
}
printf("\n\n***********TRACE OF THE Matrix A is **********\n");
printf("\n\t Trace of A = %f\t", sum );
getch(); return 0;
}

- 40 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
/*OUTPUT*/

Please enter the 3x3 matrix :

***************Input****************
A[0, 0] = 1
A[0, 1] = 2
A[0, 2] = 3
A[1, 0] = 4
A[1, 1] = 5
A[1, 2] = 6
A[2, 0] = 7
A[2, 1] = 8
A[2, 2] = 9

***************Output****************

*****************Matrix A*************

1.000000 2.000000 3.000000


4.000000 5.000000 6.000000
7.000000 8.000000 9.000000
*****************TRACE OF THE Matrix A is *************

Trace of A = 15.000000

Sign of Lecturer:-_______________

- 41 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

Practical no :-24
Date :- - -2023 */
/* OBJECTIVE:-Write a program to find the sum, deference, and multiplication of two
3X3 matrices entered through key-board.*/

/* OBJECTIVE:-(a)A program to add two 3x3 matrices


(b)A program to find the deference of two3x3 matrices
(c)A program to multiply two 3x3 matrices */

/* OBJECTIVE:- (a) A program to ADD TWO 3X3 MATRICES */


#include<stdio.h>
#include<conio.h>
void main()
{ float sum, a[3][3], b[3][3], c[3][3];
int i, j, k;
clrscr(); fflush(stdin);
printf("\n\t Please enter the 3x3 matrix\t:\t" );
printf("\n***************Input****************\n");
for (i=0; i<=2; i++ )
{
for(j=0; j<=2; j++)
{
printf("\t A[%d, %d] = ", i, j );
scanf("%f", &a[i][j] );
}
}
for (i=0; i<=2; i++ )
{
for(j=0; j<=2; j++)
{
printf("\t B[%d, %d] = ", i, j );
scanf("%f", &b[i][j] );
}
}
printf("\n***************Output****************\n");
printf("\n*****************Matrix A*************\n");
for(i=0; i<=2; i++)
{
printf("\n");
for (j=0; j <=2; j++ )
{
printf("%f\t", a[i][j] );
}
}

printf("\n***************Matrix B****************\n");

- 42 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
for(i=0; i<=2; i++)
{
printf("\n");
for (j=0; j <=2; j++ )
{
printf("%f\t", b[i][j] );
}
}

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


{
for (j=0; j <=2; j++ )
{
c[i][j] = a[i][j]+b[i][j];
}
}

printf("\n*****************Matrix A+B*************\n");
for(i=0; i<=2; i++)
{
printf("\n");
for (j=0; j <=2; j++ )
{
printf("%f\t", c[i][j] );
}
}
getch(); return 0;

/* Please enter the 3x3 matrix :


***************Input****************
A[0, 0] = 1
A[0, 1] = 2
A[0, 2] = 3
A[1, 0] = 4
A[1, 1] = 5
A[1, 2] = 6
A[2, 0] = 7
A[2, 1] = 8
A[2, 2] = 9
B[0, 0] = 9
B[0, 1] = 8
B[0, 2] = 7
B[1, 0] = 6
B[1, 1] = 5
B[1, 2] = 4
B[2, 0] = 3
B[2, 1] = 2
B[2, 2] = 1

***************Output****************

- 43 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

*****************Matrix A*************

1.000000 2.000000 3.000000


4.000000 5.000000 6.000000
7.000000 8.000000 9.000000

***************Matrix B****************

9.000000 8.000000 7.000000


6.000000 5.000000 4.000000
3.000000 2.000000 1.000000
*****************Matrix A+B*************

10.000000 10.000000 10.000000


10.000000 10.000000 10.000000
10.000000 10.000000 10.000000

/* OBJECTIVE:- (b) A program to find the deference of TWO 3X3


MATRICES */

- 44 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
#include<stdio.h>
#include<conio.h>
void main()
{ float sum, a[3][3], b[3][3], c[3][3];
int i, j, k;
clrscr(); fflush(stdin);
printf("\n\t Please enter the 3x3 matrix\t:\t" );
printf("\n***************Input****************\n");
for (i=0; i<=2; i++ )
{
for(j=0; j<=2; j++)
{
printf("\t A[%d, %d] = ", i, j );
scanf("%f", &a[i][j] );
}
}
for (i=0; i<=2; i++ )
{
for(j=0; j<=2; j++)
{
printf("\t B[%d, %d] = ", i, j );
scanf("%f", &b[i][j] );
}
}
printf("\n***************Output****************\n");
printf("\n*****************Matrix A*************\n");
for(i=0; i<=2; i++)
{
printf("\n");
for (j=0; j <=2; j++ )
{
printf("%f\t", a[i][j] );
}
}
printf("\n***************Matrix B****************\n");
for(i=0; i<=2; i++)
{
printf("\n");
for (j=0; j <=2; j++ )
{
printf("%f\t", b[i][j] );
}
}

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


{
for (j=0; j <=2; j++ )
{
c[i][j] = a[i][j]-b[i][j];
}
}

- 45 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.

printf("\n*****************Matrix A-B*************\n");
for(i=0; i<=2; i++)
{
printf("\n");
for (j=0; j <=2; j++ )
{
printf("%f\t", c[i][j] );
}
}
getch(); return 0;

****************Input****************
A[0, 0] = 87
A[0, 1] = 45
A[0, 2] = 32
A[1, 0] = 74
A[1, 1] = 98
A[1, 2] = 29
A[2, 0] = 61
A[2, 1] = 93
A[2, 2] = 92
B[0, 0] = 9
B[0, 1] = 3
B[0, 2] = 6
B[1, 0] = 2
B[1, 1] = 7
B[1, 2] = 8
B[2, 0] = 2
B[2, 1] = 9
B[2, 2] = 5

*****************Matrix A-B*************

78.000000 42.000000 26.000000


72.000000 91.000000 21.000000
59.000000 84.000000 87.000000

/* OBJECTIVE:-(c) A program to MULTIPLY TWO 3X3 MATRICES */


#include<stdio.h>
#include<conio.h>
void main()
{ float sum, a[3][3], b[3][3], d[3][3];

- 46 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
int i, j, k; clrscr(); fflush(stdin);
printf("\n\t Please enter the 3x3 matrix\t:\t" );
printf("\n***************Input****************\n");
for (i=0; i<=2; i++ )
{
for(j=0; j<=2; j++)
{
printf("\t A[%d, %d] = ", i, j );
scanf("%f", &a[i][j] );
}
}
for (i=0; i<=2; i++ )
{
for(j=0; j<=2; j++)
{
printf("\t B[%d, %d] = ", i, j );
scanf("%f", &b[i][j] );
}
}

printf("\n***************Output****************\n");

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


{
for (j=0; j <=2; j++ )
{
sum=0;
for(k=0;k<=2;k++)
{
sum = sum + a[i][k]*b[k][j];
}
d[i][j] = sum;
}
}

printf("\n*****************Matrix A*B*************\n");
for(i=0; i<=2; i++)
{
printf("\n");
for (j=0; j <=2; j++ )
{
printf("%f\t", d[i][j] );
}
}
getch(); return 0;
}
/*OUTPUT*/

/* Please enter the 3x3 matrix :

- 47 –
Core Practical: 5 Problem Solving using Programming, Dept of Mathematics, Virani Sc. College, Rajkot.
***************Input****************
A[0, 0] = 1
A[0, 1] = 2
A[0, 2] = 3
A[1, 0] = 4
A[1, 1] = 5
A[1, 2] = 6
A[2, 0] = 7
A[2, 1] = 8
A[2, 2] = 9
B[0, 0] = 9
B[0, 1] = 8
B[0, 2] = 7
B[1, 0] = 6
B[1, 1] = 5
B[1, 2] = 4
B[2, 0] = 3
B[2, 1] = 2
B[2, 2] = 1

***************Output****************

*****************Matrix A*************

1.000000 2.000000 3.000000


4.000000 5.000000 6.000000
7.000000 8.000000 9.000000

***************Matrix B****************

9.000000 8.000000 7.000000


6.000000 5.000000 4.000000
3.000000 2.000000 1.000000

*****************Matrix A*B*************

30.000000 24.000000 18.000000


84.000000 69.000000 54.000000
138.000000 114.000000 90.000000 */

Sign of Lecturer:-_______________

- 48 –

You might also like