Skip to main content

Posts

Showing posts from August, 2022

Search This Blog

matrix multiplication in c using functions and pointers

 #include <stdio.h> #define ROWS 3 #define COLS 3 void matrixMultiply(int *mat1, int *mat2, int *result, int rows1, int cols1, int cols2) {     int i, j, k;     // Multiplying matrices     for (i = 0; i < rows1; i++) {         for (j = 0; j < cols2; j++) {             *(result + i * cols2 + j) = 0;             for (k = 0; k < cols1; k++) {                 *(result + i * cols2 + j) += *(mat1 + i * cols1 + k) * *(mat2 + k * cols2 + j);             }         }     } } void displayMatrix(int *mat, int rows, int cols) {     int i, j;     // Displaying matrix     for (i = 0; i < rows; i++) {         for (j = 0; j < cols; j++) {             printf("%d\t", *(mat + i * cols + j));         }         printf("\n");     } } int main() {     int mat1[ROWS][COLS] = {{1, 2, 3},                             {4, 5, 6},                             {7, 8, 9}};     int mat2[ROWS][COLS] = {{9, 8, 7},                             {6, 5, 4},                             {

C Program to Check Armstrong Number

Before going to write the c program to check whether the number is Armstrong or not, let's understand what is Armstrong number. Armstrong number  is  a number that is equal to the sum of cubes of its digits . For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers. Let's try to understand why  153  is an Armstrong number. 153 = (1*1*1)+(5*5*5)+(3*3*3)   where:   (1*1*1)=1   (5*5*5)=125   (3*3*3)=27   So:   1+125+27=153   Example of second no  371 = (3*3*3)+(7*7*7)+(1*1*1)   where:   (3*3*3)=27   (7*7*7)=343   (1*1*1)=1   So:   27+343+1=371   This program computes all Armstrong numbers in the range of ! 0 and 999. An Armstrong number is a number such that the sum ! of its digits raised to the third power is equal to the number ! itself. For example, 371 is an Armstrong number, since ! 3**3 + 7**3 + 1**3 = 371.  #include<stdio.h> #include<conio.h> int main(void){ int a,a2,a3,a4,b,b2,b3,c,i,j; printf("Enter any number :"); scanf("%d&quo

Contact Form

Name

Email *

Message *