Sunteți pe pagina 1din 12

1 Write a function in C++, which accepts an integer array and its size as parameters and rearrange the array

in reverse. Example if an array of five members initially contains the elements as 6,7,8,13,9,19 Then the function should rearrange the array as 19,9,13,8,7,6

2 Write a function in C++, which accept an integer array and its size as arguments and swap the elements of every even location with its following odd location. Example : if an array of nine elements initially contains the elements as 2,4,1,6,5,7,9,23,10 Then the function should rearrange the array as 4,2,6,1,7,5,23,9,10

3 Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having odd values with thrice and elements having even values with twice its value. Example : If an array of five elements initially contains the elements 3,4,5,16,9 Then the function should rearrange the content of the array as 9,8,15,32,27

5 Write a function in C++ which accepts an integer array and its size as argument and exchanges the value of first half side elements with the second half side elements of the array. Example : If an array of eight elements has initial content as 2,4,1,6,7,9,23,10 The function should rearrange the array as 7,9,23,10,2,4,1,6.

6. Write a function in c++ to find and display the sum of each row and each column of 2 dimensional array. Use the array and its size as parameters with int as the data type of the array.

8 Write a c++ function to shift all the negative numbers to left and positive number in the right side. Ex: if the array contains {1,-2,3,-4,5,-6} then it should re arrange the array as {-2,-4,-6,1,3,5}

9 Define a function SWPCOL() in C++ to swap ( interchange) the first column elements with the last column elements, for a two dimensional array passed as the argument of the function. Example : if the two dimensional array contains 2149 1377 5863 7212 After swapping of the content of 1st and last column, it should be 9142 7371 3865 2217

10 Define a function SWPROW() in C++ to swap ( interchange) the first row elements with the last row elements, for a two dimensional array passed as the argument of the function. Example : if the two dimensional array contains 2149 5863 1377 7212 After swapping of the content of the array will be 7212 5863 1377 2149

11 Write a function in C++ to print the product of each column of a 2D integer array passed as the argument of the function Example : if the two dimensional array contains 2149 1377 5863 7212 Then the output should appears as Product of Column1 = 70 Product Column2 = 48 Product of column3= 168 Product of Column4=378

12. Write a function in C++ to print the product of each row of a 2D integer array passed as the argument of the function Example : if the two dimensional array contains 2149 1377 5863 7212 Then the output should appears as Product of Row1 = 72 Product Row2 = 147 Product of Row3= 720 Product of Row4=28

13. Write a function which accept 2D array of integers and its size as arguments and displays the sum of elements which lie on diagonals. [Assuming the 2D array to be a square matrix with odd dimension ie 3 x 3 , 4 x 4 etc ] Example of the array content is 543 678 129 Output through the function should be Diagonal One Sum : 21 Diagonal Two: 11

14. Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays the elements of middle row and the elements of middle column. [Assuming the 2D array to be a square matrix with odd dimension ie 3 x 3 , 5 x 5, 7 x 7 etc ] Example of the array content is 543 678 129 Output through the function should be Middle row: 6 7 9 Middle Column 4 7 2

15. Write a function in C++ which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format If the array is 1,2,3,4,5,6 The resultant 2D array is 123456 123450 123400 123000 120000 100000

16. Write a function in C++ which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format If the array is 1,2,3,4,5,6 The resultant 2D array is 123456 012345 001234 000123 000012 000001

17. Write a function in C++ which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format If the array is 1,2,3,4,5,6 The resultant 2D array is 100000 120000 123000 123400 123450 123456

18. Write a user defined function named upperhalf() which takes a 2D array A, with size n rows and n cols as arguments and print the upper half of the matrix. Example if the array contains then upper half is 123 123 678 78 234 4

19. Write a user defined function lowerhalf() which takes a 2D array, with size n rows and n cols as argument and prints the lower half of the matrix Eg:if the array contains then lower half is 123 1 567 56 912 912

20 Write the function to find the largest and second largest number from a two dimensional array. The function should accept the array and its size as argument.

21 Write a function in C++ to merge the contents of two sorted arrays A & B into third array C. Assuming array A is sorted in ascending order, B is sorted in descending order, the resultant array is required to be in ascending order.

22. Write a function in C++ to merge the contents of two sorted arrays A & B into third array C. Assuming array A is sorted in descending order, B is sorted in descending order, the resultant array is required to be in ascending order.

23. Write a function sum() in C++ with two arguments/parameters-double U and int n. the function should return a value of type double and it should perform sum of the following series: 1 U 1/ 2! + U 3 /6! - U 5/10! ++- U2n-1 /(2n)!

24. Given two arrays of integers X and Y of sizes m and n respectively. Write a function named MERGE() which will produce third array named Z, such that the following sequence is followed. (i) All odd numbers of X from left to right are copied into Z from left to right. (ii) All even numbers of X from left to right are copied into Z from right to left. (iii) All odd numbers of Y from left to right are copied into Z from left to right. (iv) All even numbers of Y from left to right are copied into Z from right to left.

27. Write a function BsearchArr that receive an integer array of size 20 and an element (that is to be searched), as arguments and it will search the element from the array by using binary search method. The function will display a message if the element is found or not found.

28. Write definition for a function AddSum() in C++ with arguments/parameters-double x and int n. the function should return a value of type double and it should perform sum of the following series: 1/x-2!/x2+4!/x3+6!/x4+8!/x5.upto n terms

29. WAF to count the vowels, consonants and digits in a string which has been passed as an argument to this function.

30. Write a program in C++ which accepts a character array and its size as an arguments and reverse that array without using second array and library function. Example : if the array is having Computer Science. Then after reversal it should rearranged as ecneicS retupmoC.

