Ask Question
19 November, 01:34

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

+2
Answers (1)
  1. 19 November, 03:15
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers