Sunday, August 1, 2021

C Program to perform Matrix Subtraction

Matrix Subtraction

We will write a C program to perform matrix subtraction operation.

Key points for subtraction of matrices

  • Two matrices should be of same order (number of rows=number of columns).
  • Subtract the corresponding element of matrices.

Example: Subtraction of matrix of order 3 * 3

Subtraction of Matrix (A-B) is as under:

A - B = C


C Program to perform Matrix Subtraction

Program Code:

#include<stdio.h>
int main()
{
 int A[3][3],B[3][3],C[3][3],i, j;
 //Loops for Reading A matrix
 for ( i = 0; i < 3; i++ ) //related to row
 {
   for ( j = 0; j < 3; j++ ) //related to column
   {
     printf("Matrix A[%d][%d]:",i,j);
     scanf("%d", &A[i][j]) ;
   }   
 }
 //Loops for Reading B matrix
 for ( i = 0; i < 3; i++ ) //related to row
 {
   for ( j = 0; j < 3; j++ ) //related to column
   {
     printf("Matrix B[%d][%d]:",i,j);
     scanf("%d", &B[i][j]) ;
   }   
 }
 printf("Matrix A is as under: \n") ;
 /* Print Matrix A, B */
 for ( i = 0; i < 3; i++ ) //related to row
 {
   for ( j = 0; j < 3; j++ ) //related to column
   {
     printf(" %d\t ",A[i][j] );
   }
   printf("\n");
 }
 printf("Matrix B is as under: \n") ;
 for ( i = 0; i < 3; i++ ) //related to row
 {
   for ( j = 0; j < 3; j++ ) //related to column
   {
     printf(" %d\t ",B[i][j] );
   }
   printf("\n");
 }
 printf("Matrix Subtraction is as under: \n");
 for ( i = 0; i < 3; i++ ) //related to row
 {
   for ( j = 0; j < 3; j++ ) //related to column
   {
     printf(" %d\t ",A[i][j] - B[i][j] );
   }
   printf("\n");
 }
 return 0;
}

Program Output:

Matrix A[0][0]:4
Matrix A[0][1]:5
Matrix A[0][2]:6
Matrix A[1][0]:7
Matrix A[1][1]:8
Matrix A[1][2]:9
Matrix A[2][0]:10
Matrix A[2][1]:11
Matrix A[2][2]:12
Matrix B[0][0]:1
Matrix B[0][1]:3
Matrix B[0][2]:2
Matrix B[1][0]:5
Matrix B[1][1]:4
Matrix B[1][2]:3
Matrix B[2][0]:2
Matrix B[2][1]:3
Matrix B[2][2]:6
Matrix A is as under:
 4        5       6
 7        8       9
 10       11      12
Matrix B is as under:
 1        3       2
 5        4       3
 2        3       6
Matrix Subtraction is as under:
 3        2       4
 2        4       6
 8        8       6

* * * * *

* * * * *








Saturday, May 8, 2021

Flowchart to input 5 numbers from user and to print odd or even number.

Flowchart to read 5 numbers from user and to print odd or even number.

[ This article is posted for a request received from the visitor of the blog.]

Following flowchart will input 5 numbers one by one from the user and prints whether it is Odd or Even number.

Flowchart to input 5 numbers from user and to print odd or even number.
Fig. Flowchart to input 5 numbers and to print Odd or Even

Output of the flowchart:

1 is odd number
2 is even number
3 is odd number
4 is even number
5 is odd number
----Run complete.  35 symbols evaluated.----






Monday, February 15, 2021

C program to find square of given number without an argument and a return value

C Programming => Functions

C program to find square of given number using function concept. This program demonstrate use of function without an argument and a return value.

Program code

#include<stdio.h>
int square(); //function prototype declaration.
int number; //use of global variable

int main()
{
  int answer;
  answer = square(); //Call function.
  printf("Square of %d is %d.", number, answer);
  return 0;
}

//User defined function to find square()
int square()
{
  printf("Enter your number:");
  scanf("%d", &number);
  //return answer to main function
  return(number*number);
}

Output of the program

Enter your number:5
Square of 5 is 25.





Monday, January 18, 2021

Flowchart to check Odd or Even Number between 1 to 10

Flowchart to check odd or even number between 1 to 10 numbers

Flowchart to check Odd or Even Number between 1 to 10



Output of the flowchart:

1 is odd

2 is even

3 is odd

4 is even

5 is odd

6 is even

7 is odd

8 is even

9 is odd

10 is even

----Run complete.  55 symbols evaluated.----


* * * * *



This flowchart is generated using Raptor tool. Read more about RAPTOR here. 


Top 10 Flowcharts Examples

You may like to visit following top 10 flowchart examples.




Thursday, December 31, 2020

Sum of all numbers between 100 and 200 using do while loop

C Program to find sum of all numbers between 100 and 200 using do while loop.

Expected output is sum of 100 + 101 + 102 + .. + 199 + 200.


Program Code

#include<stdio.h>
int main()
{
  int number=100, sum=0;
  
  do{
    sum = sum + number;
    number = number + 1;
  }while(number<=200);

  printf("Sum of all numbers between 100 to 200:"); 
  printf(" %d", sum);

  return 0;
}

Output of the program

Sum of all numbers between 100 to 200: 15150 

* * * * *


< Back to Looping Page >

< Back to Home >


Wednesday, December 30, 2020

C program to print Z to A using for loop

C Program to print Z to A using for loop


Program Code 1:

#include<stdio.h>
int main()
{
  int i;
  for(i='Z'; i>='A'; i--)
    printf("%c", i);
  
  return 0;
}

Output of the program:

ZYXWVUTSRQPONMLKJIHGFEDCBA

* * * * *

Same program can also be generated using following code.

Program Code 2:

#include<stdio.h>
int main()
{
    int i;
    //90 is ASCII value of Z
    for(i=90; i>=65; i--)
        printf("%c", i);
    
    return 0;
}

Output of the program:

ZYXWVUTSRQPONMLKJIHGFEDCBA

* * * * *



Friday, September 11, 2020

Flowchart to convert uppercase letters into lowercase

 RAPTOR Flowchart to convert Uppercase letters into Lowercase letters

Fig.: Flowchart to convert Uppercase letters into Lowercase letters

Note: 

  • ASCII value of 'A' is 65, and 'a' is 97.
  • If we add 32 into 65, we get 97 which is ASCII value of 'a'. 
  • Hence we add 32 into 'chr' variable in the flowchart. This process we repeat up to 'Z' in the flowchart using loop.

You may like to read C Program to convert uppercase letters into  Lowercase letters here. 


Check more operation flowchart on following link: