Question

Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays) Part 1: Create...

Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays)

Part 1:

Create a 2-by-3 integer array and initialize it with 6 integers of your choice.

Using nested for loops, display the contents of the array on the screen

Part 2: (Continue on part 1)

Display the sum of all the integers in the array that you created in part 1.

Create a function

Part 3:

Create a function that will display the elements of the array you created in part 1. Call the function from main to display the 6 integers.

What to submit:

  1. The .c code for the programming questions
  2. Snap shots of your answers

Homework Answers

Answer #1

The code is written in C

#include <stdio.h>

void display(int arr[][3])
{
        for(int i=0;i<2;i++)
        {
                for(int j=0;j<3;j++)
                {
                        printf("%d ",arr[i][j]);      // Printing the array element
                }
                printf("\n");
        }
}

int find_sum(int arr[][3])
{
        int sum=0;
        for(int i=0;i<2;i++)
        {
                for(int j=0;j<3;j++)
                {
                        sum+=arr[i][j];              // Adding the value of array element to the sum
                }
        }
        return sum;
}

int main(void) {
        
        int arr[2][3];                       // PART 1 starts
        
        int number=1;
        
        for(int i=0;i<2;i++)                                   
        {
                for(int j=0;j<3;j++)
                {
                        arr[i][j]=number;            // Initializing the array element with a number
                        number++;
                        printf("%d ",arr[i][j]);     // Printing the array element
                }
                printf("\n");
        }                                    // PART 1 ends
        
        
        int sum = find_sum(arr);             // PART 2
        printf("%s","The sum is: ");
        printf("%d\n",sum);
        
        display(arr);                        // PART 3
        
}

Following is the output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Part 1: Determine what is wrong (if any) with the following statements int A[4] = {...
Part 1: Determine what is wrong (if any) with the following statements int A[4] = { 1, 2, 3, 4, 5}; int A[4] = {1,2}; int A[4] = [1,2,3,4]; Part 2: Create one dimensional array and save the following integers in it:  2, 3, 6, 7, 10, 12. Display the values on the screen. (for example, a[0] = 2, a[1] = 3, etc.) Part 3: Write a program to read 5 integers from the user. Save these integers in an array...
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
Build two simple arrays (Integer and String) of 6 in length. Convert the two arrays into...
Build two simple arrays (Integer and String) of 6 in length. Convert the two arrays into a List type using an ArrayList type. A static method Array2Collection generic method is provided for that. From the List, display the contents of the two arrays in the forward or backward order: (without using an index for loop) //Code for converting Array to a Collection type static <T> void Array2Collection(T[] a, Collection<T> c) {     for (T x : a) {         c.add(x);...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
Create a class StacktwoPopArr using Arrays, Change the pop function so that two elements get popped...
Create a class StacktwoPopArr using Arrays, Change the pop function so that two elements get popped everytime instead of the one. If there is only one element in the stack, just pop the one element and report that the stack is now empty. If stack is empty, it should just report that stack is empty. All other functions for StackArray remain the same. using java StackArray.java: public class StackArray {       private final int size = 20; //Size of...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
Sailboat Race Ranking Programming Challenge 7 in Chapter 3 asked yo uto create an application that...
Sailboat Race Ranking Programming Challenge 7 in Chapter 3 asked yo uto create an application that tracks the performance of sailboats in five races. The version of the application only calculated the total points for each boat. In this new version, you are asked to rank the boats, assigning them first, second, and third place. Also, you will need to perform the following input validations: 1. All input value must be valid integers. 2. In any column (a single race),...
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...
Your C program will do the following : Must use at least 2 function prototypes &...
Your C program will do the following : Must use at least 2 function prototypes & definitions . You can also use repetitions , control structures . You re not allowed any type of global arrays, or global variables. You are only allowed to use 2 dimensional arrays. 1. In your main program, create a array of size 7 X 7. 2. Create a function that accepts the empty array. The function will initiate the to zero. Then, the function...
Assignment 7 This is a two-part assignment. Students will create and submit 3 scripts. Here are...
Assignment 7 This is a two-part assignment. Students will create and submit 3 scripts. Here are the instructions: Before You need to Import the books_sc database via phpMyAdmin Script 1 Create a php file to connect to the books_sc database. You can name this file connect.php. This separate file will be ‘included’ in the other scripts, script 2 and script 2 Script 2 (25 points – to receive these points, you need to have the connect.php file created and submitted)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT