Assignment
Assignment
Question A1: WAP to input roll number, name, marks and phone of a student and display the
values.
Question A2: WAP to input roll number, name and marks of a student in 5 subjects and calculate
the total and average marks. Display all the values.
Question A3: WAP to find out the square of a given number.
Question A4: WAP to input a number and print its cube.
Question A5: WAP to input radius and calculate the area and circumference of a circle.
Question A6: WAP to input length and breadth of a rectangle and calculate the area and
perimeter.
Question A7: WAP to input 4 integers a, b, c, d and check that the equation a 3 + b3 +c3 = d3 is
satisfied or not.
Question A8: WAP to input side of a square and calculate the area.
Question A9: WAP to input principle, rate and time from the user and calculate the simple
interest and total amount. Display all the values.
Question A10: WAP to input the number the days from the user and convert it into years, weeks
and days.
Question A11: WAP to input a character and print its ASCII value.
Question A12: WAP to input a number and print its equivalent character code.
Question A13: WAP to find out the quotient and remainder of two numbers. ( Without using
modulus ( % ) operator)
Question A14: WAP to input two numbers and print their quotient and remainder.
Question A15: WAP to input two numbers and print the greatest using conditional operator.
Question A16: WAP to input marks of a student and print the result (pass/fail) using conditional
operator.
Question A17: WAP to input inches from the user and convert it into yards, feet and inches.
Question A18: WAP to find out the area of a triangle.
Question A19: WAP to find whether a given number is even or odd using conditional operator.
Question A20: WAP to find out the greatest of three numbers using conditional operator.
Question A21: WAP to input choice (1 or 2). If choice is 1 print the area of a circle otherwise
print the circumference of circle. Input the radius from user.
Question A22: WAP to input a number. If the number is even, print its square otherwise print its
cube.
Question A23: WAP to input employee code, name and basic salary of an employee and calculate
the following values:
HRA 40 % of basic salary
DA 10 % of basic salary
CCA 5 % of basic salary
GS Basic + HRA + DA + CCA
PF 10 % of GS
IT 10 % of GS
NS GS – (PF + IT)
Display all the values.
Question A24: WAP to input the temperature in Fahrenheit and convert it into Celsius and vice
versa.
Question A25: WAP to swap the values of two integer variables
(a) Using extra variable
(b) Without using extra variable
Question A26: WAP to print the system date.
Question A27: WAP to find the age of a person by the given date of birth.
Question B27: WAP to input the marks in theory and practical and print the result.
Question B28: WAP to input a date (dd / mm / yyyy) and check for the validity of the date.
Question B29: WAP to print counting from 1 to 10.
Question B30: WAP to print counting from 10 to 1.
Question B31: WAP to print counting from 51 to 90.
Question B32: WAP to find out the sum and average of all the numbers within the given range.
Question B33: WAP to print all the numbers falling between 2 numbers entered by the user.
Question B34: WAP to print all the even numbers between 1 and 50.
Question B35: WAP to print all the odd numbers between 1 and 50.
Question B36: WAP to print the sum and average of first n natural numbers.
Question B37: WAP to print the sum and average of first n odd numbers.
Question B38: WAP to print the sum and average of first n even numbers.
Question B39: WAP to print the table of a given number.
Question B40: WAP to input 2 numbers and find out the sum of all the even numbers which are
not divisible by 5 but divisible by 3 and lies between the given two numbers.
Question B41: WAP to input the name and age of a person and print the name as many times as
age.
Question B42: WAP to print whole screen with any character.
Question B43: WAP to print the factorial of a given number.
Question B44: WAP to input a number through the keyboard until a ‘.’. Every time a number is
entered. The program should display whether it is greater than, less than or equal to the previous
number.
Question B45: WAP to check that given number is prime or not.
Question B46: WAP to input a number and count its even and odd digits and find out their sum
separately.
Question B47: WAP to generate divisors of an integer.
Question B48: If a number 972 is entered through the keyboard, your program should print
“Nine Seven Two”. Write the program such that it does this for any positive integers.
Question B49: A positive integer is entered through the keyboard, along with it the base of the
numbering system in which you want to convert this number. WAP to display the number
entered, the base and the converted number.
Question B50: WAP to input a number and separate the number in its individual digit and print
the digits separated from one another by three spaces each.
Question B51: WAP to convert a decimal number to equivalent binary number (fractions also).
Question B52: WAP to convert a decimal number to equivalent octal number.
Question B53: WAP to convert a decimal number to equivalent hexadecimal number.
Question B54: WAP to convert a binary number to the decimal number.
Question B55: WAP to convert a octal number to the decimal number.
Question B56: WAP to convert a hexadecimal number to the decimal number.
Question B57: WAP to convert a octal number to binary number.
Question B58: WAP to convert a hexadecimal number to the binary number.
Question B59: WAP to generate all combinations of 1, 2 and 3.
Question B60: WAP to find out the LCM and GCD of two given numbers.
Question B61: WAP to find out the least common divisor of two integers.
Question B62: WAP to check whether square root of a number is prime or not.
Question B63: WAP to find out the sum of the following series:
(1) 1 + x2/2! + x4/4! + x6/6! + …….xn/n!
(2) 1 - x2/2! + x4/4! - x6/6! + …….xn/n!
(3) 1 + 1/1! + 1/2! + 1/3! + …….
(4) 1 + 1/1! + 2/2! + 3/3! + …….
(5) x + x2/2! + x3/3! + x4/4! + …….xn/n!
(6) x - x2/2! + x3/3! - x4/4! + …….xn/n!
(7) 1 + 1/x + 1/x2 + 1/x3 + 1/x4 +………..
(8) x – x3/3! + x5/5! – x7/7! + x9/9! -…….xn/n!
(9) 1- 2/21 + 3/31 – 4/41 + 5/51……….
(10) 1 + x1/2! + x2/3!...................+ xN/(N+1)!
(11) 1 + x/2! + x2/4! + x3/6! + x4/8! +………..xn/(2n)!
(12) 1 + x/1! + x3/2! + x5/3! + x7/4! +………..x2n-1/n!
(13) 1 + x2/1! + x4/2! + x6/3! + x8/4! +………..x2n/n!
(14) 1 - x2/2! + x3/3! – x4/4! + …….xn/n!
(15) 1 + x2/2! + x3/3! + x4/4! + …….xn/n!
(16) x + x2/3! + x3/5! + x4/7! + x5/9! +…….xn/(2n-1)!
(17) x + x3/2! + x5/3! + x7/4! + x9/5! +…….x2n-1/n!
(18) x - x2/3! + x3/5! - x4/7! + x5/9! -…….xn/(2n-1)!
(19) a + ar + ar2 + ar3+…………+ar(n-1)
Question B64: Input two numbers from the keyboard. Write a program to find the value of one
number raised to the power of another.
Question B65: WAP to print all the ASCII values and their equivalent characters. The ASCII
values vary from 0 to 255.
Question B66: WAP to check that given number is Armstrong number or not. ( if the sum of the
cubes of each digits of the number is equal to the number itself, then the number is called the
Armstrong number. For example, 153 = (1*1*1) + (5*5*5) + (3*3*3).
Question B67: 145 is a special number, since it satisfies the following relation:
145 = 1! + 4! + 5! = 1+24+120 =145
WAP to print all the numbers of this kind between 1 – 1000000.
Question B68: WAP to find out the sum of geometric series.
Question B69: WAP to print out all Armstrong numbers between 1 and 500.
Question B70: Square of 12 is 144. 21, which is a reverse of 12 has a square 441, which is same
as 144 reversed. There are few numbers which have this property. Write a program to find out
whether any more such numbers exist in the range of 10 to 100.
Question B71: WAP to find out the difference between two dates in terms of numbers of days.
Question B72: WAP to input n numbers and calculate the sum, average, maximum and minimum
of the given numbers. (use only one variable to input the number and also find the second
largest).
Question B73: WAP to print the sum of negative numbers, sum of positive even numbers and
sum of positive odd numbers from a list of numbers entered by the user.
Question B74: WAP to print the largest even number and largest odd number from the list of
numbers entered through keyboard.
Question B75: WAP to determine all Pythagorean triplets in the range 100 to 1000.
(A Pythagorean triplet is a set of three integers i, j, k such that i2 + j2 = k2)
Question B76: WAP to print the following series:
(1) 2, 4, 8, 16, 32, 64, 128, 256
(2) 1, 4, 7, 10, …………… 40
(3) 1, -4, 7, -10……………-40
(4) 1, 5, 11, 19, 29 ……..
(5) (1)+(1+2)+(1+2+3)+(1+2+3+4)…………..up to n terms
(6) (2) + (2+4) + (2+4+6) + (2+4+6+8)………….up to n terms.
(7) (1) + (1+3) + (1+3+5) + (1+3+5+7)…………..up to n terms
(8) (12) + (12+32)+(12+32+52)+(12+32+52+72)…….up to n terms
(9) (22) + (22+42) + (22+42+62)+(22+42+62+82)………up to n terms
Question B77: WAP to calculate the root of quadratic equation.
Question B78: Write a menu driven program which has following options:
1. Factorial of a number.
2. Prime or Not
3. Odd or even
4. Exit.
Question B79: WAP to input a number and print its reverse number. Also check that the number
is palindrome or not.
Question B80: WAP to input a number and find out the sum of its digits.
Question B81: WAP to find out the count of the digits of a given integer.
Question B82: WAP to print the Fibonacci series.
Question B83: WAP to input a name and print the name in the following pattern
R RAJAT
RA RAJA
RAJ RAJ
RAJA RA
RAJAT R
1234 4444
123 333
12 22
1 1
5
54
543
5432
54321
A A
AB BB
ABC CCC
ABCD DDDD
ABCD DDDD
ABC CCC
AB BB
A A
* ****
** ***
*** **
**** *
ABCDEFGFEDCBA
ABCDEF FEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
0
1 0 1
1 0 1 0 1
1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1
0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
A
A B A
A B C B A
A B C D C B A
A B C B A
A B A
A
Question C32: WAP that replaces two or more consecutive blanks in a string by a single blank.
Question C33: WAP to input 10 names in a 2D array of characters and replace the 1 st name with
5th name and display the resultant array.
Question C34: WAP to input two strings consists of maximum 80 characters. Examine both the
strings and remove all the common characters from both the strings. Display the resultant string.
Question C35: WAP to test whether a string of opening and closing parentheses is well formed or
not.
Question C36: WAP to evaluate a postfix expression given by the user.
Question C37: WAP to evaluate a prefix expression given by the user.
Question C38: WAP to convert a given infix expression to prefix and postfix expression.
Question C39: WAP to convert a postfix expression to the prefix expression and vice versa.
Question C40: WAP to convert a postfix expression to infix expression.
Question C41: WAP to input an arithmetic expression comprising of numeric constants and
operators and evaluate the expression at the input.
Question C42: Write a function which has two strings x and y as arguments. The function finds
out the first symbol of x which does not occur in y.
Question C43: Write a program to check that any one of given n strings occur in a string s.
Section D: Programs based on arrays
Question D1: WAP to input the marks of 10 students in an array of integers and display the
marks.
Question D2: WAP to search how many times a number is present in an array.
Question D3: WAP to subtract two arrays of the same size.
Question D4: WAP to input the sales made by a salesman in every month of a given year and
find out the total, average, maximum and minimum sales.
Question D5: WAP to calculate the average of 10 values stored in an array and display all those
values which are more than the calculated average.
Question D6: WAP which finds the locations and values of largest and second largest element in
a one dimensional array.
Question D7: WAP to reverse an array of floats.
Question D8: WAP to create a sorted list using arrays. Every time the element is entered in the
array, the array must remain sorted.
Question D9: WAP to rotate an integer array towards right by the given number of times.
Question D10: WAP to input 20 values in an integer array and count the negative, positive, odd
and even values in the array.
Question D11: Given an array named A with following elements:
3, -5, 1, 3, 7, 0, -15, 3, -7, -8
WAP to shift the negative numbers to the left and positive numbers to the right so that the
resultant array look like the
-5, -15, -7, -8, 3, 1, 3, 7, 0, 3
Question D12: WAP to copy the last 5 elements of array B after first 5 elements of array A.
Assume length of A and B is greater than 5.
Question D13: WAP to print all the palindrome numbers from an integer array and find out their
sum.
Question D14: WAP to print all the prime numbers from an integer array and find out their sum.
Question D15: WAP to input 10 values in a float array and display all the values more than 75.
Question D16: WAP delete an element from the array and shift the elements
(a) Towards right.
(b) Towards left
Question D17: WAP to delete all the occurrences of a given value from the array and shift the
remaining elements to the left of the array.
Question D18: WAP to delete duplicate elements from an array.
Question D19: WAP to insert a value in the array at desired location.
Question D20: WAP to insert a value in the sorted array.
Question D21: WAP to sort an array.
• Using bubble sort technique
• Using selection sort technique
• Using insertion sort technique.
• Using Quick sort technique
• Using Heap sort technique.
Question D22: WAP to check that given array is sorted in ascending / descending order.
Question D23: WAP to search a value in the array using
• Linear search technique.
• Using binary search technique.
Question D24: WAP to count the number of occurrences of a given number in an integer array.
Question D25: An array consists of 50 integers in the range of 1 to 25, write a program that prints
the number of times each integer occurs in the array.
Question D26: A, B, C are the arrays of integers of size a, b, a + b, Write a program to produce a
third array C containing all the elements of array A and B.
Question D27: WAP to merge two arrays according to the following conditions:
First array Second array Resultant array
(1) Ascending Ascending Ascending
(2) Ascending Ascending Descending
(3) Ascending Descending Ascending
(4) Ascending Descending Descending
(5) Descending Descending Ascending
(6) Descending Descending Descending
Question D28: WAP to add and multiply two large integers, which can not be represented by
built in data types.
QuestionD29: WAP to delete all elements in between and occupying two specified positions.
Question D30: WAP to search the first occurrence a given sub array within another array.
Question D31: WAP to merge 4 arrays a, b, c, d in one array. All the arrays are in ascending
order.
R RAJAT
RA RAJA
RAJ RAJ
RAJA RA
RAJAT R
Question G5: Write a program to print the following patterns using pointers.
A A
AB BB
ABC CCC
ABCD DDDD
ABCD DDDD
ABC CCC
AB BB
A A
ABCDEFGFEDCBA
ABCDEF FEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
Question G6: Write a function to count the number of spaces, tabs and new line characters in a
given string using pointers. The string must be passed to the function as argument.
Question G7: Write a function to count the numbers of vowels, consonants, digits and special
symbols in a given string using pointers. The string must be passed to the function as argument.
Question G8: Write a function to extract specified number of characters from a given position
from a string using pointers. The function has one string argument and two integer arguments.
Question G9: Write a function to concatenate two strings using pointers. Function has two string
arguments.
Question G10: Write a function to compare two strings using pointers. Function has two string
arguments and returns 0 if strings are equal else returns 1.
Question G11: Write a function to encrypt and decrypt a string using pointers and use your own
method of encryption and decryption.
Question G12: WAP to reverse all the strings stored in an array using pointers
Question: Write a function to swap two strings stored in an array using pointers. The array of
strings is passed to the function as arguments.
Question G13: Write a function to display all the palindrome strings from the array of strings
using pointers. The array of strings is passed to the function as arguments.
Question G14: Write a function to reverse an array of floats using pointers. The array must be
passed to the function as argument.
Question G15: Write a function to print all the palindrome numbers from an integer array and
find out their sum using pointers. The array must be passed to the function as argument.
Question G16: Write a function to delete duplicate elements from the array using pointers. The
array must be passed to the function as argument.
QuestionG17: Write a function to sort an array using bubble sort technique using pointers. The
array must be passed to the function as arguments.
Question G18: Write a function to search a value in the sorted array using binary search
technique using pointers. The array and value must be passed to the function as argument and
function should return 1 if found else returns 1.
Question G19: Write a function to find out the row sum and column sum of a two dimensional
array of integers using pointers. The array must be passed to the function as argument.
Question G20: Write a function to find out the product of two matrices using pointers. The arrays
must be passed to the function as argument.
Question G21: Write a function to transpose a square matrix using pointers. The array must be
passed to the function as argument.
Question G22: Write a function to sort the elements of a matrix using pointers. The array must be
passed to the function as argument.
Question I3: WAP to declare two structures with the following specification
Structure name date
Dd int day
Mm int month
Yy int year
Question J1: WAP to input rollno, name and marks in five subjects and calculate the total and
average marks through classes. Define different functions to input, calculate and display the data.
Question J2: WAP to declare a class with the following specification
Class name Emp
(Data members) Private:
Ecode integer
Ename character array
Basic salary float
Hra float 40% of basic salary
Da float 20% of basic salary
Ta float 10% of basic salary
Gross salary float basic salary + hra + da + ta
It float 20 % of gross salary
Pf float 10% of gross salary
Net salary float gross salary – (it + pf)
(Member functions) Public:
void Input( ) - function to input the values for
ecode, ename and basic salary
void calc( ) - function to calculate all other values
void disp( ) - function to display the all the values.
Section N: Stacks and Queues (Implement all the questions using structures and classes
both)
Question N1: WAP to implement a static stack and show the push and pop operations on the
stack.
Question N2: WAP to implement a static queue and show the insert and delete operations on the
queue.
Question N3: WAP to implement a static circular Queue.
Question N4: WAP to implement a static dequeue (using arrays).
Question N5: WAP to implement n stacks in single 1D array. Write functions for “push” and
“pop” operations on i-th stack.
Question N6: WAP to implement n queues in single 1D array. Write functions for “add” and
“delete” operations on i-th queue
Question N7: Represent a stack and a queue in a single 1D array. Write functions for “push”,
“pop” operations on stack and “add”, “delete” operations on the queue.
Section O: Linked Lists (Implement all the questions using structures and classes both)
Question O1: WAP to implement a single linked list of integers and perform the following
operations
• add an integer in beginning
• add an integer after the given element in the list
• add an integer before the given element in the list
• add an integer at the position given by the user.
• add an integer at end
• display the list
• delete an element from the beginning
• delete an element from the end
• delete an element from specified position.
• delete an element given by the user.
• Search an item in the list.
Question O2: WAP to implement a circular linked list of integers
Question O3: WAP to implement linked stack
Question O4: WAP to implement a linked queue.
Question O5: WAP to implement a linked circular Queue.
Question O6: WAP to implement a linked dequeue.
Question O7: WAP to create two linked lists of integers in ascending order and merge both the
lists to create a new list in ascending order.
Question O8: WAP to reverse a linked list.
Question O9: WAP to check that the given linked list of integers is sorted in ascending order or
not.
Question O10: WAP to split a linked list into two linked lists, so that each list gets equal number
of nodes. (delete a node if required).
Question O11: WAP to concatenate two linked lists.
Question O12: WAP to convert a singly linked list into circular linked list.
Question O13: WAP to create a single linked list of integers, where the new node has to be
inserted in such a way that the list is always sorted in ascending order.
Question O14: WAP to count the maximum, minimum, sum, average and count of the values
stored in the linked list of integers.
Question O15: X points to the first node of the singly linked list. Search the first occurrence of
ITEM in the list and split the list into two, so that y points to the sublist beginning with ITEM.
Question O16: Write a program that creates a linked list of characters from a string entered by
the user. Your program is then to remove a number of consecutive elements from the linked list
(in effect removing a sub-string from the string entered). This is to be achieved by the user
entering two integers. The first of which will represent an index (counting from zero) into the
linked list, and the second will represent the number of elements to be removed. For example, if
the user enters the following string (without the quotes):
"I do not love C"
and then enters the two integers 2 and 7, the program would output (without the quotes):
"I love C"
Question Q17 : WAP to sort a linked list of integers using insertion sort technique.
Question O18: WAP to implement a doubly linked list and implement the fllowing functions :
Section P: Binary Trees (Implement all the questions using structures and classes both)
QuestionP1: Create a binary search tree and perform
• Preorder traversal(recursive and non recursive)
• Inorder traversal(recursive and non recursive)
• Postorder traversal(recursive and non recursive)
Question P2: WAP to count the number of leaf nodes in a binary tree.
Question P3: WAP to list the list the data fields of a binary tree level by level. Within levels,
nodes are to be listed from left to right.
Question P4: WAP to compute the height of a binary tree.
Question P5: WAP to check that two binary trees are similar.
Question P6: Construct two binary trees so that their preorder traversal sequences are the same.
Question P7: Construct two binary trees so that their postorder traversal sequences are the same.
Question P8: Write a function to swap a binary tree.
Question P9: Write a function to compute the maximum number of nodes in any level of a binary
tree. The maximum number of nodes in any level of a binary tree is also called the width of the
tree
Question P10: Write a function to find out the inorder successor of a given node in a binary tree.
The inputs to the function are a pointer to the root of the tree and a pointer to a node. The
function returns a pointer to the inorder successor of the given node.
Question P11: Write a function to find out the inorder predecessor of a given node in a binary
tree. The inputs to the function are a pointer to the root of the tree and a pointer to a node. The
function returns a pointer to the inorder predecessor of the given node.
Question P12: Write a function to compute the internal path length of a binary tree.
Question P13: Write a function to compute the external path length of a binary tree.
Question P14:Write a function to delete a node from a binary search tree which ultimately
deletes the inorder predecessor of the node to be deleted if the node has exactly two non empty
children.
Question P15: Write a function to check whether a given binary search tree is an AVL tree or not.
Question P16: Write a non recursive function to insert a node in AVL tree.
Question P17: Write a non recursive function to delete a node from an AVL tree.
Question P18: Write a recursive function to delete a node from an AVL tree.
Question P19: Write a function to merge the nodes of two AVL trees to obtain a new AVL tree.
Question P20: Write functions to find the immediate predecessor and immediate successor of a
given key value in a B-tree.
Question P21: Write a function to insert a new key to a B-tree of order “m”.
Question P22: Write a function to delete an existing key from a B-tree of order “m”.