Ask Question
27 July, 13: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

+3
Answers (1)
  1. 27 July, 15:06
    0
    Following are the code in C language

    #include / / 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.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers