Skip to content

Commit 5cfbf66

Browse files
Coding BlocksCoding Blocks
authored andcommitted
updated code
1 parent c43f949 commit 5cfbf66

17 files changed

+426
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.
6 KB
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main(){
6+
7+
int cliff_end = 10;
8+
int x = 10; // start
9+
10+
// do while is executed atleast once!
11+
// exit controlled doesnt check for the init condition is true or false!
12+
13+
do{
14+
x = x + 1;
15+
cout<<"Taking 1 step reaching :"<<x <<endl;
16+
}
17+
while(x<cliff_end);
18+
19+
20+
21+
cout<<"Final X "<<x<<endl;
22+
23+
if(x==cliff_end){
24+
cout<<"We are standing at cliff edge!"<<endl;
25+
}
26+
27+
else if(x>cliff_end){
28+
cout<<"Falling from the cliff!"<<endl;
29+
}
30+
31+
32+
33+
return 0;
34+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main(){
6+
7+
int cliff_end = 10;
8+
int x = 0;
9+
10+
//for(start; stop; update){...}
11+
for( ; x<cliff_end; x = x + 1){
12+
cout<<"Taking 1 step reaching :"<<x<<endl;
13+
}
14+
15+
return 0;
16+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
//Conditional Statements in C++
5+
6+
int main(){
7+
8+
int n;
9+
cin>>n;
10+
11+
//Program to check if a Number is divisble by 2, div by 3 and both
12+
// if else-if else
13+
14+
// else-if block if you want only one of the blocks is executed
15+
/*
16+
if
17+
else if
18+
else if
19+
else if
20+
else
21+
22+
*/
23+
24+
if(n%2==0 and n%3==0){
25+
cout<<n<<" is div by 2 and 3"<<endl;
26+
cout<<"If block!"<<endl;
27+
}
28+
//all other blocks below the block which is executed are skipped
29+
30+
//If-Else block is independent of the above if block
31+
else if(n%2==0){
32+
cout<<n<<" is div by 2"<<endl;
33+
cout<<"else If-1 block!"<<endl;
34+
35+
}
36+
37+
else if(n%3==0){
38+
cout<<n<<" is div by 3"<<endl;
39+
cout<<"else If-2 block!"<<endl;
40+
}
41+
else{
42+
cout<<"Not Divisible!"<<endl;
43+
cout<<"Else block"<<endl;
44+
}
45+
46+
return 0;
47+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<iostream>
2+
#include<climits>
3+
using namespace std;
4+
5+
6+
int main(){
7+
// Find the minimum and maximum of N Numbers
8+
int n;
9+
cin>>n;
10+
11+
int min_so_far = INT_MAX;
12+
int max_so_far = INT_MIN;
13+
14+
int no;
15+
// Without storing all the numbers, based upon the current number!
16+
for(int i=0;i<n;i++){
17+
cin>>no;
18+
if(no<min_so_far){
19+
min_so_far = no;
20+
}
21+
if(no>max_so_far){
22+
max_so_far = no;
23+
}
24+
}
25+
26+
cout<<"Max No "<<max_so_far<<endl;
27+
cout<<"Min No "<<min_so_far<<endl;
28+
29+
30+
return 0;
31+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Code to Print the Pattern N = 5
3+
1
4+
232
5+
34543
6+
4567654
7+
567898765
8+
9+
*/
10+
11+
#include<iostream>
12+
using namespace std;
13+
14+
15+
int main(){
16+
17+
int n;
18+
cin>>n;
19+
//Loop for rows 1 to n
20+
for(int i=1;i<=n;i++){
21+
22+
//Spaces
23+
for(int space=1;space<=n-i;space++){
24+
cout<<" ";
25+
}
26+
27+
//Increasing Number
28+
int val = i;
29+
for(int cnt=1;cnt<=i;cnt++){
30+
cout<<val;
31+
val = val + 1;
32+
}
33+
34+
//Decreasing Numbers
35+
val = val - 2;
36+
for(int cnt=1;cnt<=i-1;cnt++){
37+
cout<<val;
38+
val = val - 1;
39+
}
40+
//Print a new Line
41+
cout<<endl;
42+
43+
}
44+
45+
return 0;
46+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main(){
6+
7+
// Give a Number N
8+
// Square root of the number without using any predefined function
9+
10+
11+
12+
return 0;
13+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main(){
6+
7+
int cliff_end = 10;
8+
int x = 10;
9+
10+
while(x<cliff_end){
11+
x = x + 1;
12+
cout<<"Taking 1 step reaching :"<<x <<endl;
13+
}
14+
15+
cout<<"Final X "<<x<<endl;
16+
17+
if(x==cliff_end){
18+
cout<<"We are standing at cliff edge!"<<endl;
19+
}
20+
21+
else if(x>cliff_end){
22+
cout<<"Falling from the cliff!"<<endl;
23+
}
24+
25+
26+
27+
return 0;
28+
}
6 KB
Binary file not shown.

0 commit comments

Comments
 (0)