Skip to main content

Write a java program for multiplying two matrices and print the product for the same | VCMIT

Two matrices and print the product for the same.


INPUT

public class Matrix1{
public static void main(String args[]){   
int a[][]={{1,1,1},{2,2,2},{3,3,3}}; 
int b[][]={{1,1,1},{2,2,2},{3,3,3}};     
int c[][]=new int[3][3];   
for(int i=0;i<3;i++){ 
for(int j=0;j<3;j++){ 
c[i][j]=0;   
for(int k=0;k<3;k++)   
{   
c[i][j]+=a[i][k]*b[k][j];   
}
System.out.print(c[i][j]+" "); 
}
System.out.println(); 

}}

OUTPUT



Comments

Popular posts from this blog

Software Engineering - Waterfall Model | VCMIT

Waterfall model Winston Royce introduced the Waterfall Model in 1970.This model has five phases: Requirements analysis and specification, design, implementation, and unit testing, integration and system testing, and operation and maintenance. The steps always follow in this order and do not overlap. The developer must complete every phase before the next phase begins. This model is named "Waterfall Model", because its diagrammatic representation resembles a cascade of waterfalls. 1. Requirements analysis and specification phase: The aim of this phase is to understand the exact requirements of the customer and to document them properly. Both the customer and the software developer work together so as to document all the functions, performance, and interfacing requirement of the software. It describes the "what" of the system to be produced and not "how."In this phase, a large document called Software Requirement Specification (SRS) document is created whic...

Designed a class SortData that contains the method asec() and desc(). | VCMIT

The Method asec() And desc(). INPUT import java.util.*; class prac4A { Scanner input=new Scanner(System.in); int num,i; int arr[]; int temp=0; public void getdata() { System.out.print("Enter the size of array: "); num=input.nextInt(); arr=new int[num]; System.out.print("Enter the number: "); for( i=0;i<num;i++) { arr[i]=input.nextInt(); } } void putdata() { System.out.print("Given numbers are: "); for(i=0;i<num;i++) { System.out.println(arr[i]); } } void asce() { for(i=0;i<num;i++) { for(int j=i+1;j<num;j++) { if(arr[i]>arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } System.out.print("Ascending order of number are: "); for(int i=0;i<num;i++) { System.out.println(arr[i]); } } void desc() { for(i=0;i<num;i++) { for(int j=i+1;j<num;j++) { if(arr[i]<arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } System.out.print("Descending order of number are: "); for(int i=0;i<num;i++) { System.out.println(...
// Assuming you have fetched the search query and blog posts // Function to calculate the similarity score between search query and post function calculateSimilarity(query, post) { // You can use a similarity algorithm here, like TF-IDF or cosine similarity // Return a score that represents how relevant the post is to the query } // Function to suggest relevant posts based on search query function suggestPosts(searchQuery, blogPosts) { const suggestedPosts = []; for (const post of blogPosts) { const similarityScore = calculateSimilarity(searchQuery, post); if (similarityScore > 0) { suggestedPosts.push({ post, similarityScore }); } } // Sort the suggested posts based on similarity score suggestedPosts.sort((a, b) => b.similarityScore - a.similarityScore); // Return the sorted list of suggested posts return suggestedPosts.map(item => item.post); } // Example usage const searchQuery = "your search query"; const allBlogPosts = [/* array of your blog posts */]; const suggestedPosts = suggestPosts(searchQuery, allBlogPosts); // Now you can display suggestedPosts to the user