Thursday, March 5, 2020

Files In C Language

File : A file is a container in computer storage devices used for storing data.
Types of Files
1.Text files
2.Binary files

Text files
Text files are the normal .txt files. You can easily create text files using any simple text editors such as Notepad.

They take minimum effort to maintain, are easily readable, and provide the least security and takes bigger storage

space.

Binary files
Binary files are mostly the .bin files in your computer. Instead of storing data in plain text, they store it in the

binary form (0's and 1's). They can hold a higher amount of data, are not readable easily, and provides better

security than text files.

File Operations
In C, you can perform four major operations on files, either text or binary:
1.Creating a new file
2.Opening an existing file
3.Closing a file
4.Reading from and writing information to a file

Working with files
When working with files, you need to declare a pointer of type file. This declaration is needed for communication

between the file and the program.
Syntax : FILE *fptr;

Modes of opening a file
r    - open for reading
w   - open for writing
a   - open for append
r+  - open for both reading and writing
w+  - open for both reading and writing
a+   - open for both reading and appending

Predefined Functions in C Language
1.Creation of a new file (fopen with attributes as “a” or “a+” or “w” or “w++”)
2.Opening an existing file (fopen)
3.Reading from file (fscanf or fgetc)
4.Writing to a file (fprintf or fputs)
5.Moving to a specific location in a file (fseek, rewind)
6.Closing a file (fclose)

Opening a file - for creation and edit
Opening a file is performed using the fopen() function defined in the stdio.h header file.

The syntax for opening a file in standard I/O is:
ptr = fopen("fileopen","mode");

Ex:
fopen("D:\\test\\guru.txt","w");
Note :
If the file guru.txt doesn't exist in the location D:\test. The first function creates a new file named guru.txt and

opens it for writing as per the mode 'w'.

fopen("D:\\test\\guru.bin","rb");
Note:
Above function opens the existing file for reading in binary mode 'rb'. The reading mode only allows you to read

the file, you cannot write into the file.

Closing a File
The file (both text and binary) should be closed after reading/writing.

Closing a file is performed using the fclose() function.

fclose(fptr);
Here, fptr is a file pointer associated with the file to be closed.

Example 1: Write to a text file
#include <stdio.h>
#include <stdlib.h>
void  main()
{
   int num;
   FILE *fptr;
   fptr = fopen("D:\\guru.txt","w");

   if(fptr == NULL)
   {
      printf("Error!"); 
      exit(1);           
   }
   printf("Enter num: ");
   scanf("%d",&num);
   fprintf(fptr,"%d",num);
   fclose(fptr);
}

Example 2: Program to Open a File, Write in it, And Close the File
# include <stdio.h>
# include <string.h>
void main( )
{
    // Declare the file pointer
    FILE *filePointer ;

    // Get the data to be written in file
    char dataToBeWritten[50]="gurunadh.pahimamguru.com";
    // Open the existing file GfgTest.c using fopen()
    // in write mode using "w" attribute
    filePointer = fopen("gurufile.c", "w") ;
     
    // Check if this filePointer is null
    // which maybe if the file does not exist
    if ( filePointer == NULL )
    {
        printf( "gurufile.c file failed to open." ) ;
    }
    else
    {
        printf("The file is now opened.\n") ;
        // Write the dataToBeWritten into the file
        if ( strlen (  dataToBeWritten  ) > 0 )
        {
            // writing in the file using fputs()
            fputs(dataToBeWritten, filePointer) ;   
            fputs("\n", filePointer) ;
        }
        // Closing the file using fclose()
        fclose(filePointer) ;
         
        printf("Data successfully written in file gurufile.c\n");
        printf("The file is now closed.") ;
    }
 }

Example 3: Program to Open a File, Read from it, And Close the File
# include <stdio.h>
# include <string.h>
void main( )
{
    // Declare the file pointer
    FILE *filePointer ;
    // Declare the variable for the data to be read from file
    char dataToBeRead[50];
 
    // Open the existing file gurufile.c using fopen()
    // in read mode using "r" attribute
    filePointer = fopen("gurufile.c", "r") ;
     
    // Check if this filePointer is null
    // which maybe if the file does not exist
    if ( filePointer == NULL )
    {
        printf( "gurufile.c file failed to open." ) ;
    }
    else
    {
        printf("The file is now opened.\n") ;
        // Read the dataToBeRead from the file
        // using fgets() method
        while( fgets ( dataToBeRead, 50, filePointer ) != NULL )
        {
            // Print the dataToBeRead 
            printf( "%s" , dataToBeRead ) ;
         }
        // Closing the file using fclose()
        fclose(filePointer) ;
        printf("Data successfully read from file gurufile.c\n");
        printf("The file is now closed.") ;
    }
}

