-
Notifications
You must be signed in to change notification settings - Fork 0
/
while_loop.cpp
120 lines (101 loc) · 1.44 KB
/
while_loop.cpp
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
//1-n range number
/*#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int i = 1;
while(i<=n) //range
{
cout<<i<< " ";
i = i+1;
}
}*/
//sum of n number using while loop
/*
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int i = 1;
int sum = 0;
while(i<=n){
sum = sum + i;
i = i+1;
}
cout<<"value of sum is: " <<sum<<endl;
}
*/
//sum of n even number (HW)
/*
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int i = 2;
int sum = 0;
while(i<=n){
sum = sum + i;
i = i+2;
}
cout<<"value of sum is: " <<sum<<endl;
}
*/
//ferenhite and celcius (HW)
/*
#include<iostream>
using namespace std;
int main(){
int n, i = 2;
cin>>n;
while(i<n){
if(n%i==0){
cout<<"Not Prime for"<<i<<endl;
}
else{
cout<<"Not Prime"<<i<<endl;
}
i = i+1;
}
}
*/
//Patterns -----(1)
/*#include<iostream>
using namespace std;
int main(){
//check for row and column
//nth row --- col-row
int n;
cin>>n;
7
int i = 1; //i-row
while(i<=n){
int j = 1; //j- column
while(j<=n){
cout<<"*";
j=j+1;
}
cout<<endl;
i = i+1;
}
}
*/
//Patterns -----(2)
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int i = 1;
while(i<=n){
int j = 0;
while(j<=n){
cout<<i;
j=j+1;
}
cout<<endl;
i = i+1;
}
}