
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Please do number 1 using C language

Transcribed Image Text:1
1. write a program using an array to perform the sum and average for the zig zag elements shown in
the above figure.
Expert Solution

arrow_forward
Step 1
List of variables used:
- Considering an array "arr" of rows: 3 and columns: 5.
- Variables i,j,k for looping purpose.
- Array sum[2]: to store the sum of given figures zigzag elements.
- Array avg[2]: to store the average of zigzag elements given figures.
- Array count[2]: To count the number of elements in zigzag
Finding and calculating sum and average of first zigzag elements:
- variables i and j are used for accessing elements in the array.
- Where i represents the row.
- where j represents the column.
- Initialize i=0, j=0 means accessing first-row first-element.
- Loop for accessing rows begins with termination condition i<3
- Loop for accessing columns begins with termination condition j<=(i+1)
- Adding arr[i][j] to sum[0].
- sum[0] += arr[i][j]
- Increase count value by 1.
- count[0]++
- Increase j value by 1.
- If the termination condition j<=(i+1) satisfies, exit from the loop. Otherwise, repeat the loop.
- Adding arr[i][j] to sum[0].
- Increase value of i by 1.
- If the termination condition i<3 satisfies, exit from the loop. Otherwise, repeat the loop.
- Loop for accessing columns begins with termination condition j<=(i+1)
- Calculating average of zigzag elemnts.
- avg[0]=sum[0]/count[0]
Finding and calculating sum and average of second zigzag elements:
- variables i and j are used for accessing elements in the array.
- Where i represents the row.
- where j represents the column.
- Initialize i=0, j=0 and k=4.
- Loop for accessing rows begins with termination condition i<3
- Loop for accessing columns begins with termination condition j<5
- if value of i equals to j ( j == i) then
- Adding arr[i][j] to sum[1].
- sum[1] += arr[i][j]
- Increase count value by 1.
- count[1]++
- Adding arr[i][j] to sum[1].
- if value of k equals to j ( j == k) and value of i not equals to j (j != i) then
- Adding arr[i][j] to sum[1].
- sum[1] += arr[i][j]
- Increase count value by 1.
- count[1]++
- Adding arr[i][j] to sum[1].
- Increase j value by 1.
- If the termination condition j<5 satisfies, exit from the loop. Otherwise, repeat the loop.
- if value of i equals to j ( j == i) then
- Increase value of i by 1.
- decrement value of k by 1.
- If the termination condition i<3 satisfies, exit from the loop. Otherwise, repeat the loop.
- Loop for accessing columns begins with termination condition j<5
- Calculating average of zigzag elemnts.
- avg[1]=sum[1]/count[1]
arrow_forward
Step 2
CODE:
#include <stdio.h>
int main()
{
// Declaring variables for array, sum, average and looping.
int arr[3][5], sum[2] = {0};
float avg[2] = {0};
int i, j, k, count[2] = {0};
//Reading array elements
printf("Enter Array element of size 3 * 5:");
for (i = 0; i < 3; i++)
{
printf("\nEnter %d row 5 elements:\n", i + 1);
for (j = 0; j < 5; j++)
{
scanf("%d", &arr[i][j]);
}
}
//Displaying Array elements
printf("\nArray elements:");
for (i = 0; i < 3; i++)
{
printf("\n");
for (j = 0; j < 5; j++)
{
printf("%d\t", arr[i][j]);
}
}
// calculating sum and average of first zigzag elements
//Displatying First set of zigzag elements
printf("\nFirst zigzag puzzle:");
for (i = 0; i < 3; i++)
{
printf("\n");
for (j = 0; j <= (i + 1); j++)
{
printf("%d\t", arr[i][j]);
sum[0] += arr[i][j];
count[0]++;
}
}
avg[0] = (float)sum[0] / count[0];
// calculating sum and average of second zigzag elements
//Displatying second set of zigzag elements
printf("\nSecond zigzag puzzle:");
for (i = 0, k = 4; i < 3; i++, k--)
{
printf("\n");
for (j = 0; j < 5; j++)
{
if (j == i)
{
printf("%d", arr[i][j]);
sum[1] += arr[i][j];
count[1]++;
}
if (j == k && i != j)
{
printf("%d", arr[i][j]);
sum[1] += arr[i][j];
count[1]++;
}
printf(" \t");
}
}
avg[1] = (float)sum[1] / count[1];
//Dsipalying sum and averages of both first and second set of zigzag elements.
printf("\nFirst zigzag puzzle:");
printf("\n\tSum : %d", sum[0]);
printf("\n\tAverage : %f", avg[0]);
printf("\nSecond zigzag puzzle:");
printf("\n\tSum : %d", sum[1]);
printf("\n\tAverage : %f", avg[1]);
}
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- C Programming Language Note: Input and Output Must be the same as in case above Use C Language Only need the answer ASAParrow_forwardCode in C language. Follow instructions in photo. Use text provided as input.txt file. A1, A2 20294 Lorenzana Dr Woodland Hills, CA 91364 B1, B2 19831 Henshaw St Culver City, CA 94023 C1, C2 5142 Dumont Pl Azusa, CA 91112 D1, D2 20636 De Forest St Woodland Hills, CA 91364 A1, A2 20294 Lorenzana Dr Woodland Hills, CA 91364 E1, E2 4851 Poe Ave Woodland Hills, CA 91364 F1, F2 20225 Lorenzana Dr Los Angeles, CA 91111 G1, G2 20253 Lorenzana Dr Los Angeles, CA 90005 H1, H2 5241 Del Moreno Dr Los Angeles, CA 91110 I1, I2 5332 Felice Pl Stevenson Ranch, CA 94135 J1, J2 5135 Quakertown Ave Thousand Oaks, CA 91362 K1, K2 720 Eucalyptus Ave 105 Inglewood, CA 89030 L1, L2 5021 Dumont Pl Woodland Hills, CA 91364 M1, M2 4819 Quedo Pl Westlake Village, CA 91362 I1, I2 5332 Felice Pl Stevenson Ranch, CA 94135 I1, I2 5332 Felice Pl Stevenson Ranch, CA 94135 N1, N2 20044 Wells Dr Beverly Hills, CA 90210 O1, O2 7659 Mckinley Ave Los Angeles, CA 90001arrow_forwardWhere should I utilize dynamic versus static typing?arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education