Tuesday, February 25, 2020

Graphs In Data Structures

    

A graph is a non-linear data structure that consists of a finite set of nodes and a set of edges connecting them. The nodes are sometimes also referred to as vertices and the edges are lines or arcs that connect any two nodes.

A graph is a set of (V,E) pairs, where 
V - set of vertices - Represented as Circles -  Also know as Nodes
E - set pf edges     - Represented as Lines - connecting lines of vertices/nodes
Example 1:
















Note :
Tree : For a tree if N nodes are there then (N-1) edges will be there, one edge for each parent-child relationship.
Graph : For a Graph there are no rules for connections.
Example 2:
  Fig 1                                                                                                                                             Fig 2
Note : In the above two figures Fig 1 is a Tree and a Graph as well. Where as Fig 2 is only a Graph.
A pair (x,y) is referred to as an edge, which communicates that the x vertex connects to the y vertex.

A graph G is an ordered pair of set V of vertices and a set E of edges.
G=(V,E)
Ordered pair:
(a,b) is not equal to (b,a), if a is not equal to b
Unordered pait:
{a,b}={b,a}




Graphs are used to solve real-life problems that involve representation of the problem space as a network. Examples of networks include telephone networks, circuit networks, social networks (like LinkedIn, Facebook etc.).
Ex : Undirected Graph
For example, a single user in Facebook can be represented as a node (vertex) while their connection with others can be represented as an edge between nodes. Each node can be a structure that contains information like user’s id, name, gender, etc.


             Above Graph showis a Social Network (Nodes as users and Edges show connection)

Terminology
Node - Also know as  vertex
Edge - Connecting line between any two nodes
            These are two types. Directed Edge in which connection is one way and Undirected edge in
            which connection is two way.
            Directed  Edge (u,v) and Undirected Edge {u,v} 
Adjacent nodes - which are connected to both ends of an edge
Degree of a Node - No of edges connected to a node
Size of a graph - total no of edges in a graph
Path -   A path is a sequence of vertices where each adjacent pair is connected by an edge.
           
         


Types of Graphs
Directed Graph(unidirectional)
Un-Directed Graph(bidirectional) - no direction is specified on edges
Weighted Graph - weight is specified for each edge
Unweighted Graph  - weight is not specified for any edge
Cyclic Graph - A graph which contains cycles(loops)
Acyclic Graph - A graph which do not contain cycles(loops)

Directed Graph
In a directed graph, nodes are connected by directed edges – they only go in one direction. For example, if an edge connects node 1 and 2, but the arrow head points towards 2, we can only traverse from node 1 to node 2 – not in the opposite direction.

Un-Directed Graph
In an undirected graph, nodes are connected by edges that are all bidirectional. For example if an edge connects node 1 and 2, we can traverse from node 1 to node 2, and from node 2 to 1.



Ex : Directed Graph is useful in Web-Crawling is nothing but Graph Traversal , It is an act of visiting all nodes in a graph.


Weighted Graph - weight is specified for each edge

Unweighted Graph  - weight is not specified for any edge (or) All edges are having same edge
(OR)
A weighted graph with all edges having weight=1 unit
UnDirected Graph :
Ex :Intercity Road Network :  Network of Highways and 3 ways between cities. 

Directed Graph :
Ex: Intracity Road Network : Network within a city. One way roads.It is a weighted .
.

Edges in the above graph are waited and it is called as weighted graph.

**Social Network is unweighted and undirected graph
**WWW is unweighted and directed graph


Cyclic Graph - A graph which contains cycles(loops)
Acyclic Graph - A graph which do not contain cycles(loops)



Types of Graph Representations:
Adjacency List
To create an Adjacency list, an array of lists is used. The size of the array is equal to the number of nodes.
A single index, array[i] represents the list of nodes adjacent to the ith node.
We make use of Linked List to represent "Adjacency List". For each vertex one Linked List is maintained.
Ex1:
Ex2:

