CPP
Array & Pointer
Fill in the blanks
1.Array is Collection of Similar data type
2.Types of Array 2
3.Write array syntax datatype variablename[size]={value};
4. In Single dimensional array only presents in Row
5. In Multidimensional array presents in Row & Coloumn
6. int a[2][2]= {{3,8},{5,4}. a[0][1]= 8
7.int a[5]={1,8,3,10,15}. a[5] = 0 , a[2]= 8
8. Array allows string.[T/F] False
9.We can store character in Array .[T/F] True
10.Array is a Collections of different data type. [T/F]. False
11. Array stores multiple values in single variable.[T/F]. True
12.Write a syntax for multidimensional Array datatype variablename[row size][coloumn size]={value};
13.Pointer points address of another variable
Answer the following Question
(4 marks)
1.Write a program for single dimensional array.
#include<iostream.h>
#include<conio.h>
void
main()
{
int
a[5],i;
clrscr();
for(i=0;i<5;i++)
{
cin>>a[i];
}
for(i=0;i<5;i++)
{
cout<<a[i]<<endl;
}
getch();
}
2.Write a program for Array of Pointer
#include<iostream.h>
#include<conio.h>
void main()
{
int arr[5]={10,20,30,40,50};
int *ptr,i;
ptr=arr;
clrscr();
for(i=0;i<5;i++)
{
cout<<*(ptr+i)<<"\t";
*(ptr+i)=*(ptr+i)+5;
}
cout<<endl;
for(i=0;i<5;i++)
{
cout<<arr[i]<<endl;
}
getch();
}
3.Write a program to convert a word into lower case to upper case using Pointer
#include<iostream.h>
#include<conio.h>
void main()
{
char name[10];
char *cptr;
clrscr();
cout<<"enter the name in lower
case:";
cin>>name;
cptr=name;
for(;*cptr!='\0';cptr++)
{
if(*cptr>='a' &&
*cptr<='z')
*cptr=*cptr-32;
}
cout<<" upper case is :
"<<cptr<<endl;
}
Answer the following Question
(10 marks)
1.What is Array?Write a program for Multidimensional Array?
#include<iostream.h>
#include<conio.h>
void
main()
{
int
i,j,a[2][2];
clrscr();
cout<<"Enter
the values \n";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
}
cout<<"\n
Matrix a \n";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}
getch();
}
No comments:
Post a Comment