Professional Documents
Culture Documents
*
**
***
****
*****
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
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 .
#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
example:
two dimentional array : two_d[20][10];
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