Adjacency Matrix:
An Adjacency Matrix is a 2D array of size V x V where V is the number of nodes in a graph. A slot matrix[i][j] = 1 indicates that there is an edge from node i to node j.
[OR]
It is a Matrix a[n][n], where n is number of Vertices and a[i][j]=1 if i & j are adjacent
other wise a[i][j]=0.
Ex:

The Matrix representation of above Graph is given below

Graph Traversal
Graph traversal is a technique used for a searching vertex in a graph. The graph traversal is also used to decide the order of vertices is visited in the search process. A graph traversal finds the edges to be used in the search process without creating loops. That means using graph traversal we visit all the vertices of the graph without getting into looping path.

There are two graph traversal techniques and they are as follows...

DFS (Depth First Search)
BFS (Breadth First Search)

DFS (Depth First Search)
DFS traversal of a graph produces a spanning tree as final result. Spanning Tree is a graph without loops. We use Stack data structure with maximum size of total number of vertices in the graph to implement DFS traversal.
We use the following steps to implement DFS traversal...

Back tracking : Means coming back to the vertex from which we reached the current vertex.

Step 1 - Define a Stack of size total number of vertices in the graph.
Step 2 - Select any vertex as starting point for traversal. Visit that vertex and push it on to the Stack.
Step 3 - Visit any one of the non-visited adjacent vertices of a vertex which is at the top of stack and push it on to the stack.
Step 4 - Repeat step 3 until there is no new vertex to be visited from the vertex which is at the top of the stack.
Step 5 - When there is no new vertex to visit then use back tracking and pop one vertex from the stack.
Step 6 - Repeat steps 3, 4 and 5 until stack becomes Empty.
Step 7 - When stack becomes Empty, then produce final spanning tree by removing unused edges from the graph

Ex : consider the following example





Wednesday, February 5, 2020

Binary Tree Introduction Graphically


Tyes Of Binary Trees

Full Binary Tree / Strictly Binary Tree

Incomplete Binary Tree / Almost Complete Binary Tree
The following is not an Incomplete BinaryTree. Because for node “E” we have  child “J” which is filled from Right instead of Left side. So it is not satisfying the condition of Incomplete Binary Tree.
Complete Binary Tree
The following is Not a Complete Binary Tree as it is not satisfying the condition of Complete Binary Tree.i.e 2nd Level does not contain 4 nodes.

 Left Skewed Binary Tree
 Left Skewed Binary Tree  & Right Skewed Binary Tree
 All Binary Trees Together

Thursday, January 23, 2020

Java Database Connectivity with Oracle

Java Database Connectivity with Oracle

Connecting to Oracle Datatabase using a Java Application
About JDBC
JDBC Driver is a software component that enables java application to interact with the database. There are 4 types of JDBC drivers:
1.JDBC- ODBC bridge driver
2.Native -API driver (partially java driver)
3.Network Protocol driver (fully java driver)
4.Thin driver (fully java driver) – recommended to use

There are 5 steps to connect any java application with the database using JDBC. These steps are as follows:
Register the Driver class
Create connection
Create Statement/Prepare Statement
Execute queries
Close connection

1.Diver class: The driver class for the oracle database is "oracle.jdbc.driver.OracleDriver."
   Syntax : Class.forName("Diver class")
2.Connection URL: The connection URL for the oracle10G database is “jdbc:oracle:thin:@localhost:1521:xe”  where jdbc is the API, oracle is the database, thin is the driver, localhost is the server name on which oracle is  running, we may also use IP address, 1521 is the port number and XE is the Oracle service name. You may get all these information from the tnsnames.ora file.
  
   jdbc - api
   oracle - databaes
   thin   - driver type
   1521 - exculusive port number of oracle listener
   Syntax : Connection con=DriverManager.getConnection("Connection URL");

3.Username: The default username for the oracle database is system.

4.Password: It is the password given by the user at the time of installing the oracle database.

5. Get downloaded file "ojdbc14.jar" and copy the file in the folder  jre/lib/ext
    Ex: C:\Program Files (x86)\Java\jre1.8.0_60\lib\ext

Program to Connect to Oracle and retrieve the data from a table.
import java.sql.*; 
class OracleCon
{ 
  public static void main(String args[])
 { 
    try
   { 
     //step1 load the driver class 
     Class.forName("oracle.jdbc.driver.OracleDriver"); 
     //step2 create  the connection object 
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr"); 
         //step3 create the statement object 
     //Statement stmt=con.createStatement();
     PreparedStatement ps=con.prepareStatement("select * from emp"); 
     ResultSet rs=ps.executeQuery();
      //step4 execute query 
      //ResultSet rs=stmt.executeQuery("select * from employees"); 
      while(rs.next()) 
          System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3)); 
 
