0% found this document useful (0 votes)
4 views

CPP Inputs & Outputs

Uploaded by

bhartiayur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CPP Inputs & Outputs

Uploaded by

bhartiayur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Sum and Product of Digits of an Integer

Input:
Enter an integer: 1234

Output:
Sum of digits: 10
Product of digits: 24

2. Reverse a Number

Input:
Enter a number: 1234

Output:
Reversed number: 4321

3. Sum of First nn Terms of the Series S=1+12+13+…S = 1 + \frac{1}{2} + \frac{1}{3} + \dots

Input:
Enter the number of terms (n): 4

Output:
Sum of the series: 2.08333

4. Sum of First nn Terms of the Alternating Series S=1−2+3−4+…S = 1 - 2 + 3 - 4 + \dots

Input:
Enter the number of terms (n): 5

Output:
Sum of the series: 3

5. Check Palindrome String

Input:
Enter a string: radar

Output:
The string is a palindrome.

6. Prime Number Check and Prime Numbers Less Than 100

Input 1:
Enter a number: 23
Output 1:
23 is a prime number.

Output 2:
Prime numbers less than 100:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

7. Factors of a Number

Input:
Enter a number: 12

Output:
Factors of 12 are: 1 2 3 4 6 12

8. Swap Two Numbers Using a Macro

Input:
Enter two numbers: 5 10

Output:
Before swapping: x = 5, y = 10
After swapping: x = 10, y = 5

9. Print Star Triangle

Input:
Enter the number of lines: 3

Output:

***

*****

10. Operations on an Array

Input:
Enter the number of elements: 5
Enter the elements: 1 2 2 3 4

Output:
Even elements: 2 2 4
Odd elements: 1 3
Sum: 12, Average: 2.4
Max: 4, Min: 1
Array without duplicates: 1 2 3 4
Array in reverse order: 4 3 2 1

11. Count Occurrences of Each Alphabet in Command-Line Arguments

Input:
(Provided as command-line arguments: Hello World)

Output:
Occurrences of each alphabet:
d: 1, e: 1, h: 1, l: 3, o: 2, r: 1, w: 1

12. Swap Two Numbers Using Pointers

Input:
Enter two numbers: 6 9

Output:
Before swapping: x = 6, y = 9
After swapping: x = 9, y = 6

13. Alter Contents of Variables via Function

Input:
Enter two numbers: 7 8

Output:
Before alteration: x = 7, y = 8
After alteration: x = 17, y = 16

14. Compute Area and Circumference of a Circle

Input:
Enter the radius of the circle: 5

Output:
Area: 78.53975, Circumference: 31.4159

15. Sum of nn Elements Using Dynamic Memory Allocation

Input:
Enter the number of elements: 3
Enter the elements: 1 2 3

Output:
Sum of elements: 6
16. Merge Two Sorted Arrays

Input:
Enter the size of the first array: 3
Enter the sorted elements of the first array: 1 3 5
Enter the size of the second array: 3
Enter the sorted elements of the second array: 2 4 6

Output:
Merged sorted array: 1 2 3 4 5 6

17. Fibonacci Series (Recursion and Iteration)

Input:
Enter the number of terms: 6

Output (Iteration):
Fibonacci series (Iteration): 0 1 1 2 3 5

Output (Recursion):
Fibonacci series (Recursion): 0 1 1 2 3 5

18. Factorial (Recursion and Iteration)

Input:
Enter a number: 5

Output (Iteration):
Factorial (Iteration): 120

Output (Recursion):
Factorial (Recursion): 120

19. GCD (Recursion and Iteration)

Input:
Enter two numbers: 24 36

Output (Iteration):
GCD (Iteration): 12

Output (Recursion):
GCD (Recursion): 12

Made by Atul

You might also like