Professional Documents
Culture Documents
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;
}
Q2. Write a program in C++ to read a list of 10 integer numbers from the keyboard and find out the sum and