Question

Please work on the following short programming assignments and upload your solutions on a single .txt file. 1. Write a functi

In C++

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

Q1.

Code :

#include <iostream>
using namespace std;

int maximum(int x1, int x2){ //function that return maximum number from two number
   if(x1>x2)
       return x1;
   else
       return x2;
}
int main(){
   int x1,x2;
   cout<< "Enter two number:\n";
   cin >> x1 >> x2; //taking two number from user
   cout << "Maximum number is " << maximum(x1,x2) <<endl; //printing maximum number using help of maximum() function
   return 1;
}

Screenshot :

code:

Output :

Q2.

Code :

#include <iostream>
using namespace std;
int main()
{
   int arr[5], i;
   cout << "Enter five number :\n";

   //taking five number from user and storing into array
   for( i=0; i<5; i++){
   cin >> arr[i];
   }

   //printing elements of array

   cout << "Array:\n";
   for( i=0; i<5; i++){
   cout << arr[i] << " ";
   }
   cout <<endl;

   return 0;
}

Screenshot :

Code :

Output

Q3

Code :

#include <iostream>
using namespace std;
int main()
{
   int arr[5], i;
   cout << "Enter five number :\n";

   //taking five number from user and storing into array
   for( i=0; i<5; i++){
   cin >> arr[i];
   }

   int *p = &arr[0]; //pointer

   //printing elements of array using pointer

   cout << "Array:\n";
   for( i=0; i<5; i++){
   cout << *p << " ";
   p++;
   }
   cout <<endl;

   return 0;
}

Screenshot :

Code :

Output:

Q4.

Code :

#include <iostream>
using namespace std;
int main()
{
   int arr[3][3], i, j;
   cout << "Enter nine number :\n";

   //taking five number from user and storing into array
   for( i=0; i<3; i++){
      
       for(j=0; j<3; j++){
      
           cin >> arr[i][j];
      
      
       }
   }


   //printing elements of array

   cout << "\nArray:\n";
   for( i=0; i<3; i++){
      
       for(j=0; j<3; j++){
      
           cout << arr[i][j] <<"\t";
      
       }

       cout << endl;

   }

   return 0;
}

Screenshot :

Code :

Output :

Add a comment
Know the answer?
Add Answer to:
In C++ Please work on the following short programming assignments and upload your solutions on a...
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
  • C++ programming please Write a program that will display random numbers in order from low to...

    C++ programming please Write a program that will display random numbers in order from low to high. 1. Declare an integer array of size 100. Ask the user how many numbers to work with (n). It can be less than 100. 2. Generate random numbers from 10 to 50. 3. Write the random numbers to an output file named random.dat. Close the file. 4. Open random.dat for input and read the data values into your array. Pass your array to...

  • Please help me to make this c programming code!! Thank you!! Concatenation of two strings using...

    Please help me to make this c programming code!! Thank you!! Concatenation of two strings using pointers Step 1: Ask the user to input ni,n2 and create two character arrays (strings) with ni, n2 size using malloc. Step 2: create a 3rd array using malloc of size(n1+n2). Step 3: Ask the user to input String1 (of size nl) Step 4: Ask the user to input String2 (of size n2) Step 5: concatenate the two arrays and store them in String3...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02:...

    please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02: Large Integer (20 points) In CH, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an...

  • Please solve this C language progrm (2-D Array program) the most basic way ! Thank You!...

    Please solve this C language progrm (2-D Array program) the most basic way ! Thank You! Write a function that takes a 4 x 4 array of integers as its parameter. The function must use two nested for-loops to determine the largest integer in the array as well as its row and column numbers. Recall that C-functions cannot return multiple values. Use pointers in the function parameter list to relay the results to the caller program. Write another function, which...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs...

    Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs six numbers [Keep the numbers in an array]. The numbers must be between 20 and 200, inclusive. If the number is not between 20 and 200, ask for another input. When a number is entered, display the number only if it is not a duplicate of a number already entered. If it is a duplicate of a number already entered, display a message that...

  • As we continue with our study of programming fundamentals, here is a short extra credit programming...

    As we continue with our study of programming fundamentals, here is a short extra credit programming challenge involving selection control structures. To be specific, the program specifications below and the algorithm you develop and write will involve the set-up and use of either nested if-else statements and/or switch statements. Choose one of the following programming challenges below for this algorithm workbench extra credit programming challenge… ------------------------------------------------------------------------------------------- Finding median Use selection control structures to write a C++ program that determines the...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

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