Showing posts with label 'c' program. Show all posts
Showing posts with label 'c' program. Show all posts

Saturday, February 13, 2021

How to write a program of Matrix Multiplication in 'C'

mathextention

   Write a C-program using  two dimensional  array given two matrix scan and print then show the two matrix sum and multiplication. 

Program of Matrix  Sum & Multiplication in 'C' 

#include<stdio.h>

main(){

int a[20][20], b[20][20], d[20][20], e[20][20], i, j, n, m, k, m1, n1;

printf(" Enter the value of row m and column n = ");

scanf("%d %d", &m, &n);

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

for(j=0; j<n; j++){

printf(" Enter %d %d entris = ", i+1, j+1);

scanf("%d", &a[i][j]);

}

}

printf(" The matrix A = \n");

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

for(j=0; j<n; j++){

printf("  %d ", a[i][j]);

}

printf("\n");

}

printf(" Enter the value of second matrix row m1 and column n1 = ");

scanf("%d %d", &m1, &n1);

for(i=0; i<m1; i++){

for(j=0; j<n1; j++){

printf(" Enter %d %d entris = ", i+1, j+1);

scanf("%d", &b[i][j]);

}

}

printf(" The matrix B = \n");

for(i=0; i<m1; i++){

for(j=0; j<n1; j++){

printf("  %d ", b[i][j]);

}

printf("\n");

}

if(m==m1 && n==n1){

printf(" Sum of two matrix\n");

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

for(j=0; j<n; j++){

e[i][j] = a[i][j] + b[i][j];

printf("  %d ", e[i][j]);

}

printf("\n");

}

    }

    else

    printf(" Matrix addtion not possible\n");

if(n==m1){

printf(" Product of two matrix\n");

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

for(j=0; j<n; j++){

d[i][j]=0;

for(k=0; k<n; k++){

d[i][j] = d[i][j]+ a[i][k] * b[k][j];

}

printf("  %d ", d[i][j]);

}

printf("\n");

}

printf("\n");

  }

  else

  printf(" Matrix multiplaction not possible");

}

Friday, February 12, 2021

Minimum of 'n' number program in 'C'

mathextention

     Minimum of 'n' number program in 'C'


#include<stdio.h>

main(){

int a[120], n, minindex, i; 

printf("Enter n =");

scanf("%d", &n);

printf("Enter the number ");

for(i=0; i<n; i++){

scanf("%d", &a[i]);

}

minindex = 0;

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

if(a[i] < a[ minindex])

minindex = i;

}

printf("Minimun of number = %d", a[minindex]);

Thursday, February 11, 2021

USEING SWITCH OPERATION IN "C" TO CREATE SIMPLE CALCULATOR

mathextention

   USEING SWITCH OPERATION IN "C" TO          CREATE SIMPLE CALCULATOR

#include<stdio.h>

main(){

char a;

float m, n, p;

printf("Enter the operator we want to operated = ");

scanf("%c", &a);

printf("Enter the m and n numbers ");

scanf("%f  %f", &m, &n);

switch(a){

case '+':

p = m + n;

printf("The sum of %f and %f numbers = %f", m, n, p);

break;

case '-':

     p = m-n;

printf("The different of %f and %f numbers = %f", m, n, p);

break;

case '*':

p = m*n;

printf("The product of %f and %f numbers = %f", m, n, p);

break;

case '/':

if(n !=0){

p = m/n;

         printf("The division of %f and %f numbers = %f", m, n, p);

}

else

printf("The division of %f and %f numbers not define ", m, n);

break;

defalt :

printf(" Not valid operation")

}

}