Skip to content

Commit c43f949

Browse files
Coding BlocksCoding Blocks
authored andcommitted
added section 01 code
1 parent b0adc1e commit c43f949

16 files changed

+297
-0
lines changed

.DS_Store

10 KB
Binary file not shown.

01 Getting Started with C++/.DS_Store

6 KB
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
//Question Von Neuman Loves Binary
5+
6+
7+
int main() {
8+
9+
int no;
10+
int N;
11+
cin>>N;
12+
13+
while(N>0){
14+
15+
cin>>no;
16+
17+
int p = 1;
18+
int ans = 0;
19+
20+
while(no>0){
21+
int r = no%10;
22+
ans = ans + r*p;
23+
p = p*2;
24+
no = no/10;
25+
}
26+
cout<<ans<<endl;
27+
N = N - 1;
28+
}
29+
30+
return 0;
31+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit b0adc1ea82d545fa7caa7e80576c6c148865d2e5
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main(){
6+
// You are given N, followed by list of N numbers
7+
// Output : the squares of N Numbers
8+
/*
9+
10+
Input File
11+
3 N
12+
1
13+
2 No
14+
5
15+
16+
Output File
17+
1
18+
4 Ans
19+
25
20+
*/
21+
int N;
22+
cin>>N;
23+
24+
int no;
25+
while(N>0){
26+
cin>>no;
27+
cout<<no*no<<endl;
28+
29+
N = N - 1;
30+
}
31+
return 0;
32+
}

01 Getting Started with C++/hello.cpp

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include<iostream> //header file
2+
using namespace std; // standard c++ namespace
3+
4+
5+
6+
int main(){ //start
7+
8+
//Output
9+
cout<<"Hello Everyone!"<<endl;
10+
11+
return 0; //exit
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
1
3+
12
4+
5
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
144
3+
25
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main () {
6+
7+
int n ;
8+
cin>>n;
9+
10+
int row = 1;
11+
while(row<=n){
12+
int col = 1;
13+
14+
if(row%2!=0){
15+
//Odd Row
16+
while(col<=row){
17+
cout<<1;
18+
col = col + 1;
19+
}
20+
21+
}
22+
else{
23+
//Even Row
24+
cout<<1;
25+
while(col<=row-2){
26+
cout<<0;
27+
col = col + 1;
28+
}
29+
cout<<1;
30+
}
31+
cout<<endl;
32+
row = row + 1;
33+
}
34+
35+
return 0;
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
6+
int main(){
7+
8+
// Simple Interest
9+
//Declare a variable
10+
int p,r,t;
11+
float si;
12+
13+
/* Assigns values to the buckets (storage in the memory)
14+
p = 10;
15+
r = 25;
16+
t = 1;
17+
*/
18+
cin>>p;
19+
cin>>r>>t;
20+
21+
// 250/100 = 2.50
22+
// every statement should be terminated by a semi-colon
23+
24+
si = p*r*t/100.0;
25+
26+
// Typecasting -> Implicit
27+
//integer/integer = integer
28+
// float/integer = float
29+
// integer/float = float
30+
31+
32+
cout<< si <<endl;
33+
34+
35+
/* This is
36+
multi line comment */
37+
return 0;
38+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main(){
6+
7+
int n;
8+
cin>>n;
9+
10+
11+
//Initialisation
12+
int sum = 0;
13+
14+
//Stopping Criteria
15+
while(n>0){
16+
int last_digit = n%10;
17+
sum = sum + last_digit;
18+
19+
//Update Statement
20+
n = n/10;
21+
22+
}
23+
24+
//Print the ans
25+
cout<<"Sum of Digits is "<<sum<<endl;
26+
27+
28+
return 0;
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main(){
6+
//Program to find sum of numbers from 1 to N
7+
8+
int n;
9+
//Take Input
10+
cin>>n;
11+
12+
//Init Condition
13+
int i = 1;
14+
int sum = 0;
15+
16+
17+
while(i<=n){ //Stopping Criteria
18+
sum = sum + i;
19+
20+
i = i + 1; //Update Statement
21+
}
22+
//Output the Sum
23+
cout<<sum<<endl;
24+
25+
return 0;
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<iostream>
2+
#include<climits>
3+
using namespace std;
4+
5+
6+
int main(){
7+
8+
//Data Type Modifiers + Data types
9+
// long, short, signed, unsigned
10+
11+
int x;
12+
13+
cout<<sizeof(x)<<endl;
14+
cout<<INT_MAX<<endl;
15+
cout<<INT_MIN<<endl;
16+
17+
x = INT_MAX;
18+
19+
//What will happen you add 1 to x ?
20+
21+
22+
cout <<"X "<<x <<endl;
23+
24+
x = x +1;
25+
cout<<"Updated X "<<x <<endl;
26+
27+
28+
29+
30+
31+
32+
return 0;
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main(){
5+
6+
7+
//Primitive Datatypes
8+
//int , float, bool, double, char
9+
10+
int x = 5000;
11+
float y = 10.141;
12+
bool weather_is_rainy = true;
13+
double pi = 3.141131212121;
14+
char ch = 'A';
15+
16+
// How much memory each is going to occupy!
17+
cout<< "Int " <<sizeof(x) <<endl; // 4 bytes
18+
cout<<" Float "<<sizeof(y) <<endl; // 4 bytes
19+
20+
cout<< "Bool " <<sizeof(weather_is_rainy) <<endl; // 1 byte
21+
cout<<" Double "<<sizeof(pi) <<endl; // 8 bytes
22+
cout<< " Char "<<sizeof(ch)<<endl; // 1 byte
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
return 0;
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
5+
int main(){
6+
7+
int f = 0;
8+
int c;
9+
10+
while(f<=300){
11+
c = (5*(f-32))/9;
12+
cout<<f<<" "<<c <<endl;
13+
f = f + 20;
14+
}
15+
16+
17+
18+
return 0;
19+
}

0 commit comments

Comments
 (0)