You are on page 1of 3

Assignment-1

Topic – Single Dimensional Array

Q1. What do you mean by array ? Explain with some suitable Example?
Q2. Name the valid and invalid declaration of array
i) int a[+10] ii) int a[1..10] iii) int x[1-10] iv) int [10] a
v) int a[-10] vi) int a[ ] vii) int[10] x viii) int x[10] ; float x[10]
ix) int x[n]; x) int x[i]
Q3. Find out the output of the following program segment
#include<iostream.h>
int main( )
{
int x[10],i,sum =0;
for(i=0;i<10;i++)
if(i%2= =0 )
sum = sum+x[i];
else
sum = sum – x[i];
cout<<”\n Sum of element :”<< sum
return 0;
}

Q4. Find out the error(s) in the following program listing (assuming all the necessary files are included)
#include<iostream.h>
int main( )
{
int x[10],i,sum =0;
for(i=0;i<=10;i++)
if(i%2= =0 )
sum = = sum+x[i];
else
sum = sum – x[i];
cout<<”\n Sum of element :”<< sum
return 0;
}

Q5. Find out the output of the following program


#include<iostream.h>
int main( )
{
int x[5] ={ 1,5,3};
for(i=0;i<5;i++)
cout<<setw(6)<<x[i];
return 0;
}

Q2. Write a program in C++ to read a list of 10 integer numbers from the keyboard and find out the sum and

Last updated on: 23/01/2006 22:45 a1/p1 Page 1 of 3


average of these numbers? Also Display the entered numbers?
Q3. Write a program in C++ to red a list of 10 integer numbers from the keyboard and find out the largest
number among them. Display the largest number and the number entered
Q4. Write a program in C++ to read a list of 10 integer number from the keyboard and find out the sum of all
the even numbers and the sum of all the odd numbers? Also display the entered numbers
Q5. Write a program in C++ to read a list of 10 integer numbers from the keyboard and find out the sum of all
the positive numbers and the sum of all the negative numbers?
Q6. Write a program in C++ to read a list of 10 integer numbers from the keyboard and swap the position of
first half numbers with the second half numbers. Also display the original numbers and the swap numbers.
Q7. Write a program in C++ to read a list of 1o integer numbers and give the increment of 20 to each element
. Also display the original list and modified list ?
Q8. Write a program in C++ to read a list of 10 integer numbers and find out the sum of those elements which
is either divisible by 2 or 3. Also display the entered list and the sum ?
Q9. Write a program in C++ to read a list of 10 integer numbers and arrange them in such a manner that all
the even numbers start from the left and all the odd numbers start from the right.
Example x ={1,2,3,4,5,6,7,8,9,10) resultant array =(2,4,6,8,10 ,8,7,5,3,1 }
Q10. Write a program in C++ to read a decimal integer number and find out it’s binary equivalent ?
Q11. Write a program in C++ to read a decimal integer number and find out it’s octal number?
Q12. Write a program in C++ to read a list of 10 integer numbers and one more integer number from the
keyboard and find out whether the given number is available in the list or not (Use Linear search
algorithm)
Q13. Write a program in C++ to read a list of 10 sorted integer numbers and one more integer number from
the keyboard and find out whether the given number is available in the list or not (Use Binary search
algorithm)
Q14. Write a program in C++ to read a list of 10 floating point numbers from the keyboard and arrange them in
ascending order (use Bubble sort algorithm)
Q15. Write a program in C++ to read a list of 10 floating point numbers from the keyboard and arrange them in
descending order (use Bubble sort algorithm)
Q16. Write a program in C++ to read a list of 10 floating point numbers from the keyboard and arrange them in
ascending order (use selection sort algorithm)
Q17. Write a program in C++ to read a list of 10 floating point numbers from the keyboard and arrange them in
descending order (use selection sort algorithm)
Q18. Write a program in C++ to read a list of 10 floating point numbers from the keyboard and arrange them in
ascending order (use insertion sort algorithm)
Q19. Write a program in C++ to read a list of 10 floating point numbers from the keyboard and arrange them in
ascending order (use insertion sort algorithm)

Last updated on: 23/01/2006 22:45 a1/p1 Page 2 of 3


Q20. Write a program in C++ to read two arrays A and B of order M and N respectively. Concatenate them
to form a new array C of order M+N. Also display the original arrays and the merge array.
Q21. Write a program in C++ to read two sorted array A and B of order M and N respectively, both the arrays
A and B are arranged in ascending order. You are required to merge these two arrays to form the third
array C in ascending order only visiting the array A and B only once.
Q22. Write a program in C++ to read one array of order N and insert a new element in this array . Display the
array after insertion of the element.
Q23. Write a program in C++ to read an array of order N and delete an element from this list of element .
Display the original array and the array after deletion of the element.

Last updated on: 23/01/2006 22:45 a1/p1 Page 3 of 3

You might also like