Skip to main content

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)); ...

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.

  1. 153 = (1*1*1)+(5*5*5)+(3*3*3)  
  2. where:  
  3. (1*1*1)=1  
  4. (5*5*5)=125  
  5. (3*3*3)=27  
  6. So:  
  7. 1+125+27=153  

Example of second no 


  1. 371 = (3*3*3)+(7*7*7)+(1*1*1)  
  2. where:  
  3. (3*3*3)=27  
  4. (7*7*7)=343  
  5. (1*1*1)=1  
  6. So:  
  7. 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.


  1.  #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",&a);

    a2=a/10;

    b=a%10;

    a3=a2/10;

    b2=a2%10;

    if((b*b*b)+(b2*b2*b2)+(a3*a3*a3)==a){

    printf("%d is an armstrong number",a);

    }

    else{

    printf("%d is not an armstrong number",a);

    }

    getch();

    }




Comments

Contact Form

Name

Email *

Message *