├── Working with Numbers ├── 06.cpp ├── 07.cpp ├── 08.cpp ├── 09.cpp ├── 11.cpp ├── 12.cpp ├── 13.cpp ├── 14.cpp ├── 15.cpp ├── 16.cpp ├── 17.cpp ├── 18.cpp ├── 20.cpp ├── 21.cpp ├── 22.cpp ├── 23.cpp ├── 24.cpp ├── 25.cpp ├── 10.cpp ├── 01.exe ├── 02.exe ├── 03.exe ├── 04.exe ├── 19.exe ├── 26.cpp ├── 19.cpp ├── 04.cpp ├── 05.cpp ├── 02.cpp ├── 01.cpp └── 03.cpp ├── Important Codes related to Arrays ├── 16.cpp ├── 01.exe ├── 02.exe ├── 03.exe ├── 04.exe ├── 05.exe ├── 06.exe ├── 18.exe ├── 07.cpp ├── 06.cpp ├── 05.cpp ├── 01.cpp ├── 02.cpp ├── 03.cpp ├── 18.cpp └── 04.cpp ├── Getting Started ├── 12.exe ├── 15.exe ├── 16.exe ├── 17.exe ├── 18.exe ├── 19.exe ├── 20.exe ├── 21.exe ├── 22.exe ├── 23.exe ├── 25.exe ├── 26.exe ├── 27.exe ├── 28.exe ├── 2_even_odd.exe ├── 8_Leap_year.exe ├── 11_sum_digits.exe ├── 14_armstrong.exe ├── 9_prime_number.exe ├── 3_first_n_natural.exe ├── 4_sum_of_n_natural.exe ├── 6_greatest_two_no.exe ├── 10_prime_number_range.exe ├── 13_palindrome_number.exe ├── 1_positive_negative.exe ├── 7_greatest_three_no.exe ├── 5_sum_of_no_given_range.exe ├── 24.cpp ├── 2_even_odd.cpp ├── 4_sum_of_n_natural.cpp ├── 6_greatest_two_no.cpp ├── 5_sum_of_no_given_range.cpp ├── 1_positive_negative.cpp ├── 11_sum_digits.cpp ├── 18.cpp ├── 3_first_n_natural.cpp ├── 17.cpp ├── 19.cpp ├── 7_greatest_three_no.cpp ├── 8_Leap_year.cpp ├── 12.cpp ├── 16.cpp ├── 9_prime_number.cpp ├── 10_prime_number_range.cpp ├── 13_palindrome_number.cpp ├── 21.cpp ├── 25.cpp ├── 27.cpp ├── 14_armstrong.cpp ├── 23.cpp ├── 15.cpp ├── 26.cpp ├── 28.cpp ├── 20.cpp └── 22.cpp ├── Operations on Strings ├── 01.exe ├── 02.cpp └── 01.cpp ├── .vscode └── settings.json ├── Codes for Recursion ├── 01.cpp └── 03.cpp └── README.md /Working with Numbers/06.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/07.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/08.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/09.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/11.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/12.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/13.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/14.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/15.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/16.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/17.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/18.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/20.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/21.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/22.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/23.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/24.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Working with Numbers/25.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Important Codes related to Arrays/16.cpp: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------- /Working with Numbers/10.cpp: -------------------------------------------------------------------------------- 1 | //Binary to Octal Conversion -------------------------------------------------------------------------------- /Getting Started/12.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/12.exe -------------------------------------------------------------------------------- /Getting Started/15.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/15.exe -------------------------------------------------------------------------------- /Getting Started/16.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/16.exe -------------------------------------------------------------------------------- /Getting Started/17.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/17.exe -------------------------------------------------------------------------------- /Getting Started/18.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/18.exe -------------------------------------------------------------------------------- /Getting Started/19.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/19.exe -------------------------------------------------------------------------------- /Getting Started/20.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/20.exe -------------------------------------------------------------------------------- /Getting Started/21.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/21.exe -------------------------------------------------------------------------------- /Getting Started/22.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/22.exe -------------------------------------------------------------------------------- /Getting Started/23.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/23.exe -------------------------------------------------------------------------------- /Getting Started/25.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/25.exe -------------------------------------------------------------------------------- /Getting Started/26.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/26.exe -------------------------------------------------------------------------------- /Getting Started/27.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/27.exe -------------------------------------------------------------------------------- /Getting Started/28.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/28.exe -------------------------------------------------------------------------------- /Operations on Strings/01.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Operations on Strings/01.exe -------------------------------------------------------------------------------- /Working with Numbers/01.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Working with Numbers/01.exe -------------------------------------------------------------------------------- /Working with Numbers/02.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Working with Numbers/02.exe -------------------------------------------------------------------------------- /Working with Numbers/03.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Working with Numbers/03.exe -------------------------------------------------------------------------------- /Working with Numbers/04.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Working with Numbers/04.exe -------------------------------------------------------------------------------- /Working with Numbers/19.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Working with Numbers/19.exe -------------------------------------------------------------------------------- /Getting Started/2_even_odd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/2_even_odd.exe -------------------------------------------------------------------------------- /Getting Started/8_Leap_year.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/8_Leap_year.exe -------------------------------------------------------------------------------- /Getting Started/11_sum_digits.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/11_sum_digits.exe -------------------------------------------------------------------------------- /Getting Started/14_armstrong.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/14_armstrong.exe -------------------------------------------------------------------------------- /Getting Started/9_prime_number.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/9_prime_number.exe -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "iostream": "cpp" 4 | }, 5 | "C_Cpp.errorSquiggles": "Disabled" 6 | } -------------------------------------------------------------------------------- /Getting Started/3_first_n_natural.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/3_first_n_natural.exe -------------------------------------------------------------------------------- /Getting Started/4_sum_of_n_natural.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/4_sum_of_n_natural.exe -------------------------------------------------------------------------------- /Getting Started/6_greatest_two_no.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/6_greatest_two_no.exe -------------------------------------------------------------------------------- /Getting Started/10_prime_number_range.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/10_prime_number_range.exe -------------------------------------------------------------------------------- /Getting Started/13_palindrome_number.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/13_palindrome_number.exe -------------------------------------------------------------------------------- /Getting Started/1_positive_negative.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/1_positive_negative.exe -------------------------------------------------------------------------------- /Getting Started/7_greatest_three_no.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/7_greatest_three_no.exe -------------------------------------------------------------------------------- /Important Codes related to Arrays/01.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Important Codes related to Arrays/01.exe -------------------------------------------------------------------------------- /Important Codes related to Arrays/02.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Important Codes related to Arrays/02.exe -------------------------------------------------------------------------------- /Important Codes related to Arrays/03.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Important Codes related to Arrays/03.exe -------------------------------------------------------------------------------- /Important Codes related to Arrays/04.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Important Codes related to Arrays/04.exe -------------------------------------------------------------------------------- /Important Codes related to Arrays/05.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Important Codes related to Arrays/05.exe -------------------------------------------------------------------------------- /Important Codes related to Arrays/06.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Important Codes related to Arrays/06.exe -------------------------------------------------------------------------------- /Important Codes related to Arrays/18.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Important Codes related to Arrays/18.exe -------------------------------------------------------------------------------- /Getting Started/5_sum_of_no_given_range.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krimanisha/PREPINSTA--Top-100-codes/HEAD/Getting Started/5_sum_of_no_given_range.exe -------------------------------------------------------------------------------- /Working with Numbers/26.cpp: -------------------------------------------------------------------------------- 1 | //Finding Roots of a quadratic equation 2 | #include 3 | using namespace std; 4 | int main(){ 5 | float 6 | } -------------------------------------------------------------------------------- /Working with Numbers/19.cpp: -------------------------------------------------------------------------------- 1 | //Calculate the area of a circle 2 | #include 3 | using namespace std; 4 | int main(){ 5 | float r, area; 6 | cin>>r; 7 | area = (3.14*r*r); 8 | cout< 3 | using namespace std; 4 | void valid_perfectsq(long long n){ 5 | if(sqrt(n)) 6 | 7 | } 8 | int main(){ 9 | long long n; 10 | cin>>n; 11 | valid_perfectsq(n); 12 | } -------------------------------------------------------------------------------- /Getting Started/2_even_odd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | if(n%2==0){ 7 | cout<<"Even"< 2 | using namespace std; 3 | int main(){ 4 | int n,sum=0; 5 | cin>>n; 6 | for(int i=1;i<=n;i++){ 7 | sum=sum+i; 8 | } 9 | cout< 2 | using namespace std; 3 | int main(){ 4 | int a,b; 5 | cin>>a>>b; 6 | if(a>b){ 7 | cout< 2 | using namespace std; 3 | int main(){ 4 | int a,b,sum=0; 5 | cin>>a>>b; 6 | for(int i=a;i<=b;i++){ 7 | sum=sum+i; 8 | } 9 | cout< 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | if(n>=0){ 7 | cout<<"Positive Number"< 2 | using namespace std; 3 | void sumOfDigit(int n){ 4 | int sum=0; 5 | while(n!=0){ 6 | sum+=n%10; 7 | n/=10; 8 | } 9 | cout<>n; 14 | sumOfDigit(n); 15 | } -------------------------------------------------------------------------------- /Getting Started/18.cpp: -------------------------------------------------------------------------------- 1 | // Factorial of a number 2 | #include 3 | using namespace std; 4 | void fact(int n){ 5 | int f=1; 6 | for(int i=1; i<=n; i++){ 7 | f*=i; 8 | } 9 | cout<>n; 15 | fact(n); 16 | } -------------------------------------------------------------------------------- /Getting Started/3_first_n_natural.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n,sum=0; 5 | cin>>n; 6 | for(int i=1;i<=n;i++){ 7 | sum=sum+i; 8 | } 9 | cout< 3 | using namespace std; 4 | int fibo_nth(int n){ 5 | if(n<=1){ 6 | return n; 7 | } 8 | return fibo_nth(n-1) + fibo_nth(n-2); 9 | } 10 | int main(){ 11 | int n; 12 | cin>>n; 13 | cout< 3 | using namespace std; 4 | void power(int n, int p){ 5 | long long int val=1; 6 | for(int i=0; i>n>>p; 15 | power(n,p); 16 | } -------------------------------------------------------------------------------- /Codes for Recursion/01.cpp: -------------------------------------------------------------------------------- 1 | //Power of a Number 2 | 3 | #include 4 | using namespace std; 5 | int power(int base, int x){ 6 | if(x==0) 7 | return 1; 8 | return (base*power(base, x-1)); 9 | } 10 | int main(){ 11 | int base,x; 12 | cin>>base>>x; 13 | power(base,x); 14 | cout< 2 | using namespace std; 3 | int main(){ 4 | int a,b,c; 5 | cin>>a>>b>>c; 6 | if(a>b && a>c){ 7 | cout<a && b>c){ 10 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | char ch='9'; 6 | 7 | if( (ch>='a' && ch<='z') || (ch>='A' && ch<='Z')) 8 | cout<<"The inserted character " < 2 | using namespace std; 3 | int main(){ 4 | int yr; 5 | cin>>yr; 6 | if(yr%400==0){ 7 | cout<<"Leap Year"< 3 | using namespace std; 4 | void reverseNumber(int n){ 5 | int rev=0; 6 | int rem; 7 | while(n!=0){ 8 | rem = n%10; 9 | rev=rev*10+rem; 10 | n/=10; 11 | } 12 | cout<>n; 18 | reverseNumber(n); 19 | } -------------------------------------------------------------------------------- /Getting Started/16.cpp: -------------------------------------------------------------------------------- 1 | //Fibonacci Series upto nth term 2 | #include 3 | using namespace std; 4 | void fibo(int n){ 5 | int a=0, b=1, c; 6 | cout<>n; 17 | fibo(n); 18 | } -------------------------------------------------------------------------------- /Getting Started/9_prime_number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | int c=0; 7 | for(int i=1; i<=n; i++){ 8 | if(n%i==0){ 9 | c++; 10 | } 11 | } 12 | if(c=2){ 13 | cout<<"prime"< 4 | using namespace std; 5 | void sortAscDesc(int arr[], int n){ 6 | int mid; 7 | 8 | } 9 | int main(){ 10 | int n; 11 | cin>>n; 12 | int arr[n]; 13 | for(int i=0; i>arr[i]; 15 | } 16 | sortAscDesc(arr, n); 17 | } -------------------------------------------------------------------------------- /Important Codes related to Arrays/06.cpp: -------------------------------------------------------------------------------- 1 | //Reverse an Array 2 | 3 | #include 4 | using namespace std; 5 | void reverseArray(int arr[], int n){ 6 | for(int i=n-1; i>=0; i--){ 7 | cout<>n; 13 | int arr[n]; 14 | for(int i=0; i>arr[i]; 16 | } 17 | reverseArray(arr, n); 18 | } -------------------------------------------------------------------------------- /Working with Numbers/04.cpp: -------------------------------------------------------------------------------- 1 | //Binary to Decimal Conversion 2 | #include 3 | using namespace std; 4 | void binary_to_decimal(long long n){ 5 | float i=0,dec=0; 6 | while(n!=0){ 7 | int rem=n%10; 8 | dec+=rem*pow(2,i); 9 | n/=10; 10 | i++; 11 | } 12 | cout<>n; 17 | binary_to_decimal(n); 18 | } -------------------------------------------------------------------------------- /Working with Numbers/05.cpp: -------------------------------------------------------------------------------- 1 | //Octal to Decimal Conversion 2 | 3 | #include 4 | using namespace std; 5 | void octToDec(long long n){ 6 | int dec=0, i=0, base=8; 7 | while(n!=0){ 8 | int rem=n%10; 9 | dec+=rem*pow(base,i); 10 | n/=10; 11 | i++; 12 | } 13 | cout<>n; 18 | octToDec(n); 19 | } -------------------------------------------------------------------------------- /Operations on Strings/01.cpp: -------------------------------------------------------------------------------- 1 | //Check whether a character is a vowel or consonant 2 | 3 | #include 4 | using namespace std; 5 | int main(){ 6 | char ch; 7 | cin>>ch; 8 | if(ch=='a'|| ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch=='u' || ch=='U'){ 9 | cout<<"Vowel"< 2 | using namespace std; 3 | 4 | int largest_element(int n, int arr[]){ 5 | 6 | int max_element = INT_MIN; 7 | 8 | for(int i=0; i 4 | using namespace std; 5 | void sumElements(int arr[], int n){ 6 | int sum=0; 7 | for(int i=0; i>n; 15 | int arr[n]; 16 | for(int i=0; i>arr[i]; 18 | } 19 | sumElements(arr,n); 20 | } 21 | -------------------------------------------------------------------------------- /Getting Started/10_prime_number_range.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool isPrime(int n){ 4 | int c=0; 5 | //if n=0, n=1 6 | if(n<2) 7 | return false; 8 | for(int i=2; i>a>>b; 17 | 18 | for(int i=a; i<=b; i++){ 19 | if(isPrime(i)) 20 | cout< 2 | using namespace std; 3 | void validPalindrome(int n){ 4 | int rev=0; 5 | int rem; 6 | int temp=n; 7 | while(n!=0){ 8 | rem=n%10; 9 | rev=rev*10+rem; 10 | n/=10; 11 | } 12 | if(rev==temp){ 13 | cout<<"Palindrome Number"<>n; 22 | validPalindrome(n); 23 | } -------------------------------------------------------------------------------- /Important Codes related to Arrays/01.cpp: -------------------------------------------------------------------------------- 1 | //Find Largest element in an array 2 | 3 | #include 4 | using namespace std; 5 | void largest_element(int arr[], int n){ 6 | int max=arr[0]; 7 | for(int i=1; imax){ 9 | max=arr[i]; 10 | } 11 | } 12 | cout<>n; 17 | int arr[n]; 18 | for(int i=0; i>arr[i]; 20 | } 21 | largest_element(arr, n); 22 | } -------------------------------------------------------------------------------- /Important Codes related to Arrays/02.cpp: -------------------------------------------------------------------------------- 1 | //Find Smallest Element in an Array 2 | 3 | #include 4 | using namespace std; 5 | void smallest_element(int arr[], int n){ 6 | int min=arr[0]; 7 | for(int i=1; i>n; 17 | int arr[n]; 18 | for(int i=0; i>arr[i]; 20 | } 21 | smallest_element(arr, n); 22 | } -------------------------------------------------------------------------------- /Getting Started/21.cpp: -------------------------------------------------------------------------------- 1 | //Finding prime factors of a number 2 | #include 3 | using namespace std; 4 | void prime_fact(int n){ 5 | int fact; 6 | for(int i=0; i2){ 19 | cout<>n; 25 | prime_fact(n); 26 | } -------------------------------------------------------------------------------- /Working with Numbers/02.cpp: -------------------------------------------------------------------------------- 1 | //Least Common Factor(LCM) 2 | 3 | #include 4 | using namespace std; 5 | void findLcm(int num1, int num2){ 6 | int lcm; 7 | int max=(num1>num2)?num1:num2; 8 | for(int i=max; i<=num1*num2; i++){ 9 | if(i%num1==0 && i%num2==0){ 10 | lcm=i; 11 | break; 12 | } 13 | } 14 | cout<>num1>>num2; 19 | findLcm(num1, num2); 20 | } 21 | 22 | //Alternatives 23 | //First find hcf then use lcm formula- (num1*num2)/hcf -------------------------------------------------------------------------------- /Getting Started/25.cpp: -------------------------------------------------------------------------------- 1 | //Automorphic Number 2 | //An Automorphic number is a special number, whose’s square 3 | //ends with the same digits as the number itself. 4 | //5=25 5 | 6 | #include 7 | using namespace std; 8 | void find_auto(int n){ 9 | int sq=n*n; 10 | while(n!=0){ 11 | if(n%10 != sq%10){ 12 | cout<<"Not Automorphic number"<>n; 23 | find_auto(n); 24 | } -------------------------------------------------------------------------------- /Getting Started/27.cpp: -------------------------------------------------------------------------------- 1 | //Abundant Number 2 | //Abundant Number is a number where the sum of its proper 3 | //divisors is greater than the number itself. 4 | 5 | #include 6 | using namespace std; 7 | void isAbundant(int n){ 8 | int sum=0; 9 | for(int i=1; in){ 15 | cout<<"Abundant Number"<>n; 25 | isAbundant(n); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Important Codes related to Arrays/03.cpp: -------------------------------------------------------------------------------- 1 | //Find the Smallest and largest element in an array 2 | 3 | #include 4 | using namespace std; 5 | void maxMin(int arr[], int n){ 6 | int max=arr[0], min=arr[0]; 7 | for(int i=1; imax){ 9 | max=arr[i]; 10 | } 11 | else if(arr[i]>n; 20 | int arr[n]; 21 | for(int i=0; i>arr[i]; 23 | } 24 | maxMin(arr, n); 25 | } -------------------------------------------------------------------------------- /Working with Numbers/01.cpp: -------------------------------------------------------------------------------- 1 | //Highest Common Factor(HCF) of two numbers 2 | //also called as GCD 3 | //HCF ( Highest Common Factor ) of two numbers is the 4 | //largest positive integer that can divide both the numbers 5 | 6 | 7 | #include 8 | using namespace std; 9 | void hcf(int num1, int num2){ 10 | int hcf=1; 11 | //for loop in the iteration of i between [1, min(num1,num2)] 12 | for(int i=1; i<=num1 || i<=num2; i++){ 13 | if(num1%i==0 && num2%i==0) 14 | hcf=i; 15 | } 16 | cout<>num1>>num2; 21 | hcf(num1, num2); 22 | } -------------------------------------------------------------------------------- /Getting Started/14_armstrong.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int order(int n){ 4 | int len=0; 5 | while(n){ 6 | len++; 7 | n/=10; 8 | } 9 | return len; 10 | } 11 | 12 | int isArmstrong(int n, int len){ 13 | int sum=0, temp, rem; 14 | temp=n; 15 | while(n>0){ 16 | rem=n%10; 17 | sum+=pow(rem,len); 18 | n/=10; 19 | } 20 | if(temp==sum){ 21 | cout<<"Armstrong"<>n; 31 | len=order(n); 32 | isArmstrong(n, len); 33 | } -------------------------------------------------------------------------------- /Important Codes related to Arrays/18.cpp: -------------------------------------------------------------------------------- 1 | //Counting the number of even and odd elements in an array 2 | 3 | #include 4 | using namespace std; 5 | void countOddEven(int arr[], int n){ 6 | int countOdd=0, countEven=0; 7 | for(int i=0; i>n; 21 | int arr[n]; 22 | for(int i=0; i>arr[i]; 24 | } 25 | countOddEven(arr, n); 26 | } -------------------------------------------------------------------------------- /Getting Started/23.cpp: -------------------------------------------------------------------------------- 1 | //Perfect Number 2 | //A perfect number is a number in which the sum of the proper positive 3 | //divisors of the number is equal to the number itself. 4 | //For Example: 28 5 | //Divisors : 1 + 2 + 4 + 7 + 14 = 28 6 | 7 | #include 8 | using namespace std; 9 | void find_perfect(int n){ 10 | int sum=0; 11 | for(int i=1; i<=n/2; i++){ 12 | if(n%i==0){ 13 | sum+=i; 14 | } 15 | } 16 | if(sum==n){ 17 | cout<<"Perfect Number"<>n; 26 | find_perfect(n); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Getting Started/15.cpp: -------------------------------------------------------------------------------- 1 | //Armstrong number in a given range 2 | #include 3 | using namespace std; 4 | int order(int n){ 5 | int len=0; 6 | while(n){ 7 | len++; 8 | n/=10; 9 | } 10 | return len; 11 | } 12 | void armstrong(int a, int b){ 13 | for(int i=a; i<=b; i++){ 14 | int sum=0, temp, rem, len; 15 | temp=i; 16 | len=order(i); 17 | while(temp!=0){ 18 | rem=temp%10; 19 | sum+=pow(rem, len); 20 | temp/=10; 21 | } 22 | if(sum == i) 23 | cout<>a>>b; 30 | armstrong(a,b); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Getting Started/26.cpp: -------------------------------------------------------------------------------- 1 | //Harshard Number 2 | //a positive integer that is divisible by the sum of the digits of the integer. 3 | //For Example : 153 4 | //Sum of digits = 1 + 5 + 3 = 9 5 | //153 is divisible by 9 so 153 is a Harshad Number. 6 | 7 | #include 8 | using namespace std; 9 | 10 | void isHarshard(int n){ 11 | int sum=0, rem=1; 12 | int temp=n; 13 | while(temp!=0){ 14 | rem=temp%10; 15 | sum+=rem; 16 | temp/=10; 17 | } 18 | if(n%sum==0){ 19 | cout<<"Harshard Number"<>n; 30 | isHarshard(n); 31 | } -------------------------------------------------------------------------------- /Getting Started/28.cpp: -------------------------------------------------------------------------------- 1 | //Friendly pair 2 | //Friendly pair are two numbers num1 & num2 if the following holds true - 3 | //(Sum of divisors of num1)/num1= (Sum of divisors of num2)/num2 4 | 5 | #include 6 | using namespace std; 7 | int getDivisorsSum(int num){ 8 | int sum=0; 9 | for(int i=1; i>num1>>num2; 19 | int sum1 = getDivisorsSum(num1); 20 | int sum2 = getDivisorsSum(num2); 21 | 22 | if(sum1/num1 == sum2/num2){ 23 | cout<<"Friedly Pair"< 3 | using namespace std; 4 | void fact(int n){ 5 | for(int i=1; i<=n; i++){ 6 | if(n%i==0){ 7 | cout<>n; 14 | fact(n); 15 | } 16 | 17 | 18 | //This method is used when we need factors in pairs. 19 | // #include 20 | // using namespace std; 21 | // void fact(int n){ 22 | // for(int i=1; i<=sqrt(n); i++){ 23 | // if(n%i==0){ 24 | // if(i==n/i){ 25 | // cout<>n; 36 | // fact(n); 37 | // } -------------------------------------------------------------------------------- /Getting Started/22.cpp: -------------------------------------------------------------------------------- 1 | //Strong Number 2 | // Strong Number is a number in which sum of the factorial of 3 | // individual digits of the number is equal to the number itself. 4 | // For Example: 145 5 | // 145 = 1! x 4! x 5! = 145 6 | 7 | #include 8 | using namespace std; 9 | 10 | int fact(int n){ 11 | int fact=1; 12 | for(int i=1; i<=n; i++){ 13 | fact*=i; 14 | } 15 | return fact; 16 | } 17 | 18 | int strong_num(int n){ 19 | int rem, sum=0; 20 | int temp=n; 21 | while(temp!=0){ 22 | rem=temp%10; 23 | sum+=fact(rem); 24 | temp/=10; 25 | } 26 | return sum==n; 27 | } 28 | 29 | int main(){ 30 | int n; 31 | cin>>n; 32 | if(strong_num(n)){ 33 | cout<<"Strong number"; 34 | } 35 | else{ 36 | cout<<"Not Strong number"; 37 | } 38 | } -------------------------------------------------------------------------------- /Working with Numbers/03.cpp: -------------------------------------------------------------------------------- 1 | // Greatest Common Divisor 2 | 3 | // #include 4 | // using namespace std; 5 | // void gcd(int num1, int num2){ 6 | // int gcd=1; 7 | // for(int i=1; i<=num1||i<=num2; i++){ 8 | // if(num1%i==0 && num2%i==0){ 9 | // gcd=i; 10 | // } 11 | // } 12 | // cout<>num1>>num2; 18 | // gcd(num1, num2); 19 | // } 20 | 21 | //Euclidean Algorithm 22 | //Euclidean Algorithm: GCD of two numbers remains constant even 23 | //if we subtract the smaller number from the higher number. 24 | #include 25 | using namespace std; 26 | void euclidean_gcd(int num1, int num2){ 27 | while(num1!=num2){ 28 | if(num1>num2) 29 | num1-=num2; 30 | else 31 | num2-=num1; 32 | } 33 | cout<>num1>>num2; 38 | euclidean_gcd(num1, num2); 39 | } -------------------------------------------------------------------------------- /Important Codes related to Arrays/04.cpp: -------------------------------------------------------------------------------- 1 | //Find Second smallest element in an Array 2 | 3 | #include 4 | using namespace std; 5 | void secondSmallest(int arr[], int n){ 6 | int min=arr[0]; 7 | for(int i=0; i>n; 23 | int arr[n]; 24 | for(int i=0; i>arr[i]; 26 | } 27 | secondSmallest(arr,n); 28 | } 29 | 30 | // Alternatives:- 31 | 32 | #include 33 | using namespace std; 34 | int main(){ 35 | int n; 36 | cin>>n; 37 | int arr[n]; 38 | for(int i=0; i>arr[i]; 40 | } 41 | int first = INT_MAX, second = INT_MAX; 42 | 43 | for(int i=0; iarr[i]) 49 | second = arr[i]; 50 | } 51 | 52 | cout<