100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
C++ Practice questions $2.84   Add to cart

Other

C++ Practice questions

 5 views  0 purchase
  • Course
  • Institution

Questions to practice your c++ coding skills. Questions with expected input and output provided.

Preview 1 out of 1  pages

  • May 14, 2023
  • 1
  • 2022/2023
  • Other
  • Unknown
avatar-seller
University of the Witwatersrand
Course: Computer science I, Introduction to algorithms and programming
Practice problems for C++

1. Write a program that takes in two integers as input and displays the result of the following operations
on them:
a. Addition
b. Subtraction
c. Multiplication
d. Division
Sample input: 4 2
Expected output:
Addition: 6
Subtraction: 2
Multiplication: 8
Division: 2

2. Write a program that takes in a positive integer as input and checks if it is a prime number or not.
Display "Prime" if it is prime and "Not prime" otherwise.
Sample input: 7
Expected output: Prime

3. Write a program that takes in a string as input and displays the reverse of the string.
Sample input: "Hello World"
Expected output: "dlroW olleH"

4. Write a program to compute the sum of the first n natural numbers using the formula n(n+1)/2.
Sample input: 5
Expected output: 15

5. Write a program that takes in a string as input and checks if it is a palindrome or not. Display
"Palindrome" if it is a palindrome and "Not a palindrome" otherwise.
Sample input: "racecar"
Expected output: Palindrome

6. Write a program that takes in an integer array of size n as input and displays the maximum and
minimum elements in the array.
Sample input: {4, 2, 5, 1, 3}
Expected output: Maximum: 5, Minimum: 1

7. Write a program to sort the elements of an integer array in ascending order using bubble sort.
Sample input: {64, 34, 25, 12, 22, 11, 90}
Expected output: {11, 12, 22, 25, 34, 64, 90}

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller MsDipale. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $2.84. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

60924 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$2.84
  • (0)
  Add to cart