Question

using loops create an array of 10 elements. Fill the array with values in increments of...

using loops create an array of 10 elements. Fill the array with values in increments of 3. Create a second array that takes the square root of the elements in the first array. The output should show both arrays contents

In visual studio program for C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int first[10];
    double second[10];
    // using loops create an array of 10 elements
    for (int i = 0; i < 10; ++i) {
        // Fill the array with values in increments of 3
        first[i] = 3*i;
    }
    // Create a second array that takes the square root of the elements in the first array
    for (int i = 0; i < 10; ++i) {
        second[i] = sqrt(first[i]);
    }
    // The output should show both arrays contents
    for (int i = 0; i < 10; ++i) {
        cout << first[i] << "\t" << second[i] << endl;
    }
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
using loops create an array of 10 elements. Fill the array with values in increments of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program to : Create array arr1 of size 10 Assign values to elements...

    Write a C++ program to : Create array arr1 of size 10 Assign values to elements such that - say index = i, arr1[i] = 10 - i. Print arr1 Create arr2 and copy alternate elements from arr1 starting from index 1. Print arr2. Sort arr1 in ascending array and print its elements from indices 3 to 8 Print every output on a different line and separate array elements by spaces.

  • Write a c program that finds the uncommon elements from two array elements using pointers only...

    Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...

  • C++ QUESTION Loops, arrays, functions find the three largest values in an array of integers and...

    C++ QUESTION Loops, arrays, functions find the three largest values in an array of integers and output them to the screen. You must utilize at least three functions, counting main as a function, AND you must use parameters/arguments in one of them. Set up an integer array of 10 elements, read in the ten elements from the keyboard. There are many ways to solve this lab. Here are a couple of ideas: Use a function to find the largest value...

  • ***************C PROGRAMMING ONLY************* Demonstrate the ability to create an array on the stack Demonstrate the ability...

    ***************C PROGRAMMING ONLY************* Demonstrate the ability to create an array on the stack Demonstrate the ability to create an array on the heap allowing user to choose the number of values to store. Demonstrate the ability to store an array of Struct values on both the stack and the heap. Program Specifications: 1. Create a struct with at least 3 fields - any struct you want but explain it in your comments in the code. Populate at least 10 elements...

  • C++ This week, you are to create two separate programs, first using a simple array and...

    C++ This week, you are to create two separate programs, first using a simple array and the second using a 2D-array (matrix). [Part 1] Write a program that accepts exactly ten (10) integer numbers from the user and stores them in an array. In a separate for-loop, the program then goes through the elements in the array to print back: (i) The sum of the 10 numbers, (ii) the minimum value from the 10 numbers, and (iii) the maximum value...

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

  • C++. Write a program that copies the contents of one array into another array but in...

    C++. Write a program that copies the contents of one array into another array but in reverse order using pointers.           - in main()                    - define 2 arrays of type int, 10 elements each                              - initialize one array with numbers 1 through 10                              - initialize all elements of the second array to 0                    - call function reverseCopy with both arrays as arguments                    - display the values of array number 2 (reversed order)           - reverseCopy...

  • using C language Create an array of doubles with 5 elements. In the array prompt the...

    using C language Create an array of doubles with 5 elements. In the array prompt the user to enter 5 temperature values (in degree Fahrenheit). Do this within main. Create a user defined function called convert2Cels. This function will not return any values to main with a return statement. It should have parameters that include the temperature array and the number of elements. The function should convert the values for Fahrenheit to Celsius and save them back into the same...

  • programing C,already write part of code (a) Write a function print.array that receives an array of...

    programing C,already write part of code (a) Write a function print.array that receives an array of real numbers and the number of el stored in the array. This function must display the elements of the array in order with each one on a line by itself in a field width of 7 with two decimal places. (See sample output. Recall the format specifier would be "%7.21f"). (b) Sometimes we want to treat an array as a mathematical vector and compute...

  • Write a C++ program that reads in 6 elements from the keyboard and stores them in...

    Write a C++ program that reads in 6 elements from the keyboard and stores them in an array x[6]. It should then create a second array y[6] that contains the elements from x in reverse order and with the s Tsecond - Tsmallest shown below. A sample run should look like: rocted ITrom it (e.g., Jlast first Tsmallest Vsecond last , etc). The program should finally print out both arrays to screen, in the format Enter 6 array elements: 4...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT