how can i solve this 2 problems?!can you please help me?!

Another matrix algebra operation is determining the matrix which is the product of two matrices. This is more challenging extension of the previous problem. The rule governing matrix multiplication is that two can matrices can be multiplied if the number of the columns in the first matrix is equal to the number of rows in the second. The first matrix is the multiplier and the second matrix is the multiplicand. The number of rows in the product matrix will be the number of rows in the first, and the number of the columns in the product matrix will be the number of columns in the second. Stated mathematically,

If A=[a i,j] and B=, then AB=C=[c i,k]

Where brackets indicate matrices. For example, if the two given matrices are


a 1.1 a 1.2 a 1.3 a 1.4 b 1.1 b 1.2 b 1.3 b 1.4 b 1.5

a 2.1 a 2.2 a 2.3 a 2.4 b 2.1 b 2.2 b 2.3 b 2.4 b 2.5

a 3.1 a 3.2 a 3.3 a 3.4 and b 3.1 b 3.2 b 3.3 b 3.4 b 3.5

b 4.1 b 4.2 b 4.3 b 4.4 b 4.5

the product is

c 1.1 c 1.2 c 1.3 c 1.4 c 1.5

c 2.1 c 2.2 c 2.3 c 2.4 c 2.5

c 3.1 c 3.2 c 3.3 c 3.4 c 3.5


The values of each element in the product matrix are determined by summing the products of the elements in the row of the first matrix times the elements in a column of the second matrix, for example:

c 1.1 = a1.1*b1.1+ a1.2*b2.1+a1.3*b3.1+a1.4*b4.1

c 1.5 = a1.1*b1.5+a1.2*b2.5+a1.3*b3.5+a1.4*b4.5

c 2.1 = a2.1*b1.1+a2.2*b2.1+a2.3*b3.1+a2.4*b4.1

Write a program which will read the values of any two matrices up to 10 x 10 array and determine the product matrix. Both the given matrices and the product matrix should be printed. For simplicity, use integer elements and plan the program so that the matrix with fewest rows is read first.


and this one..

Write a program to input a string in sentence format. Change all occurence of strings within the sentence with length of 4 to "AHA". Print the original string and the new string.

please help me..

can anyone give me the source code?!

>>can anyone give me the source code?!
Yes. But you have to show your effort first. Post what you have done to solve those problems.

>>can anyone give me the source code?!
Yes. But you have to show your effort first. Post what you have done to solve those problems.

#include<stdio.h>
      #include<math.h>
      main()
      {
        int i,j,k;
       int a,b,c;/*three variables to get the row and colum of the two matrix*/
       int sum;
       int m[10][10],n[10][10],l[10][10];
       printf("The first matrix:\n");
       printf("Enter the number of rows and columns for the first matrix:\t")  ;
       scanf("%d%d",&a,&b);
       printf("The Second matrix:\n");
       printf(Enter the rows and columns of the second matrix:\t:);
       scanf("%d%d",&b,&c);
       
       /* Note: For matrix multiplication the number of columns in the first matrix should be equal to the number of rows in the second message*/
       printf(":Enter the values of the first matrix:\n");
       for(i=0;i<a;i++)
         {
           for(j=0;j<b;j++)
             {
               scanf("%d",&m[i][j]);
             }
         }
        printf("Enter the values of the second matrix:\n");
        for(i=0;i<b;i++)
         {
           for(j=0;j<c;j++)
            {
              scanf("%d",&n[i][j]);
            }
         }
         for(i=0;i<a;i++)
           {
          for(j=0;j<c;j++)
           {
             sum=0;
             for(k=0;k<b;k++)
              {
                sum=sum+(m[i][k]*n[k][j]);
                l[i][j]=sum;
              }
           }
        }
        printf("The multiplied matrix is:\n);
        for(i=0;i<a;i++)
         {
           for(j=0;j<c;j++)
            {
               printf ("%d",l[i][j]);
               printf("\t");
            }
             printf("\n");
         }

i can't be sure that this is correct..but this is the code you want..

It isn't necessary to manually add line numbers to your code when you use code tags.

i can't be sure that this is correct..

Compile it for knowing whether there are any syntax errors. Correct them if any (Like, you've not written 'return 0;' and '}' at the end of main()). Even, if you cannot see what is wring, then post the errors and the respective line no.s. We'll tell you why the errors are ocurring and help you fix them. Once it is compiled, run it. If it does not work the way you want, go through the code. Add watches and breakpoints for debugging. If you are not able to do that, post the output you're getting. You'll get help then.

Write a program to input a string in sentence format. Change all occurence of strings within the sentence with length of 4 to "AHA". Print the original string and the new string.

All the above statements apply for this problem also. I think you should have started a new thread for this one, as the two problems have nothing in common.

One more thing. The stdio.h library and the printf() statements suggest this is a C code, not a C++ code. Or is it that you've got the code in C and you want to do the same thing in C++?

Compile it for knowing whether there are any syntax errors. Correct them if any (Like, you've not written 'return 0;' and '}' at the end of main()). Even, if you cannot see what is wring, then post the errors and the respective line no.s. We'll tell you why the errors are ocurring and help you fix them. Once it is compiled, run it. If it does not work the way you want, go through the code. Add watches and breakpoints for debugging. If you are not able to do that, post the output you're getting. You'll get help then.


All the above statements apply for this problem also. I think you should have started a new thread for this one, as the two problems have nothing in common.

One more thing. The stdio.h library and the printf() statements suggest this is a C code, not a C++ code. Or is it that you've got the code in C and you want to do the same thing in C++?

i finish the source code of the first problem..the second one..i can't do it..it's hard for me..

i finish the source code of the first problem..the second one..i can't do it..it's hard for me..
Write a program to input a string in sentence format. Change all occurence of strings within the sentence with length of 4 to "AHA". Print the original string and the new string.

Read sentence in vector of strings,
traverse the vector of string
if (length(vector[i]) == 4) vector[i]=std::string("AHA");
Read sentence in vector of strings,
traverse the vector of string
if (length(vector[i]) == 4) vector[i]=std::string("AHA");

how can i do it?!i wonder how..I'm a beginner in doing program..can you elaborate how can i do it?!

>>Write a program to input a string in sentence format. Change all occurence of strings
>>within the sentence with length of 4 to "AHA". Print the original string and the new string.

For this create a std::string sentence object and call getline(sentence, cin); to get the sentence from the keyboard. After that you can use std::stringstream object to split the string into its individual words inside a loop. If the word does not have length 4 just call cout to print it to the screen, otherwise if the word has length 4 then print "AHA" to the screen. I see no requirement to save any of the information anywhere.

stringstream is declared in <sstring>. It works very similar to cin and cout but it gets its information from another string instead of the keyboard. Here is a simple example of how it might work.

std::string word;
std::stringstream stream;
std::string line = "Once upon a time";
stream = line;
while( stream >> word) // while not end of sentence
{
   // do somewith with this word
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.