1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
zmey [24]
2 years ago
14

Write a program called array1.cpp file that use either regular for loop or range based for loop to display the contents of the a

rray test []. You can also write a function to display the contents of array. Submit your code array1.cpp to Blackboard.
Computers and Technology
1 answer:
ch4aika [34]2 years ago
7 0

Answer:

The program in C++ is as follows:

#include <iostream>

using namespace std;

void display(int array_test [], int n){

   for(int i = 0; i<n;i++){

       cout<<array_test[i]<<" ";   }

}

int main(){

   int n;

   cin>>n;

   int array_test[n];

   for(int i = 0; i<n;i++){

       cin>>array_test[i];

   }

   display(array_test,n);

   return 0;

}

Explanation:

This defines the display function

void display(int array_test [], int n){

This iterates through the array

   for(int i = 0; i<n;i++){

This prints each element of the array

       cout<<array_test[i]<<" ";   }

}

The main begins here

int main(){

This declares n as integer; n represents the length of the array

   int n;

This gets input for n

   cin>>n;

This declares the array

   int array_test[n];

The following iteration gets input for the array

   for(int i = 0; i<n;i++){

       cin>>array_test[i];

   }

This calls the display function to display the elements of the array

   display(array_test,n);

   return 0;

}

You might be interested in
Can anybody come up with a catchy title for this?
nekit [7.7K]

What the future beholds!

Trouble with technology? Not a problem!

Techno Gadget

I have more ideas if you're not interested in any of these. :)

7 0
2 years ago
Design a program that asks the user to enter a string containing a series of single digit numbers with nothing separating them.
ruslelena [56]

Answer:

  1. def calcSum(d):
  2.    sum = 0
  3.    for x in d:
  4.        sum += int(x)
  5.    return sum
  6. digits = input("Please enter your digits: ")
  7. print(calcSum(digits))

Explanation:

The solution code is written in Python.

Firstly, create a function that take one input digit string (Line 1).

In the function, create a sum variable with initial value 0.

Use a for loop to traverse through each character in the digit string and in the loop use int method to convert each character to integer and add it to sum variable (Line 3-5) and return the sum as output.

Next, use input function to prompt user enter a digit string (Line 7).

Lastly test the function by passing the input digit as argument and print the result (Line 8).

7 0
3 years ago
_____ includes a wide range of applications, practices, and technologies for the extraction, transformation, integration, analys
Alla [95]

Answer:

The answer is "Option a".

Explanation:

The B.I. is a method, methodology, software, and development set that makes raw data usable and relevant, which facilitates improved decision-making and competitive opportunities, and certain choices were wrong, which can be described as follows:

  • In option b, The A.I is uses in the machines, that's why it is not correct.
  • In option c, It is used to analyze the data, which used in business. that's why it is not correct.
  • In option d, It is wrong, because it a part of A.I.
6 0
3 years ago
What was the effect of the norman conquest on the language of britain?
Maslowich
Option c is answer because most of us are literature in English
6 0
3 years ago
Write a program that asks the user how many numbers will be entered and then has the user enter those numbers. When this is done
KATRIN_1 [288]

Answer:

<em>The program written in Python 3 is as follows;</em>

<em>The program does not make use of comments; however, see explanation section for detailed line by line explanation of the program</em>

num = int(input("Number of Inputs: "))

mylist = []

userinput = int(input("Enter a digit: "))

i = 1

while i < num:

     mylist.append(userinput)

     userinput = int(input("Enter a digit: "))

     i += 1

   

try:

     first7 = mylist.index(7)+1

     print('The first position of 7 is ',first7)

     last7 = num - 1 - mylist[::-1].index(7)

     print('The last position of 7 is ',last7)

except:

     print('7 is not on the list')

Explanation:

This line prompts user for the number of inputs

num = int(input("Number of Inputs: "))

This line declares an empty list

mylist = []

This line inputs the first number into the empty list

userinput = int(input("Enter a digit: "))

The italicized lines represent an iteration that allows user to input the numbers into the empty list.

<em>i = 1</em>

<em>while i < num:</em>

<em>      mylist.append(userinput)</em>

<em>      userinput = int(input("Enter a digit: "))</em>

<em>      i += 1</em>

The try-except is used to check the presence of 7 in the list

try:

This checks the first occurrence of 7

     first7 = mylist.index(7)+1

This prints the first occurrence of 7

     print('The first position of 7 is ',first7)

This checks the last occurrence of 7

     last7 = num - 1 - mylist[::-1].index(7)

This prints the last occurrence of 7

     print('The last position of 7 is ',last7)

The following is executed if there's no occurrence of 7

except:

     print('7 is not on the list')

See Attachments for sample runs

7 0
3 years ago
Other questions:
  • A drop-down menu must be contained by
    5·1 answer
  • When selecting text in word, holding down the ctrl key while clicking the mouse button will select the?
    15·1 answer
  • You put $500 in an interest bearing bank account that pays 2% per year but has a fee of $2 per month. Are you getting ahead?
    14·2 answers
  • Multiple Choice
    6·1 answer
  • David would like to send a letter to more than one hundred people. He would like the letter to have names and addresses inserted
    12·2 answers
  • The design of a blog refers to:
    8·1 answer
  • Assume that you want two C# or C++ programs to share some data. You can write the first program so that it writes it's output to
    5·1 answer
  • No down payment, 18 percent / year, payment of $50/month, payment goes first to interest, balance to principal. Write a program
    9·1 answer
  • To have a reason or purpose to do something
    8·2 answers
  • Write a method to add/subtract two matrices. The header of the method is as follows:
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!