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

Assignment 5

Uploaded by

dinaarshad439
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)
12 views

Assignment 5

Uploaded by

dinaarshad439
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/ 3

Assignment 5

1. Write a program to print all elements of an array using the function.


Input
Input elements: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Output
Array elements: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

2. Write a program to find the sum of array elements using the function
Input
Input array elements: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Output
Sum of array: 55

3. Write a function takes a matrix then return the sum of main diagonal (major
diagonal) elements of the matrix.
Input :
123
456
789
Output: 15

4. Write a function takes string then return the most repeated char
Input aaabca
Output: a

5. Write a function receive string and convert it to lowercase


Input: AbCD
Output: abcd

6. Write a function to check all chars are digits or not


input: 12354 Output: True
Input: a123 Output: False

7. Write a function to reverse int using recursion


input: 5324 Output:4235

8. Write a function to return the max digit in int


Input:5234 Output: 5

9.Write a C program to find reverse of a given string using loop.


Input: Hello Output: olleH

10.Write a CPP program to count the total number of words in a string.


Input string: I love Code.
Output
Total number of words: 3
Pointer

11. Write a function that takes an array of integers with size 10 and return an
array with EVEN numbers only.

Input: { 4,7,3,9,2,13,6,7,8,11}
Output: { 4,2,6,8}

12. Write a function to swap two numbers Using Pointer and display in main function
the values before and after swapping,

13. Write a program to dynamically allocate memory for an integer array, read values
from the user, and print them.
Input: 1 9 2 1 5
Output: 1 9 2 1 5

14. Find the output : (Don’t USE Visual Studio or Codeblocks)


#include <iostream>
using namespace std;
int main()
{
int arr[] = {4, 5, 6, 7};
int *p = (arr + 1);
cout << *arr + 9;
return 0;
}

a) 12 b) 14 c) 13 d) Error
15. What will happen in this code? (Don’t USE Visual Studio or Codeblocks)
int a = 100, b = 200;
int *p = &a, *q = &b;
p = q;
a) b is assigned to a
b) p now points to b
c) a is assigned to b
d) q now points to a
Bounce:

1. Write a C++ program to change every letter in a given string with the letter
following it in the alphabet (i.e., a becomes b, p becomes q, z becomes a).
Example:
Input: w3resource
Output: x3sftpvsdf

2. Write a C++ program to capitalize the first letter of each word in a given string.
Words must be separated by only one space.
Example:
Sample Input: cpp string exercises
Sample Output: Cpp String Exercises

3. Complete the function/method so that it returns the url with anything after the
anchor (#) removed.
Examples
Input: www.code.com#about
Output www.code.com
Input: www.code.com?page=1
Output: www.code.com?page=1

You might also like