Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

scherniak Group Title

how do i: Write a program to input 2 numbers, first and diff. The program will then create a one-dimensional array of 16 elements in an arithmetic sequence which is printed out.  For example, if first is 21 and diff = 5, the arithmetic sequence will be:  21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96

  • 3 years ago
  • 3 years ago

  • This Question is Closed
  1. jaskaran Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    since you didn't specified any language so here's a program in python first = input('Enter the first number: ') diff = input('Enter the difference among the numbers: ') count=0 while count < 16: print first first = first + diff count+=1

    • 3 years ago
  2. DaveWong Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    int output[] = new output[16]; for (int i=0, i<16, i++) { output[i] = first + (diff * i); } It helps to ask a more specific question so we know what you're stumped on exactly and if you need to know something in a particular language or if psuedo code is suitable. I've answered above only what I guess would be the most trivial part of your problem, in a C#/Java-like language.

    • 3 years ago
  3. Hyouga Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    First thing to tell scherniak, please specify the language you use. So, other can help you.

    • 3 years ago
  4. scherniak Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks a alot! How can i do the same with a 2d array (in java)?

    • 3 years ago
  5. DaveWong Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Be more specific - what exactly do you want to do with the 2d array?

    • 3 years ago
  6. scherniak Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    input 2 numbers, first and diff. The program will then create a two-dimensional array of 4x4 in an arithmetic sequence which is printed out. For example, if first is 21 and diff = 5, the arithmetic sequence will be: 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96

    • 3 years ago
  7. scherniak Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    for(int i = 0;i<4;i++) { for(int j = 0; j<4; j++) { output[i][j] = (cant figure out what to put here) } }

    • 3 years ago
  8. DaveWong Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Ah okay. output[i][j] = first + (diff * ((i * 4) + j) );

    • 3 years ago
  9. scherniak Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    also... how can i reverse the diagonals? eg. have no idea how to approach this 96 26 31 81 41 71 66 56 61 51 46 76 36 86 91 21

    • 3 years ago
  10. DaveWong Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Here's one way you could do it: for(int i = 0;i<4;i++) { for(int j = 0; j<4; j++) { if (i==j) { output[i][j] = first + (diff * ( ((3-i) * 4) + (3-j) ); } else { output[i][j] = first + (diff * ((i * 4) + j) ); } } }

    • 3 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.