Computer Science, asked by jayshreerathod1, 1 year ago

1. Write a program to print the month of year using switch cases
2. Write a program for multiplication of two 3x3 matrices.

Answers

Answered by franktheruler
6

Answer:

Write a program to print the month of year using switch cases:

void main ( )

{

char ch ;

printf ( " enter the value of ch  " ) ;

scanf ( " % c " , & ch );

switch (ch)

{

case 1:

printf ( " JANUARY " ) ;

break ;

case 2:

printf ( " FEBRUARY " ) ;

break ;

case 3:

printf ( " MARCH " ) ;

break ;

case 4:

printf ( "APRIL " )  ;

break ;

case 5:

printf ( " MAY " ) ;

break ;

case 6:

printf ( "JUNE " ) ;

break ;

case 7:

printf ( "JULY " ) ;

break ;

case 8:

printf ( " AUGUST " ) ;

break ;

case 9:

printf ( " SEPTEMBER " ) ;

break ;

case 10:

printf ( " OCTOBER " ) ;

break ;

case 11:

printf ( " NOVEMBER " ) ;

break ;

case 12:

printf ( " DECEMBER " ) ;

break;

default :

printf ( " EXIT " ) ;

}

}

Write a program for multiplication of two 3x3 matrices.

#include<stdio.h>

int main() {

  int a [ 100 ] [ 100 ], b [ 100 ] [ 100 ], c [ 100 ] [ 100 ], p, q, r ;

  int sum = 0;

 

  printf ( " Enter First Matrix : n " );

  for ( p = 0 ; p < 3 ; q ++ ) {

     for ( q = 0 ; q < 3 ; q ++ ) {

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

     }

  }

 

  printf ( " Enter Second Matrix:n " ) ;

  for ( p = 0 ; p < 3 ; p ++ ) {

     for ( q = 0 ; q < 3 ; q ++ ) {

        scanf ( " % d " , & b [ p ] [ q ] ) ;

     }

  }

 

  printf ( " The First Matrix is: " ) ;

  for ( p = 0 ; p < 3 ; p ++ ) {

     for ( q = 0 ; q < 3 ; q ++ ) {

        printf ( " %d " , a[ p ] [ q ] ) ;

     }

     printf ("\n") ;

  }

 

  printf("The Second Matrix is : \n");

  for ( p = 0; p < 3; p++) {

     for ( q = 0 ; q < 3 ; q++ ) {

        printf ( " %d " , b [ p ] [ q ]);

     }

     printf("\n");

  }

 

  //Multiplication Logic

  for ( p = 0 ; p <= 2 ; p ++ ) {

     for (q = 0 ; q <= 2 ; q++ ) {

        sum = 0;

        for ( r = 0; r <= 2; r ++ ) {

           sum = sum + a [ p ] [ r ] * b [ r ] [ q ] ;

        }

        c [ p ][ q ] = sum;

     }

  }

 

  printf("\nMultiplication Of Two Matrices : \n");

  for ( p = 0; p < 3; p++) {

     for ( q = 0; q < 3; q++) {

        printf ( " %d " , c[ p ] [  q ] ) ;

     }

     printf("\n");

  }

 

  return (0);

}

Similar questions