diff --git a/C++/s1.cpp b/C++/s1.cpp index 95629da..dda5879 100644 --- a/C++/s1.cpp +++ b/C++/s1.cpp @@ -1,17 +1,21 @@ // to find the reverse of a given number -#include +#include using namespace std; -int reverse(int x) { - long r=0; - while(x){ - r=r*10+x/10; - x=x/10; +int reverse(int x) +{ + long r = 0; + while (x) + { + // r=r*10+x/10; // bug + r = r * 10 + x % 10; // solution + x = x / 10; } return r; } -int main(void){ +int main(void) +{ cout << reverse(12345) << endl; -} +} \ No newline at end of file diff --git a/C++/s2.cpp b/C++/s2.cpp index d995ee5..4586dc6 100644 --- a/C++/s2.cpp +++ b/C++/s2.cpp @@ -3,16 +3,19 @@ #include #include -int main(){ - std :: vector myVec; +int main() +{ + std ::vector myVec; myVec.push_back(1); myVec.push_back(2); myVec.push_back(3); - for(int i=0; i < myVec.size(); i++){ - std :: cout << myVec[i] << std :: endl; + for (int i = 0; i < myVec.size(); i++) + { + std ::cout << myVec[i] << std ::endl; } - std :: cout << "Element at index 3: "<< myVec.at(3) << std::endl; - + // std :: cout << "Element at index 3: "<< myVec.at(3) << std::endl; // bug + std ::cout << "Element at index 3: " << myVec.at(2) << std::endl; // solution + return 0; -} +} \ No newline at end of file diff --git a/C++/s3.cpp b/C++/s3.cpp index 854ed28..059144b 100644 --- a/C++/s3.cpp +++ b/C++/s3.cpp @@ -1,24 +1,30 @@ // find the bug in the concept -#include +#include using namespace std; int i = 5; int j; -int foo(int j) { - for (i=0; i +#include #include using namespace std; -#define Random(n) random()%n +#define Random(n) random() % n -int random(){ +int random() +{ srand(time(0)); return rand(); } - -int main(void){ - int i=6, j=7; - int val = Random(j-i+1); +int main(void) +{ + int i = 6, j = 7; + // int val = Random(j-i+1); + int val = random() % (j - i + 1); cout << val << endl; -} +} \ No newline at end of file diff --git a/C++/s5.cpp b/C++/s5.cpp index 3c05697..40ba125 100644 --- a/C++/s5.cpp +++ b/C++/s5.cpp @@ -1,13 +1,13 @@ -#include +#include using namespace std; - -int main(void){ +int main(void) +{ string string1 = "Hello"; string string2 = "Horld"; if (string1 == string2) - cout << "Equal"; + cout << "Equal"; else - cout << "Not Equal"; -} + cout << "Not Equal"; +} \ No newline at end of file diff --git a/C++/s6.cpp b/C++/s6.cpp index 736760a..a0edf26 100644 --- a/C++/s6.cpp +++ b/C++/s6.cpp @@ -1,18 +1,36 @@ // to find the largest sum of subarray -#include +#include using namespace std; int maxSubArraySum(int a[], int size) { - int max_so_far = INT_MIN, max_ending_here; - - for (int i = 0; i < size; i++) { + // change INT_MIN to 0 + int max_so_far = 0; + int max_ending_here = 0; + + for (int i = 0; i < size; i++) + { max_ending_here = max_ending_here + a[i]; if (max_so_far < max_ending_here) max_so_far = max_ending_here; - - if (max_ending_here < 0) + + // if (max_ending_here < 0)//bug + if (max_ending_here < max_so_far) // solution max_ending_here = max_so_far; } return max_so_far; } +// solution +int main() +{ + int a[5]; + for (int i = 0; i < 4; i++) + { + a[i] = i; + } + a[4] = -2; + + int max = maxSubArraySum(a, 5); + cout << max << endl; + return 0; +} \ No newline at end of file diff --git a/JS & TS/four.js b/JS & TS/four.js index 71006fa..98336a2 100644 --- a/JS & TS/four.js +++ b/JS & TS/four.js @@ -21,7 +21,15 @@ let team = [ }, ]; const filterBySalary = (peopleArray, threshold = 300) => { - return peopleArray.find((person) => person.salary > threshold); + // return peopleArray.find((person) => person.salary > threshold); + // pushing all the person with salary > threshold into the list + list = []; + peopleArray.forEach((person) => { + if (person.salary > threshold) { + list.push(person); + } + }) + return list; }; const filteredTeam = filterBySalary(team, 300); -console.log(team, filteredTeam); +console.log(filteredTeam); diff --git a/JS & TS/one.js b/JS & TS/one.js index b2f1d83..315be89 100644 --- a/JS & TS/one.js +++ b/JS & TS/one.js @@ -1,5 +1,6 @@ const printNames = (names) => { return `We are ${names.toLowerCase()}`; }; -const intro = printNames("krish" + +"bob"); +// const intro = printNames("krish" + +"bob"); +const intro = printNames("krish" + "bob"); console.log(intro); diff --git a/JS & TS/three.js b/JS & TS/three.js index e149777..b6db5d0 100644 --- a/JS & TS/three.js +++ b/JS & TS/three.js @@ -17,12 +17,15 @@ const team = [ { name: "james", place: "earth", + // james' friends should be defined }, ]; const hasFriends = (person) => { - return !(person.friends === false); + // return !(person.friends === false); + return !(person.friends === undefined); }; const jamesHolden = team[3]; const jamesHasFriends = hasFriends(jamesHolden); console.log(jamesHasFriends); + diff --git a/JS & TS/two.js b/JS & TS/two.js index 9664a6f..4a96d91 100644 --- a/JS & TS/two.js +++ b/JS & TS/two.js @@ -17,6 +17,8 @@ const team = [ { name: "james", place: "earth", + // james' earns value is not defined + earns: false, }, ]; diff --git a/Web-Dev/css-is-awesome/initial.css b/Web-Dev/css-is-awesome/initial.css index 3bf343a..95b796a 100644 --- a/Web-Dev/css-is-awesome/initial.css +++ b/Web-Dev/css-is-awesome/initial.css @@ -1,15 +1,16 @@ body { - min-height: 90vh; - background: linear-gradient(90deg, #0c97fa 0%, #16e1f5 100%); - display: grid; - place-items: center; + min-height: 90vh; + background: linear-gradient(90deg, #0c97fa 0%, #16e1f5 100%); + display: grid; + place-items: center; } .container { - background: white; - width: 120px; - height: 200px; - padding-inline: 0.3rem; - font-size: 3rem; - border-radius: 0.3rem; -} \ No newline at end of file + background: white; + /* Do not give a fixed width */ + /* width: 120px; */ + height: 200px; + padding-inline: 0.3rem; + font-size: 3rem; + border-radius: 0.3rem; +}