Professional Documents
Culture Documents
Digital Assignment -1
Code:
#include <stdio.h>
#include <math.h>
int main() {
int num, orgNum, rem, result = 0, n = 0;
printf("Enter a number: ");
scanf("%d", &num);
orgNum = num;
while (orgNum != 0) {
orgNum /= 10;
++n;
}
orgNum = num;
while (orgNum != 0) {
rem = orgNum % 10;
result += pow(rem, n);
orgNum /= 10;
}
if (result == num) {
printf("%d = %d ",result,num);
printf("\n so %d is an Armstrong number.\n", num);
} else {
printf("%d != %d",result,num);
Name: Bhanesh Gopal K Reg no: 21BEC2149
return 0;
}
Screenshots of Code:
Screenshot of output:
Name: Bhanesh Gopal K Reg no: 21BEC2149
2. Write a C program to multiply a 2 × 3 matrix with a 3 × 4 matrix and then multiply the
resultant matrix with a 4 × 2 matrix. Define matrix elements through user input. Display
the output in the form a matrix.
Code:
#include <stdio.h>
int main() {
int mat1[2][3], mat2[3][4], mat3[4][2], res1[2][4], res2[2][2];
printf("Third matrix:\n");
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 2; ++j) {
printf("%d ", mat3[i][j]);
}
printf("\n");
}
printf("\n");
}
return 0;
}
Screenshot of Code:
Name: Bhanesh Gopal K Reg no: 21BEC2149
Name: Bhanesh Gopal K Reg no: 21BEC2149
Screenshot of output: