Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashtaj
    New Member
    • Feb 2007
    • 7

    #1

    Array

    Hi all how can i multiplay two arrays toger in C language
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    How do you want to multiply them? Element by element or some other fashion?

    Comment

    • ashtaj
      New Member
      • Feb 2007
      • 7

      #3
      Element by element

      Comment

      • AdrianH
        Recognized Expert Top Contributor
        • Feb 2007
        • 1251

        #4
        Originally posted by ashtaj
        Element by element
        Then write a loop to go through each element. We aren't going to do your work for you ya know. :)

        Write some code and come back with some more specific questions.


        Adrian

        Comment

        • ashtaj
          New Member
          • Feb 2007
          • 7

          #5
          int y[i],x[z],c[m];
          int o;

          for(o=0;o<i;o++ )
          {
          c[m]=y[i]*x[z];
          printf("%d",c[m]);
          }


          is it right?

          Comment

          • AdrianH
            Recognized Expert Top Contributor
            • Feb 2007
            • 1251

            #6
            Originally posted by ashtaj
            int y[i],x[z],c[m];
            int o;

            for(o=0;o<i;o++ )
            {
            c[m]=y[i]*x[z];
            printf("%d",c[m]);
            }


            is it right?
            Assuming that i, z, and m are constants, then no. I am going to assume the following:
            • that i==z and z==m
            • that you want to multiply the 0th element of y to the 0th element to x which is to be stored in the 0th element in c, the 1st element of y to the 1st element to x which is to be stored in the 1sr element in c, and so on.

            In which case, in your loop, you don't want to index using the constants. You tell me, what index(s) do you want to use?


            Adrian

            Comment

            Working...