├── 01_datatypes └── datatypes.cpp ├── 02_if else ├── I_01_if else.cpp ├── I_02_if elseif else.cpp ├── I_03_armstrong no.cpp ├── I_04_nested if else (check max).cpp ├── I_05_oddeven.cpp ├── I_06_triangle type.cpp └── I_07_vowels and consonants.cpp ├── 03_loops ├── L_01_while loop for 10 times.cpp ├── L_02_while loop 2 conditions.cpp ├── L_03_infinite loop.cpp ├── L_04_even nos.cpp ├── L_05_natural nos.cpp └── L_06_odd nos below 10.cpp ├── 04_break continue ├── 03_prime non prime.cpp ├── 04_odd even.cpp ├── BC_01_ continue statement.cpp └── BC_02_break statement.cpp ├── 05_switch ├── 01_basic.cpp └── 02_calculator.cpp ├── 06_operators ├── O_01_ pre increment.cpp ├── O_02_post decrement.cpp ├── O_03_pre+post increment.cpp ├── O_04_ incr pre post mix prob.cpp ├── O_05_relational.cpp ├── O_05_relational_more than or equal to.cpp ├── O_06_logical_div by both 2 and 3.cpp └── O_07_(bitwise,assign,misc).cpp ├── 07_patterns ├── P_01_inverted no.cpp ├── P_02_zero one.cpp ├── P_03_no pyramid.cpp ├── P_04_solid rhombus.cpp ├── P_05_pascals triangle.cpp ├── P_06_rectangle.cpp ├── P_07_hollow rectangle.cpp ├── P_08_inverted half pyramid.cpp ├── P_09_half pyramid 180 rotation.cpp ├── P_10_half pyramid using nos.cpp ├── P_12_butterfly.cpp └── P_13_play button.cpp ├── 08_functions ├── 09_prime sieve.cpp ├── 10_prime factorization.cpp ├── F_01_1st n natural nos.cpp ├── F_02_ pythogorean triplet.cpp ├── F_03_euclid algo to find GCD.cpp ├── F_04_calculate ncr.cpp ├── F_05_factorial.cpp ├── F_06_fibenacci sequence.cpp ├── F_07_ print all primes btw 2 nos.cpp └── F_08_inclusion exclusion principle.cpp ├── 09_array ├── A_00_basic.cpp ├── A_01_maximum till i.cpp ├── A_02_ first repeating element.cpp ├── A_03_smalest positive missing.cpp └── A_04_find min & max.cpp ├── 10_pointers ├── P_16_pointers and arrays.cpp ├── P_17_pointer arithmetic.cpp ├── P_18_ basic.cpp ├── P_19_pointer to pointer.cpp ├── P_20_pointer to functions1.cpp └── P_21_pointer to functions2.cpp ├── 11_strings ├── S_01_convert to upper and lower cases.cpp ├── S_02_upper case transform.cpp ├── S_03_biggest no from numeric s.cpp ├── S_04_occur max times.cpp ├── S_05_string declaration types 3.cpp ├── S_06_string functions 15.cpp └── S_07_balanced parentheses.cpp ├── LICENSE └── README.md /01_datatypes/datatypes.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | /* 4 | 5 | 6 | 7 | */ 8 | 9 | #include 10 | using namespace std; 11 | 12 | int main(){ 13 | 14 | int a; //declaration 15 | a=12; //initialisation 16 | 17 | cout<<"size of int "< 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n=15; 11 | if(n>10) 12 | { 13 | cout<<"greater"; 14 | } 15 | else 16 | { 17 | cout<<"smaller"; 18 | } 19 | return 0; 20 | } 21 | 22 | //greater 23 | -------------------------------------------------------------------------------- /02_if else/I_02_if elseif else.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | /* 4 | print greater than elements 5 | use if else lader 6 | 7 | */ 8 | 9 | 10 | //IF-ELSEIF-ELSE 11 | 12 | #include 13 | using namespace std; 14 | 15 | int main () 16 | { 17 | int tt; 18 | cin>>tt; 19 | while(tt--){ 20 | 21 | int n; 22 | cin>>n; 23 | 24 | if(n>1 && n<10) 25 | cout<<"greater than 1 and less than 10"; 26 | 27 | else if (n>=20 && n<=30) 28 | cout<<"greater than 20 nad less than 30 "; 29 | 30 | else 31 | cout<<"greater than 30"; 32 | } 33 | return 0; 34 | } 35 | 36 | // 37 | //3 38 | //2 39 | //greater than 1 and less than 10 40 | //21 41 | //greater than 20 nad less than 30 42 | //65 43 | //greater than 30 44 | 45 | -------------------------------------------------------------------------------- /02_if else/I_03_armstrong no.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | //armstrong number (cubes and add) 4 | 5 | 6 | //Armstrong number is a number that is equal to the sum of cubes of its digits. 7 | //For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers 8 | 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | int main(){ 14 | int n; 15 | cin>>n; 16 | 17 | int sum=0; 18 | int originaln=n; 19 | while(n>0){ 20 | int lastdigit = n%10; 21 | sum+= pow(lastdigit, 3); 22 | n = n/10; 23 | } 24 | 25 | if(sum==originaln){ 26 | cout<<"armstrong"< 12 | 13 | using namespace std; 14 | 15 | int main() 16 | { 17 | int a,b,c; 18 | cin>>a>>b>>c; 19 | 20 | //a is greater than b 21 | if(a>b){ 22 | if(a>c){ 23 | cout<c) 33 | cout< 12 | 13 | using namespace std; 14 | 15 | int main() 16 | { 17 | int n; 18 | cin>>n; 19 | 20 | if(n%2!=0) 21 | cout<<"odd"< 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | 10 | int sidea, sideb, sidec; 11 | cout << "Input three sides of triangle: \n "; 12 | cin >> sidea >> sideb >> sidec; 13 | 14 | if (sidea == sideb && sideb == sidec) 15 | { 16 | cout << "This is an equilateral triangle. \n "; 17 | } 18 | else if (sidea == sideb || sidea == sidec || sideb == sidec) 19 | { 20 | cout << "This is an isosceles triangle. \n "; 21 | } 22 | else 23 | { 24 | cout << "This is a scalene triangle. \n "; 25 | } 26 | 27 | return 0; 28 | } 29 | 30 | 31 | // 12 3 4 32 | //This is a scalene triangle. 33 | 34 | // 1 2 2 35 | //This is an isosceles triangle. 36 | 37 | // 12 12 12 38 | //This is an equilateral triangle. 39 | -------------------------------------------------------------------------------- /02_if else/I_07_vowels and consonants.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | /* 4 | 5 | 6 | 7 | */ 8 | 9 | 10 | #include 11 | using namespace std; 12 | 13 | int main() 14 | { 15 | char c; 16 | int isLowercaseVowel, isUppercaseVowel; 17 | 18 | cout << "Enter an alphabet: "; 19 | cin >> c; 20 | 21 | isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); 22 | 23 | isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); 24 | 25 | if (isLowercaseVowel || isUppercaseVowel) 26 | cout << c << " is a vowel."; 27 | else 28 | cout << c << " is a consonant."; 29 | 30 | return 0; 31 | } 32 | 33 | 34 | //Enter an alphabet: a 35 | //a is a vowel. 36 | 37 | //Enter an alphabet: k 38 | //k is a consonant. 39 | 40 | -------------------------------------------------------------------------------- /03_loops/L_01_while loop for 10 times.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | //while loop 4 | //infinite loop for 10 times 5 | 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int i=0; //i is just our varibal 13 | while(i<10) 14 | { 15 | cout<<"hi"< 13 | 14 | using namespace std; 15 | 16 | int main() 17 | { 18 | int t; 19 | cin>>t; 20 | while(t--){ 21 | 22 | int i; 23 | cin>>i; 24 | while(i<10 && i>5) 25 | { 26 | cout<<"hi"< 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | while(1) //no condition so it goes into infinite loop 17 | { 18 | cout<<"hi"; 19 | } 20 | return 0; 21 | } 22 | 23 | 24 | 25 | 26 | //hihihihihihihihihihihihihihihihihihihihihihihihihihihi 27 | 28 | 29 | -------------------------------------------------------------------------------- /03_loops/L_04_even nos.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | //print even numbers upto 10th element 4 | //by using for loop 5 | 6 | #include 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | for(int i=1; i<=10; i++) //equal to symbol is compulsory without which we get onnly 9 elements 12 | { 13 | cout< 7 | 8 | using namespace std; 9 | int main() 10 | { 11 | for(int i=0 ;i<10 ;i++ ) 12 | { 13 | cout< 7 | 8 | using namespace std; 9 | int main() 10 | { 11 | for(int i=0 ;i<10 ;i++ ) 12 | { 13 | if((i%2)!=0) //check with remainder and if it is not equal to zero then it is odd 14 | { 15 | cout< 11 | using namespace std; 12 | 13 | int main() { 14 | 15 | int n; 16 | cin>>n; 17 | bool flag=0; 18 | 19 | for(int i=2;i*i<=n;i++){ 20 | if(n%i==0){ 21 | cout<<"Non-Prime"< 11 | using namespace std; 12 | 13 | int main() { 14 | 15 | int n; 16 | cout<<"Enter a number: "; 17 | cin>>n; 18 | 19 | for (int i=1; i<=n; i++) { 20 | 21 | if (i%2==0) { // i is even 22 | continue; 23 | } 24 | cout< 14 | 15 | using namespace std; 16 | 17 | int main() 18 | { 19 | 20 | for(int i=1; i<=30; i++) //date in month from 1 to 30 21 | if(i%2==0) 22 | continue; //continue hit hothe hi, jo hamara next statement hai go out vo execute nahi hogi, we will skip to the next iteration 23 | else 24 | cout<<"go out"< 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | int pocketMoney=3000; 17 | for(int i=1; i<=30; i++){ //date in month from 1 to 30 18 | if(i%2==0) 19 | continue; //continue hit hothe hi, jo hamara next statement hai go out vo execute nahi hogi, we will skip to the next iteration 20 | 21 | if(pocketMoney==0) //when pocket money becomes zero we come outta the loop 22 | break; 23 | 24 | else 25 | cout<<"go out"< 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--){ 11 | 12 | int n; 13 | cin>>n; 14 | 15 | switch(n) 16 | { 17 | case 10 : cout<<"value is 10"; 18 | break; 19 | 20 | case 15 : cout<< "value is 15"; 21 | break; 22 | 23 | default : cout<< "not found"; 24 | } 25 | 26 | } 27 | return 0; 28 | } 29 | 30 | 31 | 32 | //3 33 | //10 34 | //value is 10 35 | //16 36 | //not found 37 | //15. 38 | //value is 15 39 | -------------------------------------------------------------------------------- /05_switch/02_calculator.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | //implement a simple calculator using switch 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | float n1, n2; 10 | cout << "Input 2 numbers: "; 11 | cin >> n1 >> n2; 12 | 13 | char op; 14 | cout << "input an operator"; 15 | cin >> op; 16 | 17 | switch (op) 18 | { 19 | case '+': 20 | cout << n1 + n2 << endl; 21 | break; 22 | case '-': 23 | cout << n1 - n2 << endl; 24 | break; 25 | case '*': 26 | cout << n1 * n2 << endl; 27 | break; 28 | case '/': 29 | cout << n1 / n2 << endl; 30 | break; 31 | 32 | default: 33 | cout << "Enter another operator:" << endl; 34 | break; 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | 41 | //Input 2 numbers: 5 6 42 | //input an operator: + 43 | //11 44 | // 45 | //Input 2 numbers: 79 90 46 | //input an operator* 47 | //7110 48 | 49 | -------------------------------------------------------------------------------- /06_operators/O_01_ pre increment.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int a=10; //initially a will be 10 10 | int b; //and b will be 0 11 | 12 | b=++a; //declaration.....pehle a ki value increment horahi, fir jake b me stor horahi 13 | cout< 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int a=10; 13 | int b; 14 | 15 | b=a++;// 10 will go in b then increment 16 | cout< 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int i=1; //initially i is 1 12 | 13 | //1 //3 14 | i=i++ + ++i; //i++ means 1 on hand 1 in mind = 2, ++i=2 on hand 15 | cout< 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | 10 | //initialize 3 variables 11 | int i=1; 12 | int j=2; 13 | int k; 14 | 15 | //1 //2 //1 //2 //3 //4 16 | k=i + j + i++ + j++ + ++i + ++j; 17 | cout< 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int n; 12 | cin>>n; 13 | 14 | if(n>=10) 15 | cout<<"no is greater than or equal to 10"< 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int n; 12 | cin>>n; 13 | 14 | if(n>=10) 15 | cout<<"no is greater than or equal to 10"< 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int tt; 13 | cin>>tt; 14 | while(tt--){ 15 | int n; 16 | cin>>n; 17 | 18 | if(n%2==0 && n%3==0) 19 | cout<<" divisible by 2 and 3"<>1 (0100) will give 0010 which is 2 ka decimal.... 12 | 13 | //a<>n = a divided by 2 power n 15 | 16 | #include 17 | 18 | using namespace std; 19 | 20 | int main() 21 | { 22 | // int a; 23 | // cout<<&a; 24 | return 0; 25 | } 26 | // 27 | ////assignment operators 28 | // 29 | // = assigns right operand to left operand 30 | // += assigns sum of two operands to the left operand a+=b means a=a+b 31 | // -= diff 32 | // *= product 33 | // /= quotient 34 | 35 | //miscellaneous operators 36 | 37 | //sizeof() //returns the size of the variable eg:int a;.....sizeof(a)-->4 cuz integer takes 4 bytes 38 | //condition? x:y //returns value of x if condition is true or else value of y 39 | //cast //convert one data type to another....eg: char ch='a' int(ch)-->97 (it will cout the ascii value) 40 | //, //causes a sequence of operations to be performed 41 | //& //reference operator returns address of the variable 42 | //* //pointer to a variable 43 | 44 | 45 | //refer precendence and asociativity table 46 | 47 | -------------------------------------------------------------------------------- /07_patterns/P_01_inverted no.cpp: -------------------------------------------------------------------------------- 1 | //to print inverted pattern 2 | // 3 | //1 2 3 4 5 4 | //1 2 3 4 5 | //1 2 3 6 | //1 2 7 | //1 8 | 9 | #include 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | int n; 15 | cin>>n; 16 | for(int i=1; i<=n; i++) 17 | { 18 | for(int j=1; j<=n+1-i; j++) 19 | { 20 | cout< 13 | using namespace std; 14 | 15 | int main() 16 | { 17 | int n; 18 | cin>>n; 19 | 20 | for(int i=1; i<=n; i++){ 21 | for(int j=1; j<=i; j++){ 22 | if((i+j)%2==0){ 23 | cout<<" 1"; 24 | } 25 | else{ 26 | cout<<" 0"; 27 | } 28 | } 29 | cout< 12 | 13 | using namespace std; 14 | 15 | int main() 16 | { 17 | int n; 18 | cin>>n; 19 | 20 | for(int i=1; i<=n; i++){ 21 | for(int j=1; j<=n-i; j++){ 22 | cout<<" "; 23 | } 24 | for(int j=1; j<=i; j++){ 25 | cout< 17 | 18 | using namespace std; 19 | 20 | int main() 21 | { 22 | int n; 23 | cin>>n; 24 | 25 | for(int i=1; i 12 | using namespace std; 13 | 14 | int fact(int n){ 15 | int factorial=1; 16 | for(int i=2; i<=n; i++){ 17 | factorial*=i; 18 | } 19 | return factorial; 20 | 21 | } 22 | 23 | int main(){ 24 | 25 | int n; 26 | cin>>n; 27 | 28 | for(int i=0; i<=n; i++){ 29 | for(int j=0; j<=i; j++){ 30 | cout< 14 | 15 | using namespace std; 16 | 17 | int main() 18 | { 19 | int n,m; //taking rows and coloums 20 | cin>>n>>m; 21 | 22 | for(int i=1;i<=n;i++){ 23 | for(int j=1;j<=m;j++){ 24 | cout<<"*"; 25 | } 26 | cout< 15 | 16 | using namespace std; 17 | 18 | int main() 19 | { 20 | int n,m; 21 | cin>>n>>m; 22 | 23 | for(int i=1;i<=n;i++){ //rows k liye 24 | for(int j=1;j<=m;j++){ //coloums k liye 25 | if(i==1 || i==n || j==1 || j==m){ 26 | cout<<"*"; 27 | } 28 | // else if(j==1 || j==m){ 29 | // cout<<"*"; 30 | // } 31 | else{ 32 | cout<<" "; 33 | } 34 | } 35 | cout< 16 | 17 | using namespace std; 18 | 19 | int main() 20 | { 21 | int n; //only 1 input 22 | cin>>n; 23 | 24 | for(int i=n;i>=1;i--){ //n to 1 25 | for(int j=1;j<=i;j++) //j eqal to row no. 26 | cout<<"*"; 27 | cout< 19 | 20 | using namespace std; 21 | 22 | int main() 23 | { 24 | int n; 25 | cin>>n; 26 | 27 | for(int i=1;i<=n;i++){ 28 | for(int j=1;j<=n; j++){ 29 | if(j<=n-i){ 30 | cout<<" "; 31 | } 32 | else{ 33 | cout<<"*"; 34 | } 35 | } 36 | cout< 17 | 18 | using namespace std; 19 | 20 | int main() 21 | { 22 | int n; 23 | cin>>n; 24 | 25 | for(int i=1;i<=n;i++){ 26 | for(int j=1;j<=i;j++){ 27 | cout< 31 | 32 | using namespace std; 33 | 34 | int main() 35 | 36 | { 37 | int r,i,j; 38 | cin>>r; 39 | 40 | for(i=1;i<=r;i++) 41 | { 42 | for(j=1;j<=i;j++) 43 | cout<<"*"; 44 | for(j=1;j<=2*(r-i);j++) 45 | cout<<" "; 46 | for(j=1;j<=i;j++) 47 | cout<<"*"; 48 | cout<<"\n"; 49 | } 50 | 51 | for(i=r;i>=1;i--) 52 | {s 53 | for(j=1;j<=i;j++) 54 | cout<<"*"; 55 | for(j=1;j<=2*(r-i);j++) 56 | cout<<" "; 57 | for(j=1;j<=i;j++) 58 | cout<<"*"; 59 | cout<<"\n"; 60 | } 61 | return 0; 62 | } 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /07_patterns/P_13_play button.cpp: -------------------------------------------------------------------------------- 1 | //play button pattern 2 | 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int n; 10 | cout<<"enter number of columns:"; 11 | cin>>n; 12 | 13 | for(int i=1; i<=n; i++) 14 | { 15 | for(int j=1; j<=i; j++) 16 | { 17 | cout<<"*"; 18 | } 19 | cout<=1; i--) 22 | { 23 | for(int j=1; j<=i; j++) 24 | { 25 | cout<<"*"; 26 | } 27 | cout< 11 | using namespace std; 12 | 13 | void primeSieve(int n){ 14 | 15 | int prime[100]={0}; 16 | 17 | for(int i=2;i<=n;i++){ //satrt with 2 18 | if(prime[i]==0){ //checdk if unmarked 19 | for(int j=i*i;j<=n;j+=i){ 20 | prime[j]=1; 21 | } 22 | } 23 | } 24 | 25 | for(int i=2;i<=n;i++){ 26 | if(prime[i]==0){ 27 | cout<>n; 37 | 38 | primeSieve(n); 39 | 40 | 41 | return 0; 42 | } 43 | 44 | 45 | 46 | //30 47 | //2 3 5 7 11 13 17 19 23 29 48 | 49 | -------------------------------------------------------------------------------- /08_functions/10_prime factorization.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | /* 4 | 5 | prime factorization using sieve 6 | 7 | */ 8 | 9 | 10 | 11 | #include 12 | using namespace std; 13 | 14 | 15 | void primefactor(int n){ 16 | 17 | int spf[100]={0}; 18 | for(int i=2;i<=n;i++){ 19 | spf[i]=i; 20 | } 21 | 22 | for(int i=2;i<=n;i++){ 23 | if(spf[i]==i){ 24 | for(int j=i*i;j<=n;j+=i){ 25 | if(spf[j]==j){ 26 | spf[j]=i; 27 | } 28 | } 29 | } 30 | } 31 | 32 | while(n!=1){ 33 | cout<>n; 44 | 45 | primefactor(n); 46 | return 0; 47 | } 48 | 49 | // 50 | //60 51 | //2 2 3 5 52 | 53 | -------------------------------------------------------------------------------- /08_functions/F_01_1st n natural nos.cpp: -------------------------------------------------------------------------------- 1 | //author :shreyamalogi 2 | 3 | //SUM OF FIRST N NATURAL NUMBERS 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | int sum(int n){ 10 | int ans =0; 11 | for(int i=1;i<=n;i++) 12 | ans += i; 13 | return ans; 14 | } 15 | 16 | int main() 17 | { 18 | int n; 19 | cin>>n; 20 | 21 | cout< 7 | 8 | using namespace std; 9 | 10 | bool check(int x, int y, int z) //return type will be bool 11 | { 12 | int a = max(x, max(y,z)); //store max value in a 13 | int b, c; 14 | 15 | if(a==x){ 16 | b=y; 17 | c=z; 18 | } 19 | else if(a==y){ 20 | b=x; 21 | c=z; 22 | } 23 | else{ 24 | b=x; 25 | c=y; 26 | } 27 | 28 | if(a*a == b*b + c*c) 29 | return true; 30 | else 31 | return false; 32 | } 33 | 34 | 35 | int main() 36 | { 37 | int x,y,z; 38 | cin>>x>>y>>z; 39 | 40 | if (check(x,y,z)) 41 | { 42 | cout<<"yes, it is pythogorean triplet"; 43 | 44 | } 45 | else 46 | { 47 | cout<<"not a pythogorean triplet"; 48 | } 49 | return 0; 50 | } 51 | 52 | // 53 | //3 4 5 54 | //pythogorean triplet. 55 | -------------------------------------------------------------------------------- /08_functions/F_03_euclid algo to find GCD.cpp: -------------------------------------------------------------------------------- 1 | //LOGIC 2 | // 3 | //24 = 2*2*2*3 4 | //42 = 2*3*7 5 | //COMMON = 2*3=6 6 | // 7 | //42-24=18 8 | //24-18=6 9 | //18-6=12 10 | //12-6=6 11 | //6-6=0 12 | // 13 | //OR 14 | // 15 | //42%24=18 16 | //24%18=5 17 | //18%6=0 18 | 19 | //number theory 20 | 21 | #include 22 | using namespace std; 23 | 24 | int gcd(int a, int b){ 25 | while(b!=0){ //jb tk b ki value 0 nai hoti 26 | int rem=a%b; //me sabse pehle remainder find out karungi 27 | a=b; //a me b ki value dalenge 28 | b=rem; //aur b me remainder ki value 29 | } 30 | return a; 31 | } 32 | //jb hamara b ki value 0 hojayega toh apan return karenge a ki value 33 | 34 | int main() 35 | { 36 | int a,b; //declare a and b 37 | cin>>a>>b; //user se input lelete 38 | cout< 6 | #include 7 | using namespace std; 8 | 9 | int fact(int n){ 10 | int factorial=1; 11 | for(int i=2; i<=n; i++){ 12 | factorial=factorial*i; 13 | } 14 | return factorial; 15 | } 16 | 17 | int main(){ 18 | 19 | int n,r; 20 | cin>>n>>r; 21 | 22 | int ans = fact(n)/(fact(r)*fact(n-r)); 23 | cout< 7 | #include 8 | 9 | using namespace std; 10 | 11 | int fact(int n){ 12 | int factorial=1; 13 | for(int i=2; i<=n; i++){ 14 | factorial=factorial*i; 15 | } 16 | return factorial; 17 | } 18 | 19 | 20 | int main(){ 21 | 22 | int n; 23 | cin>>n; 24 | 25 | int ans = fact(n); 26 | cout< 4 | #include 5 | 6 | using namespace std; 7 | 8 | void fibenacci(int n){ 9 | 10 | int t1=0; 11 | int t2=1; 12 | int nextTerm; 13 | 14 | for(int i=1; i>n; 27 | 28 | fibenacci(n); 29 | 30 | 31 | return 0; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /08_functions/F_07_ print all primes btw 2 nos.cpp: -------------------------------------------------------------------------------- 1 | //PRINT ALL PRIME NOS BETWEEN 2 GIVEN NUMBERS 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | bool isprime(int num){ 8 | for(int i=2; i>a>>b; 21 | 22 | for(int i=a; i<=b; i++){ 23 | if(isprime(i)){ 24 | cout< 11 | 12 | using namespace std; 13 | 14 | int divisible(int n, int a, int b){ 15 | int c1=n/a; 16 | int c2=n/b; 17 | int c3=n/(a*b); 18 | 19 | return c1+c2-c3; 20 | 21 | } 22 | 23 | int main() 24 | { 25 | int n,a,b; 26 | cin>>n>>a>>b; 27 | cout< 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | int n; //declare size 17 | cin>>n; //take in the size 18 | int a[n]; //declare array of size n 19 | //cin>>a[0]; cin>>a[1].... 20 | //but 21 | for(int i=0; i>a[i]; //full array kosam 23 | 24 | for(int i=0; i 13 | 14 | using namespace std; 15 | 16 | int main() 17 | { 18 | int mx=-1999999; //give any small value so that we can find the maximum value 19 | int n; 20 | cin>>n; 21 | int a[n],i; 22 | for(i=0; i>a[i]; 24 | 25 | //main logic 26 | for(i=0; i 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int n; 13 | cin>>n; 14 | int a[n]; 15 | for(int i=0;i>a[i]; 18 | } 19 | 20 | 21 | const int N = 1e6+2; //10 power 6, const is cuz we cant change n ki value 22 | int idx[N]; //DECLARING OUR IDX ARRAY OF SIZE CAPITAL N 23 | for(int i=0; i 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | int n; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | 15 | const int N= 1e6+2; 16 | bool check[N]; //our check array 17 | for(int i=0;i=0) //non negitive 27 | { 28 | check[a[i]]= 1; //check of a[i] ko true mark kardo 29 | 30 | } 31 | 32 | } 33 | int ans= -1; //initialize 34 | for(int i=1;i 6 | //#include 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int n; 12 | cin>>n; 13 | 14 | int a[n]; 15 | for(int i=0;i>a[i]; 16 | 17 | // each element ko maximum aur minimum value se compare karenge 18 | // aur jaha pe currect max zyada miljatha hai toh hum maximum ko update kardete hai 19 | // aur jaha pe km miljatha hai toh minimum ko update kardete hai 20 | 21 | // int mx; 22 | // int mn; //just delaring is not enough we have to even initialize it 23 | 24 | int mx = INT_MIN; 25 | int mn = INT_MAX; 26 | 27 | for(int i=0;imx) //if hamara number(unknown) 30 | // mx= a[i]; //toh mx ko update kardo apne no se 31 | // if(a[i] 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | //by using array 11 | int a[]={10,20,30}; 12 | cout<<*a< 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int a=10; 12 | int* aptr = &a; 13 | 14 | cout<<*aptr< 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | int a=10; 12 | int *p; 13 | p=&a; 14 | 15 | cout<<*p< 6 | 7 | using namespace std; 8 | 9 | void increment(int a){ 10 | a++; 11 | } 12 | 13 | int main() 14 | { 15 | int a=2; 16 | increment(a); //pass by value 17 | cout< 6 | 7 | using namespace std; 8 | 9 | swap(int *a, int*b){ 10 | int temp = *a; 11 | *a = *b; 12 | *b = temp; 13 | } 14 | //swap(int a, int b){ 15 | // int temp = a; 16 | // a = b; 17 | // b = temp; 18 | //} 19 | 20 | int main() 21 | { 22 | int a=2; 23 | int b=4; 24 | 25 | int *aptr=&a; 26 | int *bptr=&b; //without using 2 lines we can access adress 27 | 28 | swap(aptr,bptr); //or &a, &b 29 | cout< 8 | 9 | using namespace std; 10 | 11 | int main() 12 | { 13 | string str = "aggyfggfrnjl"; 14 | 15 | // convert to upper case 16 | for(int i=0; i='a' && str[i]<='z') //koi bhi character string ka is greater than or equal to a and less than equal to z 18 | str[i]-=32; 19 | } 20 | cout<='A' && str[i]<='Z') 25 | str[i]+=32; 26 | } 27 | cout< 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string s = "hwkefHkw"; 11 | 12 | // TO CONVERT TO UPPER CASE 13 | transform(s.begin(),s.end(), s.begin(), ::toupper); 14 | cout< 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | string s = "572305729898"; 13 | sort(s.begin(), s.end(), greater()); // 2 arguments pass karne ka hai ek ye sort wala argument dusra ye greater int wala argument 14 | cout< 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | string s ="ekwhfheglweg"; 17 | int freq[26]; 18 | 19 | for(int i=0; i<26; i++) 20 | freq[i]=0; 21 | 22 | for(int i=0; imaxF){ 31 | maxF = freq[i]; 32 | ans = i+'a'; 33 | } 34 | } 35 | cout< 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | string str; 13 | 14 | cin>>str; 15 | cout< 27 | 28 | using namespace std; 29 | 30 | int main() 31 | { 32 | string str; 33 | string str1(5, 's'); // declare with size (it prints n character 5 times) 34 | cout< 44 | 45 | using namespace std; 46 | 47 | int main() 48 | { 49 | string str = "shreya malogi"; 50 | cout< 5 | 6 | using namespace std; 7 | 8 | int main() 9 | { 10 | string str; 11 | //cin>>str //wont work (panga hosaktha kyunki it will print just hfh 12 | getline(cin, str); //pure k pure sentence ko input karalega 13 | cout< 31 | 32 | using namespace std; 33 | 34 | int main() 35 | { 36 | string str; 37 | 38 | string s1 = "fam"; 39 | string s2 = "ily"; 40 | 41 | //method 1 42 | s1.append(s2); // agr s1 me append karana s2 ko 43 | cout< 66 | 67 | using namespace std; 68 | 69 | int main() 70 | { 71 | string s1 = "nincompoop"; 72 | cout< 88 | 89 | using namespace std; 90 | 91 | int main() 92 | { 93 | string s1 = "nincompoop"; 94 | 95 | for(int i=0; i 121 | 122 | using namespace std; 123 | 124 | int main() 125 | { 126 | int x=786; 127 | cout< 141 | 142 | using namespace std; 143 | 144 | int main() 145 | { 146 | string s1 = "nincompoop"; 147 | 148 | string s = s1.substr(6,4); //(KONSE INDEX SE , KITNE CHARATERS agae TK chahiyae) 149 | cout< 164 | //#include me baithe hotha ye sort function 165 | //#include me baita hotha ye strings sb 166 | using namespace std; 167 | 168 | int main() 169 | { 170 | string s1 = "acazdgweitupmbnhg"; 171 | sort(s1.begin(), s1.end()); // it will sort from a to z in ascending order 172 | 173 | cout< 188 | 189 | using namespace std; 190 | 191 | int main() 192 | { 193 | string s1 ="nincompoop"; 194 | s1.insert(2,"lol"); //(KIS INDEX PE, STRING NAME TO BE INSERTED 195 | cout< 210 | 211 | using namespace std; 212 | 213 | int main() 214 | { 215 | string s1 = "nincompoop"; 216 | 217 | cout< 235 | 236 | using namespace std; 237 | 238 | int main() 239 | { 240 | string s1= "nincompoop"; 241 | 242 | s1.erase(3,2); //arguments me we must send (index,character) 243 | cout< 254 | 255 | using namespace std; 256 | 257 | int main() 258 | { 259 | string s1 = "abc"; 260 | cout< 282 | 283 | using namespace std; 284 | 285 | int main() 286 | { 287 | string s1 = "abc"; 288 | string s2 = "xyz"; 289 | cout< 301 | 302 | using namespace std; 303 | 304 | int main() 305 | { 306 | string s1 = "abc"; 307 | string s2 = "abc"; 308 | 309 | cout< 8 | using namespace std; 9 | string isBalanced(string s){ 10 | stack st; 11 | for(auto c:s){ 12 | switch (c){ 13 | //declare the cases of opening brackets and push it into the stack 14 | case '(': 15 | case '{': 16 | case '[': 17 | st.push(c); 18 | break; 19 | 20 | //intitialize case of closing bracket seoperate seperately 21 | case '}': 22 | if(st.empty() || st.top()!='{' ) //if stack is empty or the top element in the stack is not equal to its partner the say no 23 | return "NO"; //return no 24 | st.pop(); //pop out 25 | break; //and break 26 | //copy paste same 27 | case ']': 28 | if(st.empty() || st.top()!='[') 29 | return "NO"; 30 | st.pop(); 31 | break; 32 | case ')': 33 | if(st.empty() || st.top()!='(') 34 | return "NO"; 35 | st.pop(); 36 | break; 37 | default: break; //dont forget to mention default 38 | } 39 | } 40 | return st.empty() ? "YES":"NO"; //check if stack is empty or not 41 | } 42 | 43 | int main(){ 44 | int t; 45 | cin >> t; 46 | for(int i = 0; i < t; i++){ 47 | string s; 48 | cin >> s; 49 | cout << isBalanced(s) << endl; 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 CodeMacrocosm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # 📚 C++ Programming 10-Day Training 3 | 4 | 5 | Welcome to the C++ Programming 10-Day Training repository led by Shreya Malogi! 🌟 , a hands-on program designed to provide you with practical knowledge and intensive experience in C++ programming. 🚀 6 | 7 | ## 📖 About This Training 8 | 9 | This comprehensive 10-day training program is designed to immerse you in the world of C++ programming and equip you with the skills needed to excel in this versatile language. Each day of training focuses on key concepts and practical exercises to ensure you build a strong foundation in C++. 10 | 11 | ## 🌟 Why C++? 12 | 13 | C++ is a powerful and versatile programming language used in a wide range of applications, from game development to system programming. By learning C++, you open up opportunities to work on exciting projects and contribute to the world of technology. 14 | 15 | ## 📜 Training Resources 16 | 17 | In this repository, you'll find a structured collection of chapters and topics that cover essential aspects of C++ programming. Each section is tailored to the daily training schedule and includes hands-on exercises to reinforce your learning. 18 | 19 | ## 📚 What's Covered? 20 | 21 | Here's an overview of what's covered during this 10-day training: 22 | 23 | 1. **Day 1: Datatypes** 📊 24 | - Understanding fundamental data types in C++. 25 | 26 | 2. **Day 2: If-Else Statements** 🤔 27 | - Exploring conditional statements for decision-making. 28 | 29 | 3. **Day 3: Loops** 🔄 30 | - Learning about loops for repetitive tasks. 31 | 32 | 4. **Day 4: Break and Continue** ⏸️ 33 | - Mastering control flow with break and continue statements. 34 | 35 | 5. **Day 5: Switch Statements** 🔄 36 | - Diving into switch statements for multi-case scenarios. 37 | 38 | 6. **Day 6: Operators** 🤖 39 | - Exploring C++ operators for various operations. 40 | 41 | 7. **Day 7: Patterns** 🌟 42 | - Creating interesting patterns using loops and characters. 43 | 44 | 8. **Day 8: Functions** 📦 45 | - Understanding functions for modular and reusable code. 46 | 47 | 9. **Day 9: Arrays** 📊 48 | - Working with arrays to store and manipulate data. 49 | 50 | 10. **Day 10: Pointers and Strings** 🔗📝 51 | - Exploring pointers for memory management and manipulating character strings in C++. 52 | 53 | ## 📜 License 54 | 55 | This training program is open-source and distributed under the MIT License. 56 | 57 | MIT License 58 | 59 | Copyright (c) 2021 CodeMacrocosm 60 | 61 | ## ⭐ Star This Repository 62 | 63 | If you find this C++ Programming 10-Day Training helpful and informative, don't forget to star this repository to show your appreciation! ⭐ 64 | 65 | ## 🚀 Let's Get Started! 66 | 67 | Embark on your 10-day journey to becoming a C++ programming pro by exploring the chapters and topics provided in this repository. We hope you find these resources valuable. 68 | 69 | Happy Learning! 🖥️ 70 | 71 | 72 | --------------------------------------------------------------------------------