KEMBAR78
CA Cover Page (Programming Fundamentals | PDF | Mathematical Objects | Matrix Theory
0% found this document useful (0 votes)
6 views9 pages

CA Cover Page (Programming Fundamentals

The document contains a series of C programming exercises for a BCA course at Maulana Abul Kalam Azad University of Technology. It includes code examples for matrix multiplication, checking for perfect numbers, matrix addition, finding the GCD of two numbers, and calculating the factorial of a number using recursion. Each question is followed by its respective code implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

CA Cover Page (Programming Fundamentals

The document contains a series of C programming exercises for a BCA course at Maulana Abul Kalam Azad University of Technology. It includes code examples for matrix multiplication, checking for perfect numbers, matrix addition, finding the GCD of two numbers, and calculating the factorial of a number using recursion. Each question is followed by its respective code implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Maulana Abul Kalam Azad

University Of Technology

MAKAUT WB

NAME: ABHIJIT SINGHA


DEPARTMENT: Department of IT
COURSE: BCA
SUBJECT: PROGRAMMING FUNDAMENTALS
PRACTICAL
SEMESTER: 1st SEMESTER
CET: 1
REG. NO: 223001010633
ROLL NO: 30001222032
PCA: II

Question 1: Write a C Program to perform the


multiplication of two matrices.

Code:- #include<stdio.h>
#include<conio.h>
int main()
{
int mat1[3][3], mat2[3][3], mat3[3][3], sum=0, i, j, k;
printf("Enter first 3*3 matrix element: ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
scanf("%d", &mat1[i][j]);
}
printf("Enter second 3*3 matrix element: ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
scanf("%d", &mat2[i][j]);
}
printf("\nMultiplying two matrices...");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
sum=0;
for(k=0; k<3; k++)
sum = sum + mat1[i][k] * mat2[k][j];
mat3[i][j] = sum;
}
}
printf("\nMultiplication result of the two given Matrix is: \n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
printf("%d\t", mat3[i][j]);
printf("\n");
}
getch();
return 0;
}

Output:-
Question 2:- Write a C Program to check whether a
number is Perfect or not using function.

Code:- #include <stdio.h>


int main()
{
int i, num, sum = 0;
/* Input a number from user */
printf("Enter any number to check perfect number: ");
scanf("%d", &num);
for(i = 1; i <= num / 2; i++)
{
if(num%i == 0)
{
sum += i;
}
}
if(sum == num && num > 0)
{
printf("%d is PERFECT NUMBER", num);
}
else
{
printf("%d is NOT PERFECT NUMBER", num);
}
return 0;
}

Output:-

Question 3:- Write a C Program to perform the addition of


two matrices.
Code:-
#include <stdio.h>
int main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];

printf("Enter the number of rows and columns of matrix\n");


scanf("%d%d", &m, &n);
printf("Enter the elements of first matrix\n");

for (c = 0; c < m; c++)


for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);

printf("Enter the elements of second matrix\n");

for (c = 0; c < m; c++)


for (d = 0 ; d < n; d++)
scanf("%d", &second[c][d]);
printf("Sum of entered matrices:-\n");

for (c = 0; c < m; c++) {


for (d = 0 ; d < n; d++) {
sum[c][d] = first[c][d] + second[c][d];
printf("%d\t", sum[c][d]);
}
printf("\n");
}

return 0;
}

Output:-
Question:- 4 Write a C Program to find the GCD
of two numbers using function.
Code:-
#include<stdio.h>
int gcd(int a, int b);

int main()
{
int num1, num2;

printf("Enter two numbers : ");


scanf("%d %d",&num1, &num2);

int result = gcd(num1, num2);


printf("The GCD of %d and %d = %d", num1, num2, result);

return 0;
}

// User-defined function to find gcd of two numbers


int gcd(int a, int b)
{
int hcf;
for(int i=1; i<=a && i<=b; i++)
{
if(a%i==0 && b%i==0)
{
hcf = i;
}
}
return hcf;
}
Output:-

Question:- 5 Write a C Program to find the factorial of


a number using recursion.
Code:-
#include<stdio.h>
int find_factorial(int);
int main()
{
int num, fact;
//Ask user for the input and store it in num
printf("\nEnter any integer number:");
scanf("%d",&num);

//Calling our user defined function


fact =find_factorial(num);

//Displaying factorial of input number


printf("\nfactorial of %d is: %d",num, fact);
return 0;
}
int find_factorial(int n)
{
//Factorial of 0 is 1
if(n==0)
return(1);

//Function calling itself: recursion


return(n*find_factorial(n-1));
}

Output:-

You might also like