      //step5 close the connection object 
        con.close(); 
   }
   catch(Exception e)
   {
      System.out.println(e);
   } 
} 
}

Output:
E:\>javac OracleCon.java
E:\>java OracleCon
111  NAMMU  ANALYST
222  MOHAN  CLERK
333  GURU  MANAGER
444  KRISHNA  ENGINEER

Java ResultSetMetaData Interface
If you have to get metadata of a table like total number of column, column name, column type etc. , ResultSetMetaData interface is used
Commonly used methods of ResultSetMetaData interface
Commonly used methods of ResultSetMetaData interface
Method                                                                          Description
public int getColumnCount()throws SQLException               it returns the total number of
                                                                                          columns in the ResultSet object.
public String getColumnName(int index)     it returns the column name of the specified
throws SQLException                                  column index.
public String getColumnTypeName(int index)   it returns the column type name
throws SQLException                                        for the specified index.
public String getTableName(int index)           it returns the table name for the
throws SQLException                                    specified column index.


Write a program to Display Resultset Metadata

import java.sql.*; 
class rsmd{ 
public static void main(String args[]){ 
try{ 
Class.forName("oracle.jdbc.driver.OracleDriver"); 
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr"); 
 
PreparedStatement ps=con.prepareStatement("select * from emp"); 
ResultSet rs=ps.executeQuery(); 
ResultSetMetaData rsmd=rs.getMetaData(); 
 
System.out.println("Total columns: "+rsmd.getColumnCount()); 
System.out.println("Column Name of 1st column: "+rsmd.getColumnName(1)); 
System.out.println("Column Type Name of 1st column: "+rsmd.getColumnTypeName(1)); 
 
con.close(); 
}catch(Exception e){ System.out.println(e);} 
} 
} 
Output:
E:\>javac rsmd.java
E:\>java rsmd
Total columns: 5
Column Name of 1st column: EMPNO
Column Type Name of 1st column: NUMBER

Towers Of Hanoi Program

//Program to demonstrate Towers Of Hanoi 
import java.util.Scanner;
class tb

// Java recursive function to solve tower of BRAHMA/HANOI puzzle 
 static int c=0;   
 static void th(int n, char ST, char DT, char TT) 
    { 
        if (n == 1) 
        { 
            System.out.println("Move disk 1 from PEG " +  ST + " to PEG " + DT); 
            c++;
            return; 
        } 
        th(n-1, ST, TT, DT); 
        System.out.println("Move disk " + n + " from PEG " +  ST + " to PEG " + DT); 
        c++;
        th(n-1, TT, DT, ST);
         
    }
    public static void main(String args[]) 
    { 
        Scanner s=new Scanner(System.in);
        System.out.println("Enter Number Of Disks To Move:");
        int n = s.nextInt(); // Number of disks 
        th(n, 'A', 'C', 'B');  // A, B and C are names of PEG/TOWERS
        System.out.println("\nTotal Number Of Moves Occurred: "+c); 
    }
}

Output:
E:\>java tb
Enter Number Of Disks To Move:
1
Move disk 1 from PEG A to PEG C

Total Number Of Moves Occurred: 1

E:\>java tb
Enter Number Of Disks To Move:
2
Move disk 1 from PEG A to PEG B
Move disk 2 from PEG A to PEG C
Move disk 1 from PEG B to PEG C

Total Number Of Moves Occurred: 3

E:\>java tb
Enter Number Of Disks To Move:
3
Move disk 1 from PEG A to PEG C
Move disk 2 from PEG A to PEG B
Move disk 1 from PEG C to PEG B
Move disk 3 from PEG A to PEG C
Move disk 1 from PEG B to PEG A
Move disk 2 from PEG B to PEG C
Move disk 1 from PEG A to PEG C

Total Number Of Moves Occurred: 7

Towers Of Brahma or Towers of Hanoi

There is a story about an ancient temple in India has a large room with three towers surrounded by 64 golden disks. These disks are continuously moved by priests in the temple. According to a prophecy, when the last move of the puzzle is completed the world will end. These priests acting on the prophecy, follow the immutable rule by Lord Brahma of moving these disk one at a time. Hence this puzzle is often called Tower of Brahma(and also called Tower of Hanoi) puzzle.

