-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP7.cpp
More file actions
133 lines (117 loc) · 2.3 KB
/
P7.cpp
File metadata and controls
133 lines (117 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <iostream>
using namespace std;
int main (){
// //Sum of numbers
// int n,sum;
// sum=0;
// cin>>n;
// for (int i = 0; i < n; i++)
// {
// sum = sum + i;
// }
// cout<<"Sum of series = "<<sum<<endl;
//Factorial
// int n;
// cin>>n;
// unsigned long long Fac=1;
// for(int i=1; i<=n;i++)
// {
// Fac = Fac*i;
// }
// cout<<Fac;
// //Prime numbers
// int n;
// cin>>n;
// bool b=true;
// for (int i = 2; i < n; i++)
// {
// if(n%i==0)
// {b=false;}
// }
// if(b==true) {
// cout<<"It is prime";
// }
// else
// cout<<"It is not prime";
//Palindrome No.
// int num, originalNum, reversedNum=0, lastDigit;
// cout<<"Enter the No."<<endl;
// cin>>num;
// originalNum = num;
// while (num>0)
// {
// lastDigit=num%10;
// reversedNum=(reversedNum*10) + lastDigit;
// num = num/10;
// }
// if (originalNum == reversedNum)
// {
// cout<<originalNum << " is a palindrome";
// }
// else
// cout<<originalNum <<" is not a palindrome";
//Fibonacci series
// int a,b,n, c;
// cout<<"Enter the value of n "<<endl;
// cin>>n;
// a=0;
// b=1;
// for (int i=1; i<n; i++)
// {
// cout<<a<<" ";
// c = a + b;
// a = b;
// b = c;
//}
//right angle triangle
// int n;
// cin>>n;
// for (int row=0; row<n; row++){
// for (int col = 0; col < row+1; col++)
// {
// cout<<"* ";
// }
// cout<<endl;
// }
//Pyramid
// int n;
// cin>>n;
// for (int row = 0; row < n; row++)
// {
// for (int col = 0; col < n-1-row; col++)
// {
// cout<<" ";
// }
// for (int col = 0; col < row+1; col++)
// {
// cout<<"* ";
// }
// cout<<endl;
// }
//Diamond
int n;
cin>>n;
for (int row = 0; row < n; row++)
{
for (int col = 0; col < n-1-row; col++)
{
cout<<" ";
}
for (int col = 0; col < 2*row+1; col++)
{
cout<<"* ";
}
cout<<endl;
}
for (int row = n-2; row >= 0; row--)
{
for (int col = 0; col < n-1-row; col++)
{
cout<<" ";}
for (int col = 0; col < 2*row+1; col++)
{
cout<<"* ";
}
cout<<endl;
}
}