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
Step-by-step 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 .