https://www.hackerearth.com/blog/become-better-developer

What is the game of Tower of Hanoi?
Tower of Hanoi consists of three pegs or towers with n disks placed one over the other.
The objective of the puzzle is to move the stack to another peg following these simple rules.
Only one disk can be moved at a time.
No disk can be placed on top of the smaller disk

But what about the prophecy for the tower of Hanoi where the priests are using 64 disks?
Suppose that these priests are highly powerful and can move these massive disks at a speed of 1 per second per hour every day. At this speed, they would need 2^64 -1 move to complete the task.
That is, 18,446,744,073,709,551,615 moves to complete, which would take about 580 billion years

Tower of hanoi recursion explained, Tower of Hanoi, Tower of Hanoi recursion, Recursion explained, Tower of Hanoi explain

Wednesday, January 1, 2020

 Merge Sort ::  Data structure | Merge Sort using JAVA code

File Name : Mrgsrt.java
import java.util.*;
public class Mrgsrt
{
    public static void main(String[] args)
   {
      int a[],n,i;
      Scanner s=new Scanner(System.in);
      System.out.println("Enter size of the aay: ");
      n=s.nextInt(); 
      a=new int[n];
      System.out.println("Enter "+n+" Elements : ");
      for (i=0;i<n;i++)
      a[i]=s.nextInt();
      System.out.println("Elements in Array Before Merge Sort is: ");
      for (i=0;i<n; i++)
      System.out.print(a[i] + " ");
      System.out.println("\n");
      a=Merge_sort(a, n);
      System.out.println("Elements in Array After Merge Sort is: ");
      for (i=0;i<n; i++)
      System.out.print(a[i] + " ");
      System.out.println("\n");
   }

      static int[] Merge_sort(int a[], int size)
     {
        if (size>1)
       {
        int mid=size /2,first[],second[];
        first = Arrays.copyOfRange(a, 0, mid);
        first = Merge_sort(first, mid); // recursive call for first half aay
        second = Arrays.copyOfRange(a, mid, size);
        second = Merge_sort(second, size - mid); // recursive call for second half aay
        a=Merge_arrays(first, second, mid, size - mid);
     }
      return a;
  }

  static int[] Merge_arrays(int first[], int second[], int n, int m) // respectively
 {
    int a[] = new int[n + m];
    int i = 0, f = 0, s = 0;
    while(f<n && s<m)
    {
       a[i++]=(first[f]<second[s])?first[f++]:second[s++];
     }
    while(f <n)
      a[i++] = first[f++];
    while(s<m)
      a[i++]=second[s++];
    return a;
  }
}


Compilation
E:\>javac Mrgsrt.java
Execution
E:\>java Mrgsrt
Output
Enter size of the aay:
6
Enter 6 Elements :
23
5
66
1
8
99
Elements in Array Before Merge Sort is:
23 5 66 1 8 99

Elements in Array After Merge Sort is:
1 5 8 23 66 99

Tuesday, February 26, 2019

Demonistration of function using Call By Reference

Function : A function is a group of statements that together perform a task.A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.

File Name : callbyreference.c
//program to swap two numbers using functions - callbyreference

#include<stdio.h>
 void main()
{
  int a=10,b=50;
  void swap(int *,int *);
  clrscr();
  printf("Before Swapping: %d %d\n",a,b);
  swap(&a,&b);
  printf("After Swapping: %d %d\n",a,b);
}
void swap(int *a,int *b)
{
  int t;
  t=*a;
  *a=*b;
  *b=t;
}

Output :
Before Swapping: 10 50
After Swapping: 50 10

program to perform various String Operations - in C Language using Ubuntu

File Name : string.c

#include <stdio.h>
#include <string.h>
void main()
{
    char str1[30],str2[30];
    int choice,result=0;
    int len1=0,len2=0;
    printf("\n Enter First String : ");
    scanf("%[^\n]",str1);
    printf("\n Enter Second String : ");
    scanf("%s",str2);
    printf("\n Enter Your Choice : \n");
    printf("1. Copy Strings. \n");
    printf("2. Compare Strings. \n");
    printf("3. Concatenate Strings. \n");
    printf("4. Find Lengths. \n");
    printf("\n Enter Your Choice :");
    scanf("%d",&choice);
    switch(choice)
    {
       case 1 :
         {
        strcpy(str1,str2);
          //strcpy(pos1,pos2);
        printf("\n %s %s \n",str1,str2);
        break;
         }
       case 2 :
         {
        result = strcmp(str2,str1);
        if(result == 0)
           printf("\n Both Strings are Same. ");
        else
           printf("\n Both are different strings.");

        break;
         }
       case 3 :
         {
        strcat(str1,str2);
          //strcat(pos1,pos2);
        printf("\n %s %s \n",str1,str2);
        break;
         }
       case 4 :
         {
        len1 = strlen(str1);
        printf("\n Legth of First String is %d \n",len1);
        len2 = strlen(str2);
        printf("\n Legth of Second String is %d \n",len2);
        break;
         }
     default : printf("\n Wrong Choice .");
    }
   
}

