Question

C++

This week, you are to create two separate programs, first using a simple array and the second using a 2D-array (matrix). [Par

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part 1 code

#include<bits/stdc++.h>
using namespace std;
int main()
{
   int arr[10];
   cout<<"Enter 10 Integers "<<endl;
   for(int i=0;i<10;i++)
   {
       cin>>arr[i];
   }
   int sum=0;
   int maximum=INT_MIN;
   int minimum=INT_MAX;
   for(int i=0;i<10;i++)
   {
       sum+=arr[i];
       if(maximum<arr[i])
       {
           maximum=arr[i];
       }
       if(minimum>arr[i])
       {
           minimum=arr[i];
       }
   }
   cout<<"Sum of 10 integers are "<<sum<<endl;
   cout<<"Minimum value from 10 integers "<<minimum<<endl;
   cout<<"Maximum value from 10 integers "<<maximum<<endl;
}

part 2 code

#include<bits/stdc++.h>
using namespace std;
int main()
{
   int A[2][2],B[2][2],C[2][2];
   cout<<"\n";
   cout<<"Elements are entered row-wise \n"<<endl;
   cout<<"Enter the values in first matrix \n "<<endl;
   for(int i=0;i<2;i++)
   {
       for(int j=0;j<2;j++)
       {
           cin>>A[i][j];
       }
   }
   cout<<"The values of matrix is A \n"<<endl;
   for(int i=0;i<2;i++)
   {
       for(int j=0;j<2;j++)
       {
           cout<<A[i][j]<<" ";
       }
       cout<<endl;
   }
   cout<<"Enter the values in second matrix \n "<<endl;
   for(int i=0;i<2;i++)
   {
       for(int j=0;j<2;j++)
       {
           cin>>B[i][j];
       }
   }
   cout<<"The values of matrix is B \n"<<endl;
   for(int i=0;i<2;i++)
   {
       for(int j=0;j<2;j++)
       {
           cout<<B[i][j]<<" ";
       }
       cout<<endl;
   }
   cout<<"The values of matrix C is \n "<<endl;
   for(int i=0;i<2;i++)
   {
       for(int j=0;j<2;j++)
       {
           C[i][j]=A[i][j]+B[i][j];
       }
   }
   for(int i=0;i<2;i++)
   {
       for(int j=0;j<2;j++)
       {
           cout<<C[i][j]<<" ";
       }
       cout<<endl;
   }  
}

Add a comment
Know the answer?
Add Answer to:
C++ This week, you are to create two separate programs, first using a simple array and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For the program described below, document your code well. Use descriptive identifier names. Use s...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • For the program described below, document your code well. Use descriptive identifier names. Use spaces and...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • using C language Create an array of doubles with 5 elements. In the array prompt the...

    using C language Create an array of doubles with 5 elements. In the array prompt the user to enter 5 temperature values (in degree Fahrenheit). Do this within main. Create a user defined function called convert2Cels. This function will not return any values to main with a return statement. It should have parameters that include the temperature array and the number of elements. The function should convert the values for Fahrenheit to Celsius and save them back into the same...

  • Write a java program: Create a method fillRandom() that accepts an array of int as input...

    Write a java program: Create a method fillRandom() that accepts an array of int as input and populates it with random numbers in the range -999 to 1000 Explicitly store zero in index [0] and 900 in index [1]. (0 and 900 will be used as search keys) Create a method DisplayLastInts() that accepts an array of int as input and displays the last hundred elements to the screen in rows of 10 elements. Format the output so the 10...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask...

    Create the following programs in Java {Java1 difficulty} [Please create as simple as possible] a. Ask the user to enter their favorite number and favorite word. Pass both of these values to a method that will print the favorite word vertically the favorite number of times. b. Ask the user to enter 2 integers. Pass the integers to 2 different methods: one method to add the integers and print the sum (from the method); the second method to multiply the...

  • Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that...

    Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that holds an array for the integer values 1-10. Pass the array to a method that will calculate the values to the power of 2 of each element in the array. Then return the list of calculated values back to the main method and print the values

  • Write a VBA Sub Program to perform matrices multiplication of matrix A and B using 2D...

    Write a VBA Sub Program to perform matrices multiplication of matrix A and B using 2D arrays. a. Get the number of rows and columns of both matrix A and B from the user, and check if multiplication is possible with matrix A and B. b. If matrices multiplication is possible, input the matrix A and B using arrays and multiply matrix A and B.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT