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
astraxan [27]
3 years ago
13

You do not need to use any functions beyond the main function in this problem. Initialize an array of int with the values: 4, 6,

9, and 12. Write a for loop to add the values in the array and find their sum. Write a second loop to print the values from the array and their sum in the following format: 4 + 6 + 9 + 12 = 31
Computers and Technology
1 answer:
Mariulka [41]3 years ago
3 0

Answer:

Following are the code in C language

#include <stdio.h> // header file

int main() // main function

{

int s1=0;// variable declaration

int arr[10]={4,6,9,12}; // array declaration

for(int k=0;k<4;++k) // iterating over the loop

{

s1=s1+arr[k]; // sum of the array of elements  

}

for(int k=0;k<4;++k) // iterating over the loop

{

if(k<3)

{

printf("%d+",arr[k]); //for display values

}

else

{

printf("%d=",arr[k]);

}

}

printf("%d",s1); // display the total sum

return 0;

}

Output:

4+6+9+12=31

Explanation:

  • Declared a variable sum of int type also declare an array "arr" of int type.
  • Iterating over the for loop to add the values of the array in the "sum" variable.
  • Again iterting the for loop  to print the values from the array in the format as given in the question .

You might be interested in
What problems does the swim coach have? Use details from the story to support your answer.
kobusy [5.1K]
Swimming questions that you need to know how to do
5 0
3 years ago
Which line of code outputs the decimal portion of a float stored in the variable x? print (x % 1000) print (x) O print (x / 1000
vlabodo [156]

print(x - int(x))

int(x) will round the float down to the nearest whole number x - int(x) subtracts that rounded value from the original float. This will leave the remaining decimal portion.

I hope this helps!

6 0
3 years ago
PYTHON
Nina [5.8K]

Answer:

This is one of the efficient ways to find the number of occurrences of a given number in a list:

<h3><u>def find_num(arr,n):</u></h3><h3><u>    return len([count for count in arr if count == n])</u></h3><h3><u>print(find_num([0,1,1,1,0],1))</u></h3>

If you want a simpler version, you can try this:

<h2><u>def find_num(arr,n):</u></h2><h2><u>    count = 0 </u></h2><h2><u>    for i in range(len(arr)): </u></h2><h2><u>        if arr[i]==n: </u></h2><h2><u>            count += 1 </u></h2><h2><u>    return count</u></h2><h2><u>print(find_num([0,1,1,1,0],1))</u></h2>

This is the simplest method:

<h2><u>arr = [0,1,1,1,0]</u></h2><h2><u>print(arr.count(1))</u></h2>

I think I gave you enough examples. This should get you started off easily.

If you need an explanation, I am happy to help you. BTW I started python 6 months back so even I am pretty new to this.

4 0
3 years ago
Create a program that compares the unit prices for two sizes of laundry detergent sold at a grocery store.
astraxan [27]

Complete Question:

Create a program that compares the unit prices for two sizes of laundry detergent sold at a grocery store. Console Price Comparison Price of 64 oz size: 5.99 Price of 32 oz size: 3.50 Price per oz (64 oz): 0.09 Price per oz (32 oz): 0.11

Using Python

Answer:

<em>This program does not make use of comments (See explanation section)</em>

price64 = float(input("Price of 64 oz size: "))

price32 = float(input("Price of 32 oz size: "))

unit64 = price64/64

unit32 = price32/32

print("Unit price of 64 oz size: ", round(unit64,2))

print("Unit price of 32 oz size: ", round(unit32,2))

if unit64>unit32:

     print("Unit price of 64 oz is greater" )

else:

     print("Unit price of 32 oz is greater" )

Explanation:

This line prompts the user for the price of 64 oz size

price64 = float(input("Price of 64 oz size: "))

This line prompts the user for the price of 32 oz size

price32 = float(input("Price of 32 oz size: "))

This line calculates the unit price of 64 oz size

unit64 = price64/64

This line calculates the unit price of 32 oz size

unit32 = price32/32

This next two lines print the unit prices of both sizes

print("Unit price of 64 oz size: ", round(unit64,2))

print("Unit price of 32 oz size: ", round(unit32,2))

The next line compares the unit prices of both sizes

if unit64>unit32:

This line is executed if the unit price of 64 oz is greater than 32 oz

     print("Unit price of 64 oz is greater" )

else:

This line is executed, if otherwise

     print("Unit price of 32 oz is greater" )

4 0
3 years ago
_______ _____ is the process of creating usable computer pograms and applications and the theories behind those processes. Quest
stepladder [879]
<span>The correct answer is


C. Computer Science</span>
7 0
3 years ago
Read 2 more answers
Other questions:
  • One form of the IF field is called an If…Then…Else: If a condition is true, then perform an action; else perform a different act
    15·2 answers
  • Write three statements to print the first three elements of array runTimes. Follow each statement with a newline. Ex: If runTime
    12·1 answer
  • Controls that are used to assess whether anything went wrong, such as unauthorized access attempts, are called ________ controls
    5·2 answers
  • A computer is a(n) ____ device, operating under the control of instructions stored in its own memory, that can accept data, proc
    9·1 answer
  • What command will disable dns lookup to prevent the router from attempting to translate incorrectly entered commands as though t
    6·1 answer
  • What term identifies the physical interface between a computer and its peripherals?
    5·1 answer
  • A ________ determines what cpus a system can use, what integrated ports the system can provide without use of third-party produc
    5·1 answer
  • Is e commerce a challenge or opportunity to the freight forwarder
    8·1 answer
  • Give me reasons why Harry Potter is bad and anime is better
    5·1 answer
  • Data is stored on ________ using a laser to either melt the disc material or change the color of embedded dye.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!