Output1:
Enter First String : guru
Enter Second String : nath
 Enter Your Choice :
1. Copy Strings.
2. Compare Strings.
3. Concatenate Strings.
4. Find Lengths.
Enter Your Choice :1
nath nath

Note : here strcpy function copies string in position2 copies to string in position1

Output 2:
Enter First String : guru
Enter Second String : nath
Enter Your Choice :
1. Copy Strings.
2. Compare Strings.
3. Concatenate Strings.
4. Find Lengths.
 Enter Your Choice :2
 Both are different strings.

Enter First String : guru
Enter Second String : guru
Enter Your Choice :
1. Copy Strings.
2. Compare Strings.
3. Concatenate Strings.
4. Find Lengths.
Enter Your Choice :2
Both Strings are Same.

Output 3:
Enter First String : guru
Enter Second String : nath
Enter Your Choice :
1. Copy Strings.
2. Compare Strings.
3. Concatenate Strings.
4. Find Lengths.
Enter Your Choice :3
gurunath nath

Enter First String : nath
Enter Second String : guru
Enter Your Choice :
1. Copy Strings.
2. Compare Strings.
3. Concatenate Strings.
4. Find Lengths.
Enter Your Choice :3
nathguru guru

 Note : strcat() function string in position1 will be concatinated with string in position2

Output 4:
Enter First String : guru
Enter Second String : nammu
Enter Your Choice :
1. Copy Strings.
2. Compare Strings.
3. Concatenate Strings.
4. Find Lengths.
Enter Your Choice :4
Legth of First String is 4
Legth of Second String is 5

Friday, February 15, 2019

Multiplication of two Matrices in C - Language Using Ubuntu

File Name : mulmat.c

#include <stdio.h>
void main()
{
 int m,n,p,q,c,d,k,sum=0;
 int f[10][10],s[10][10],mul[10][10];
 printf("Enter the number of rows and columns of First Matrix\n");
 scanf("%d%d",&m,&n);
 printf("Enter the elements of First Matrix\n");
 for(c=0;c<m;c++)
    for(d=0;d<n;d++)
       scanf("%d",&f[c][d]);
 printf("Enter the number of rows and columns of Second Matrix\n");
 scanf("%d%d",&p,&q);
 if(n!=p)
    printf("The matrices multiplication is not possible.\n");
 else
 {
  printf("Enter the elements of Second Matrix\n");
  for(c=0;c<p;c++)
    for(d=0;d<q;d++)
        scanf("%d",&s[c][d]);    
  for(c=0;c<m;c++)
     {
      for(d=0;d<q;d++)
         {
          for(k=0;k<p;k++)
             {
               sum=sum+f[c][k]*s[k][d];
             }
          mul[c][d]=sum;
          sum = 0;
         }
     }
 printf("Product of Matrices is:\n");
 for(c=0;c<m;c++)
    {  
     for(d=0;d<q;d++)
         printf("%d\t", mul[c][d]);
         printf("\n");
    }
 }
}

Output 1:
Enter the number of rows and columns of First Matrix
2
2
Enter the elements of First Matrix
1
2
3
4
Enter the number of rows and columns of Second Matrix
2
2
Enter the elements of Second Matrix
1
2
3
4
Product of Matrices is:
7    10   
15    22

Output 2:
Enter the number of rows and columns of First Matrix
2
2
Enter the elements of First Matrix
1
2
3
4
Enter the number of rows and columns of Second Matrix
4
5
The matrices multiplication is not possible.

Hadoop Commands

HADOOP COMMANDS OS : Ubuntu Environment Author : Bottu Gurunadha Rao Created: 31-Jan-2022 Updated: 31-Jan-2022 Release  : 1.0.1 Purpose: To ...

Search This Blog