You are on page 1of 4

CODE TO SHOW

*
**
***
****
*****
CODING

#include<iostream>
using namespace std;

int main(){
int rows;
cout<<"Enter number of rows:"
cin>>rows;

for(int i=1;i<=rows;++i){
for(int j=1;j<=i;++j){
cout<<"\n";
}
return 0;
}

output:
Enter number of rows:5
*
**
***
****
*****

here int rows takes input rows of * pyramid ,cout print the * and cout "\n' start
with new line . because of int i and j value the increase with number of rows

CODE TO DETERMINE NUMBER IS PRIME NUMBER

coding

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i=2,n;
cout<<"enter the number:";
cin>>n;
while(n%i!=0)
{
i++;
}
if(n==i)
{
cout<<"prime number";
}
else
{
count<<"not a prime number";
}
getch();
}

output:
enter the number:7
prime number

in this coding when we enter any integer it match with n%i!=o . if statement
display prime number when i ==n and if i==n not then else print is not a prime
number .

CODE TO FIND AREA OF CIRCLE USING RADIUS INPUT

#include<iostream.h>
#include<conio.h>
class circle
{
float r, a ;
public:
void main()
{
cout<<"enter the radius";
cin>>r;
}
void compute()
{
a=3.14*r*r;
}
void display ()
{
cout<<"area="<<a;
}
};
void main()
{
clrscr();
circle();
c.read();
c.compute();
c.display();
getch();
}

here cin>>r: is use for take inpute , float function used for the value can be
floate , void compute used for calculation . 3.14*r*r is the formula for area of
circle in above coding when we take input it calculate the area of circle similarly
we can create code for volume of circle replaced the formula for volume of circle
MULTIDIMENTIONAL ARRAY

a multidimentional array is termed as an arraay of array that store homogeneous


data in tAbuar form .

the data of multidimentional array store in rows

the genral form of declaration n dimentional is


data_type array_name[size1],[size2],.....[sizen]

here data_type is the type of data can be store

array_name : name of array

[size1], [size2],...[sizen] :size of dimention

example:
two dimentional array : two_d[20][10];

three dimentional array: three_d[10][20][30],

size of multidimentional array


the total number of element can be stored in dimentional is calculater by
calculating the size of array

exAmple int x [10][20]= 200 element store

similarly int x [10][20][5] store 1000 elements

two dimentional array


it is simplest multidimentional array .
syntex= data_type array_name[x][y];

decler 2d array integer x


int x [3][3];

the size of array will be 3*3 but indices from o to 2 in both row and column the
representation like

0 1 2
0 a[0][0] a[0][1] a[0][2]
1 a[1][0] a[1][1] a[1][2]
2 a[2][0] a[2][1] a[2][2]
we assume thAT value of matrix store 9 memory

so if we put 9 value of matrix and when we code it display a 3*3 matrix

You might also like