Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

scalar multiplication of matrices in C

Posted on 2008-10-06
6
Medium Priority
?
1,654 Views
Last Modified: 2010-05-18
I need to create a program in C language that will calculate the multiplication of a matrix times a scalar value. All the user input should be read from a file. The input file must contain the size of matrix as well as the values stored inside the matrix and the scalar value by which the matrix will multiplied. The resulting matrix is to be stored in a new matrix called mResult and printed on the screen. Must have at least two functions aside from the main function. One hould handle the scalar*matrix multiplication and the other the output. Use any of the following loops; while, do-while, while.
0
Comment
Question by:wlgarcia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 22649962
And what's your question ?
0
 
LVL 5

Expert Comment

by:jose_juan
ID: 22650279
Simple.

Good luck!

<edited by sunnycoder>
ZAPE

Open in new window

0
 
LVL 3

Expert Comment

by:wktang83
ID: 22656150
You have to create a class call Matrix.

To enable operation such as M * k (k is a scalar value, and M is a matrix), you need to overload the operator * in C. How much do you know about operator overloading?

If you are beginner to operator overloading, you may read this tutorial: http://www.learning-computer-programming.blogspot.com/2007/08/introduction-to-operator-overloading-in.html

Let me know your progress. Post questions if you are stucked, and we'll try to guide you along.

Regards,
wktang83
0
 
LVL 5

Accepted Solution

by:
jose_juan earned 500 total points
ID: 22656927
Uhm....

Yes wktang83, your way are a good way but I think, wlgarcia is begginer.

I suggest to wlgarcia understand IO reading in C/C++ (printf, scanf functions), basic types (char, int, float, double, ...) and basic flow control (if, for, while, do-while, ...).

For print a message to user (console mode) you can do

    printf("Enter a number: ");

For read a number into a variable:

    float number;
    scanf("%f", &number);
    // now, number have the input

To implement a matrix on your program you must known the array and allocation in C/C++ using (understanding):

   float matrix[ 30 ][ 30 ];
   float matrix[ 30 * 30 ];
   float *matrix = new float [ 30 * 30 ];
   float **matrix; // iteration for population is needed

To iterate a bidimensional array you can do

  for( int row = 0; row < max_rows; row++ )
    for( int col = 0; col < max_cols; col )
       printf("%f ", matrix[ row ][ col ] );

and, a while or do-while version? (without for)

Good luck!



0
 

Author Closing Comment

by:wlgarcia
ID: 31503410
I have some understanding about I/O. so the piece of advice you have given me is sufficient for me to build the program.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question