31. WAF which is passed an integer n and should find the sum of the series given below: (1)1+(1+2) 2+(1+2+3) 3+(1+2+3+4) 4 .upto N terms

32. WAF which is passed a string and a character. The function should Each occurrence of the given character (regardless of its case) is converted to opposite case. For example, if the string entered is: A a b r A c a d and the character as A or a then the output string should be aAbracAd See each a or A is converted to opposite case i.e. upper to lower or vice versa.

33. WAF which is passed a string to check whether a string entered by the user is a palindrome or not.

34 WAP to read a name (first, middle and last name) from a user and produce an output where the first letter of each name is capatilised and rest all in lower case. Ex. If the input string is sUmiT kUmAr KhuRana then it should be converted to Sumit Kumar Khurana

35. WAF which is passed an integer to find if the number entered by the user is an Armstrong number or not.

36. Write a program to find a substring in the given string. If you find the string then also display the position where it is in the main string.

37. WAF which is passed a string and display the words from the last. E.g. if the string is Computer hardware and software then it should display software and hardware Computer.

38. WAF which is passed a string and that function should count the words and spaces in a string.

39. WAF which is passed a string and that function should cyclic the string. E.g. If the string is : Chetna then it should print as Chetna hetnaC etnaCh tnaChe naChet aChetn 45. Write a function which accept 2D array of integers and its size as arguments and displays the elements which lie on diagonals. [Assuming the 2D array to be a square matrix with odd dimension ie 3 x 3 , 4 x 4 etc ] Example of the array content is 543 678 129 Output through the function should be Diagonal One: 5 7 9 Diagonal Two: 3 7 1

46. WAF which is passed an integer number and that function will return 0 if the number is not perfect no. otherwise return 1. 47. WAF which is passed an integer number and that function will return 1 if the number is prime no. otherwise return 0. 48. WAF which is passed an integer number and that function will return 1 if the number is palindrome otherwise return 0.

49. WAF int SKIPSUM(int A[][4],int N,int M) in c++ to find and return the sum of elements from all alternate elements of a 2-d array starting from A[0][0] Ex: If the array contains 3 4 2 [0][0] [0][1] [0][2] 7 [1][0] 8 [2][0] 9 [1][1] 5 [2][1] 3 [1][2] 4 [2][2] 5 [0][3] 2 [1][3] 1 [2][3]

The function should add elements A[0][0],A[0][2],A[1][0],A[1][2],A[2][0],[2][2]

Q50. WAF in C++ to print the sum of all the values which are either divisible by 5or 7 in a 2 D array passed as the argument to the function along with the row and column size.

Q51. WAP that would accept a one dimensional integer array NUMBERS. It should rearrange the contents of the array in such a way that the values of alternate locations of the array are exchanged.(assume the size of the array to be even). Ex. If the array initially contains 2,15,3,14,7,9,19,6,1,10 then after rearranging the array should contain 15,2,14,3,9,7,6,19,10,1

Q52. WAF which is passed a string, function has to check whether a string entered by the user is a palindrome or not. If it is a palindrome it should return 1 else return 0.

Q53. Write a program in c++ which accepts a 2D array of integers, number of rows and number of columns as arguments and assign the elements which are divisible by 3 or 5 into a one dimensional array of integers. If the 2D array is arrays is 12 , 3 , 9 , 24 , 25 , 45 , 9 , 5 , 18
12 24 19 11 3 25 32 5 9 16 45 28 14 31 The 27 18

resultant 1D

54. Write a function which accept 2D array of integers and its size as arguments and the elements which are divisible by 7 multiply them with 7 and rest divide by 3. 55. WAF which is passed a string and that function should count words in a string irerspective of spaces. 56. WAF which is passed a string and that function should find the frequency of every alphabet in a string. 57. WAF which is passed two strings and that function should find whether 2 strings entered by the user is a anagram or not.

58. WAF which is passed a string and that function should count uppercase vowel, lowercase vowel and alphabets. 59. WAF which is passed a string and that function should count alphabets, spaces and digits.

60.WAF which is passed a string and that function should check the input string is palindrome or not.

61.WAF which is passed a string and that function should count and display the number of blanks in the given string and replace every blank with % sign.

62.WAF which is passed a string and that function should count and display the number of vowels and digits in the given string. 63. Write a function seqsum( ) in C++ with two arguments, double x and int n. The function should return a value of type double and it should find the sum of the following series.

1+ x/2! + x2/4! + x3/6! + x4/8! + x5/10! + ----------+ xn/(2n)!


64. A struct student has three data members: name, roll number, marks of 5 subjects. Write a function to assign streams on the basis of table given below: Average marks Stream 96% and above Computer science 91%- 95% Electronics 86%-90% Mechanical 81% - 85% Electrical 76%- 80% chemical 71% - 75% civil 65. WAP to accept the name and total marks of 20 students in an array. Display the names of the students (including marks) securing the highest and lowest using structure. 66. Declare a structure having the following members: code, name, no. of units consumed and bill_amount. The bill is to be calculated according to the following conditions.

No. of Units For the first 100 units For the next 200 units For the next 300 units Beyond 600 units

Amount per unit Rs. .8o per unit Rs. 1.20 per unit Rs. 2.0 per unit Rs. 3.0 per unit

67. Declare a structure to represent a complex number ( a number having real and imaginary part) WAP to add, subtract 2 complex numbers. 68. WAP to store information of country, its capital and per capita income, and perform the following operation: a) display country and per capita, given its capital b)display capital and per capita income, given its country c) display country and capital, given its per capita income. 69 WAP to create distance structure, and add two distance structure variable (such that inches >=12 will become 1 feet). Print the final answer on screen.

S-ar putea să vă placă și