From 116386233cdd7ecdea3bbd8d8e3e261fed01c719 Mon Sep 17 00:00:00 2001 From: Tanisha Banga Date: Tue, 27 Jan 2026 00:41:06 +0530 Subject: [PATCH 1/2] Added C++ solutions for first 30 programming questions. --- .gitignore | 1 + TanishaBanga_AbundantNo_q27.cpp | 24 +++++++++++++++ TanishaBanga_ArmstrongNo_q14.cpp | 34 ++++++++++++++++++++++ TanishaBanga_ArmstrongWithinRange_q15.cpp | 34 ++++++++++++++++++++++ TanishaBanga_AutomorphicNo_q25.cpp | 22 ++++++++++++++ TanishaBanga_FactorOfaNo_q20.cpp | 16 ++++++++++ TanishaBanga_FactorialOfNo_q18.cpp | 18 ++++++++++++ TanishaBanga_Fibonacci_q16.cpp | 23 +++++++++++++++ TanishaBanga_FriendlyPair_q28.cpp | 29 ++++++++++++++++++ TanishaBanga_GreatestOf2Nos_q6.cpp | 15 ++++++++++ TanishaBanga_Greatestof3Nos_q7.cpp | 17 +++++++++++ TanishaBanga_HCFof2No_q29.cpp | 16 ++++++++++ TanishaBanga_HarshadNo_q26.cpp | 21 +++++++++++++ TanishaBanga_LCMof2Nos.q30.cpp | 21 +++++++++++++ TanishaBanga_LeapYear_q8.cpp | 19 ++++++++++++ TanishaBanga_NthFibonacciSeries_q17.cpp | 21 +++++++++++++ TanishaBanga_OddOrEven_q2.cpp | 13 +++++++++ TanishaBanga_Palindrome_q13.cpp | 28 ++++++++++++++++++ TanishaBanga_PerfectNo_q23.cpp | 25 ++++++++++++++++ TanishaBanga_PerfectSquare_q24.cpp | 25 ++++++++++++++++ TanishaBanga_PositiveOrNegative_q1.cpp | 17 +++++++++++ TanishaBanga_PowerOfNo_q19.cpp | 27 +++++++++++++++++ TanishaBanga_PrimeFactorsOfNo_q21.cpp | 29 ++++++++++++++++++ TanishaBanga_PrimeNo_q9.cpp | 30 +++++++++++++++++++ TanishaBanga_PrimeWithinGivenRange_q10.cpp | 32 ++++++++++++++++++++ TanishaBanga_ReverseOfaNumber_q12.cpp | 21 +++++++++++++ TanishaBanga_StrongNo_q22.cpp | 30 +++++++++++++++++++ TanishaBanga_SumOfDigitsOfNo_q11.cpp | 21 +++++++++++++ TanishaBanga_SumOfNosInRange_q5.cpp | 10 +++++++ TanishaBanga_SumOfnNaturalNos_q4.cpp | 17 +++++++++++ TanishaBanga_Sumof1stnNaturalNos_q3.cpp | 12 ++++++++ 31 files changed, 668 insertions(+) create mode 100644 .gitignore create mode 100644 TanishaBanga_AbundantNo_q27.cpp create mode 100644 TanishaBanga_ArmstrongNo_q14.cpp create mode 100644 TanishaBanga_ArmstrongWithinRange_q15.cpp create mode 100644 TanishaBanga_AutomorphicNo_q25.cpp create mode 100644 TanishaBanga_FactorOfaNo_q20.cpp create mode 100644 TanishaBanga_FactorialOfNo_q18.cpp create mode 100644 TanishaBanga_Fibonacci_q16.cpp create mode 100644 TanishaBanga_FriendlyPair_q28.cpp create mode 100644 TanishaBanga_GreatestOf2Nos_q6.cpp create mode 100644 TanishaBanga_Greatestof3Nos_q7.cpp create mode 100644 TanishaBanga_HCFof2No_q29.cpp create mode 100644 TanishaBanga_HarshadNo_q26.cpp create mode 100644 TanishaBanga_LCMof2Nos.q30.cpp create mode 100644 TanishaBanga_LeapYear_q8.cpp create mode 100644 TanishaBanga_NthFibonacciSeries_q17.cpp create mode 100644 TanishaBanga_OddOrEven_q2.cpp create mode 100644 TanishaBanga_Palindrome_q13.cpp create mode 100644 TanishaBanga_PerfectNo_q23.cpp create mode 100644 TanishaBanga_PerfectSquare_q24.cpp create mode 100644 TanishaBanga_PositiveOrNegative_q1.cpp create mode 100644 TanishaBanga_PowerOfNo_q19.cpp create mode 100644 TanishaBanga_PrimeFactorsOfNo_q21.cpp create mode 100644 TanishaBanga_PrimeNo_q9.cpp create mode 100644 TanishaBanga_PrimeWithinGivenRange_q10.cpp create mode 100644 TanishaBanga_ReverseOfaNumber_q12.cpp create mode 100644 TanishaBanga_StrongNo_q22.cpp create mode 100644 TanishaBanga_SumOfDigitsOfNo_q11.cpp create mode 100644 TanishaBanga_SumOfNosInRange_q5.cpp create mode 100644 TanishaBanga_SumOfnNaturalNos_q4.cpp create mode 100644 TanishaBanga_Sumof1stnNaturalNos_q3.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbe9c82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/ \ No newline at end of file diff --git a/TanishaBanga_AbundantNo_q27.cpp b/TanishaBanga_AbundantNo_q27.cpp new file mode 100644 index 0000000..aaaaf08 --- /dev/null +++ b/TanishaBanga_AbundantNo_q27.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +int main() { + int num; + cin >> num; + + int sum = 1; + + for (int i = 2; i <= sqrt(num); i++) { + if (num % i == 0) { + sum += i; + if (i != num / i) + sum += num / i; + } + } + + if (num > 1 && sum > num) + cout << "Abundant Number"; + else + cout << "Not an Abundant Number"; + + return 0; +} diff --git a/TanishaBanga_ArmstrongNo_q14.cpp b/TanishaBanga_ArmstrongNo_q14.cpp new file mode 100644 index 0000000..fe60048 --- /dev/null +++ b/TanishaBanga_ArmstrongNo_q14.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; + +int main() { + int num; + cin>>num; + int originalNum, remainder, n = 0; + int result = 0.0; + + cout << "Enter a number: "; + cin >> num; + + originalNum = num; + + while (originalNum != 0) { + originalNum /= 10; + n++; + } + + originalNum = num; + + while (originalNum != 0) { + remainder = originalNum % 10; + result += pow(remainder, n); + originalNum /= 10; + } + + if (result == num) + cout << num << " is an Armstrong number."; + else + cout << num << " is not an Armstrong number."; + + return 0; +} diff --git a/TanishaBanga_ArmstrongWithinRange_q15.cpp b/TanishaBanga_ArmstrongWithinRange_q15.cpp new file mode 100644 index 0000000..5050757 --- /dev/null +++ b/TanishaBanga_ArmstrongWithinRange_q15.cpp @@ -0,0 +1,34 @@ +#include +#include +using namespace std; + +int main() { + int start, end; + + cin >> start; + cin >> end; + + cout << "Armstrong numbers between " << start << " and " << end << " are:\n"; + + for (int num = start; num <= end; num++) { + int temp = num, sum = 0, digits = 0; + + while (temp != 0) { + temp /= 10; + digits++; + } + + temp = num; + + while (temp != 0) { + int rem = temp % 10; + sum += pow(rem, digits); + temp /= 10; + } + + if (sum == num) + cout << num << " "; + } + + return 0; +} diff --git a/TanishaBanga_AutomorphicNo_q25.cpp b/TanishaBanga_AutomorphicNo_q25.cpp new file mode 100644 index 0000000..f054c61 --- /dev/null +++ b/TanishaBanga_AutomorphicNo_q25.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +int main() { + int n; + cin >> n; + + long long sq = (long long)n * n; + int temp = n; + + while (temp > 0) { + if (temp % 10 != sq % 10) { + cout << "Not Automorphic"; + return 0; + } + temp /= 10; + sq /= 10; + } + + cout << "Automorphic Number"; + return 0; +} diff --git a/TanishaBanga_FactorOfaNo_q20.cpp b/TanishaBanga_FactorOfaNo_q20.cpp new file mode 100644 index 0000000..e60b66b --- /dev/null +++ b/TanishaBanga_FactorOfaNo_q20.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main() +{ + int num; + cin>>num; + + cout << "Factors of " << num << " are: " << endl; + + for(int i = 1; i <= num; i++) + { + if(num % i == 0) + cout << i << " "; + } +} \ No newline at end of file diff --git a/TanishaBanga_FactorialOfNo_q18.cpp b/TanishaBanga_FactorialOfNo_q18.cpp new file mode 100644 index 0000000..f628c24 --- /dev/null +++ b/TanishaBanga_FactorialOfNo_q18.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; +int main () +{ + int num; + cin>>num; + + int fact = 1; + if(num < 0) + cout << "Not Possible"; + else + { + for(int i = 1; i <= num; i++) + fact = fact * i; + } + + cout << "Factorial" << num << ": " << fact; +} \ No newline at end of file diff --git a/TanishaBanga_Fibonacci_q16.cpp b/TanishaBanga_Fibonacci_q16.cpp new file mode 100644 index 0000000..0400343 --- /dev/null +++ b/TanishaBanga_Fibonacci_q16.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; + +int main() +{ + int n; + cin>>n; + int a = 0, b = 1; + + cout << a << ", " << b << ", "; + + int nextTerm; + + for(int i = 2; i < n; i++){ + nextTerm = a + b; + a = b; + b = nextTerm; + + cout << nextTerm << ", "; + } + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_FriendlyPair_q28.cpp b/TanishaBanga_FriendlyPair_q28.cpp new file mode 100644 index 0000000..83ff62a --- /dev/null +++ b/TanishaBanga_FriendlyPair_q28.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +int getDivisorsSum(int n){ + + int sum = 0; + + for(int i = 1; i < n; i++){ + if(n % i == 0) + sum = sum + i; + } + return sum; +} + +int main () +{ + int n1, n2; + cin>>n1>>n2; + + int s1 = getDivisorsSum(n1); + int s2 = getDivisorsSum(n2); + + if(s1/n1 == s2/n2) + cout << n1 << " & " << n2 << " are friendly pairs"; + else + cout << n1 << " & " << n2 << " are not friendly pairs"; + + +} \ No newline at end of file diff --git a/TanishaBanga_GreatestOf2Nos_q6.cpp b/TanishaBanga_GreatestOf2Nos_q6.cpp new file mode 100644 index 0000000..9754cb5 --- /dev/null +++ b/TanishaBanga_GreatestOf2Nos_q6.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +int main () +{ + int n1, n2; + cin>>n1>>n2; + + if (n1 == n2) + cout << "both are equal"; + else + cout << max(n1,n2) << " is greater"; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_Greatestof3Nos_q7.cpp b/TanishaBanga_Greatestof3Nos_q7.cpp new file mode 100644 index 0000000..e77fcf2 --- /dev/null +++ b/TanishaBanga_Greatestof3Nos_q7.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +int main () +{ + int n1, n2, n3; + cin>>n1>>n2>>n3; + + int result; + + result = max(n1,max(n2, n3)); + + cout << result << " is the largest"; + + + return 0; +} diff --git a/TanishaBanga_HCFof2No_q29.cpp b/TanishaBanga_HCFof2No_q29.cpp new file mode 100644 index 0000000..6dd3979 --- /dev/null +++ b/TanishaBanga_HCFof2No_q29.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +int main() { + int a, b; + cin >> a >> b; + + while (b != 0) { + int rem = a % b; + a = b; + b = rem; + } + + cout << "HCF = " << a; + return 0; +} diff --git a/TanishaBanga_HarshadNo_q26.cpp b/TanishaBanga_HarshadNo_q26.cpp new file mode 100644 index 0000000..0f33673 --- /dev/null +++ b/TanishaBanga_HarshadNo_q26.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main() { + int num, temp, sum = 0; + cin >> num; + + temp = num; + + while (temp > 0) { + sum += temp % 10; + temp /= 10; + } + + if (num % sum == 0) + cout << "Harshad Number"; + else + cout << "Not a Harshad Number"; + + return 0; +} diff --git a/TanishaBanga_LCMof2Nos.q30.cpp b/TanishaBanga_LCMof2Nos.q30.cpp new file mode 100644 index 0000000..2935567 --- /dev/null +++ b/TanishaBanga_LCMof2Nos.q30.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int hcf(int a, int b) { + while (b != 0) { + int rem = a % b; + a = b; + b = rem; + } + return a; +} + +int main() { + int a, b; + cin >> a >> b; + + int lcm = (a * b) / hcf(a, b); + cout << "LCM = " << lcm; + + return 0; +} diff --git a/TanishaBanga_LeapYear_q8.cpp b/TanishaBanga_LeapYear_q8.cpp new file mode 100644 index 0000000..a2696f7 --- /dev/null +++ b/TanishaBanga_LeapYear_q8.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + int year; + cin>>year; + + if(year % 400 == 0) + cout << year << " is a Leap Year"; + + else if(year % 4 == 0 && year % 100 != 0) + cout << year << " is a Leap Year"; + + else + cout << year << " is not a Leap Year"; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_NthFibonacciSeries_q17.cpp b/TanishaBanga_NthFibonacciSeries_q17.cpp new file mode 100644 index 0000000..87fbd4c --- /dev/null +++ b/TanishaBanga_NthFibonacciSeries_q17.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int F(int n) +{ + if (n <= 1) + { + return n; + } + + return F(n-1) + F(n-2); +} + +int main () +{ + int n; + cin>>n; + + cout << F(n); + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_OddOrEven_q2.cpp b/TanishaBanga_OddOrEven_q2.cpp new file mode 100644 index 0000000..c3b9bb3 --- /dev/null +++ b/TanishaBanga_OddOrEven_q2.cpp @@ -0,0 +1,13 @@ +#include +using namespace std; + +int main () +{ + int num; + cin>>num; + + + (num % 2 == 0) ? cout << "Even":cout << "Odd"; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_Palindrome_q13.cpp b/TanishaBanga_Palindrome_q13.cpp new file mode 100644 index 0000000..c914623 --- /dev/null +++ b/TanishaBanga_Palindrome_q13.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; + +int main () +{ + int n; + cin>>n; + + int reverse = 0, temp; + cout <<"\nThe number is: "< +using namespace std; + +int main () +{ + int num ; + cin>>num; + int sum = 0; + + int i = 1; + + while(i <= num/2) + { + if(num % i == 0) + sum = sum + i; + i++; + } + + if(sum == num) + cout << num << " is a perfect number"; + else + cout << num << " is not a perfect number"; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_PerfectSquare_q24.cpp b/TanishaBanga_PerfectSquare_q24.cpp new file mode 100644 index 0000000..87d16a2 --- /dev/null +++ b/TanishaBanga_PerfectSquare_q24.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +int main() { + int n; + cin >> n; + + int low = 0, high = n; + + while (low <= high) { + long long mid = low + (high - low) / 2; + + if (mid * mid == n) { + cout << "Perfect Square"; + return 0; + } else if (mid * mid < n) { + low = mid + 1; + } else { + high = mid - 1; + } + } + + cout << "Not a Perfect Square"; + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_PositiveOrNegative_q1.cpp b/TanishaBanga_PositiveOrNegative_q1.cpp new file mode 100644 index 0000000..79b37d5 --- /dev/null +++ b/TanishaBanga_PositiveOrNegative_q1.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +int main() +{ + int num; + cin>>num; + + if (num > 0) + cout << "The number is positive"; + else if (num < 0) + cout << "The number is negative"; + else + cout << "Zero"; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_PowerOfNo_q19.cpp b/TanishaBanga_PowerOfNo_q19.cpp new file mode 100644 index 0000000..0a8aa7c --- /dev/null +++ b/TanishaBanga_PowerOfNo_q19.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +int main() +{ + double b; + cin>>b; + + int e; + cin>>e; + + double result = 1; + + while (e > 0) { + result *= b; + e--; + } + + while (e < 0) { + result /= b; + e++; + } + + cout << "Result = " << result; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_PrimeFactorsOfNo_q21.cpp b/TanishaBanga_PrimeFactorsOfNo_q21.cpp new file mode 100644 index 0000000..0f3f4e2 --- /dev/null +++ b/TanishaBanga_PrimeFactorsOfNo_q21.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +void primeFactors(int n) +{ + while (n % 2 == 0) + { + cout << 2 << " "; + n = n/2; + } + + for (int i = 3; i <= sqrt(n); i = i + 2) + { + + while (n % i == 0) + { + cout << i << " "; n = n/i; } } if (n > 2) + cout << n << " "; +} + +// Driver code +int main() +{ + int n; + cin>>n; + + primeFactors(n); + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_PrimeNo_q9.cpp b/TanishaBanga_PrimeNo_q9.cpp new file mode 100644 index 0000000..5e6885b --- /dev/null +++ b/TanishaBanga_PrimeNo_q9.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; + +int main() +{ + int n; + cin>>n; + bool isprime= true; + + if(n < 2) + { + isprime = false; + } + else + { + for(int i=2; i < n/2; i++) + { + if(n % i == 0) + { + isprime = false; + break; + } + } + } + + string result = isprime ? "Prime":"not Prime"; + cout<<"The number " << n << " is : " << result; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_PrimeWithinGivenRange_q10.cpp b/TanishaBanga_PrimeWithinGivenRange_q10.cpp new file mode 100644 index 0000000..1ce713d --- /dev/null +++ b/TanishaBanga_PrimeWithinGivenRange_q10.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +bool isPrime(int n){ + int count = 0; + + if(n < 2) + return false; + + for(int i = 2;i < n/2; i++) + { + if(n % i == 0) + return false; + } + + return true; +} + +int main() +{ + int n1, n2; + cin>>n1>>n2; + + for(int i = n1; i <= n2; i++){ + if(isPrime(i)){ + cout << i << " "; + } + } + + return 0; + +} \ No newline at end of file diff --git a/TanishaBanga_ReverseOfaNumber_q12.cpp b/TanishaBanga_ReverseOfaNumber_q12.cpp new file mode 100644 index 0000000..884bf41 --- /dev/null +++ b/TanishaBanga_ReverseOfaNumber_q12.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main () +{ + int n; + cin>>n; + int reverse = 0; + cout <<"\nThe number is"< +using namespace std; + +int factorial(int n) { + int fact = 1; + for (int i = 1; i <= n; i++) { + fact *= i; + } + return fact; +} + +int main() { + int num, temp, sum = 0; + cin >> num; + + temp = num; + + while (temp > 0) { + int digit = temp % 10; + sum += factorial(digit); + temp /= 10; + } + + if (sum == num) + cout << "Strong Number"; + else + cout << "Not a Strong Number"; + + return 0; +} diff --git a/TanishaBanga_SumOfDigitsOfNo_q11.cpp b/TanishaBanga_SumOfDigitsOfNo_q11.cpp new file mode 100644 index 0000000..cd07b03 --- /dev/null +++ b/TanishaBanga_SumOfDigitsOfNo_q11.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main () +{ + int n; + cin>>n; + + int sum = 0; + + cout <<"\nThe number is: " << n; + + while(n!=0){ + sum += n % 10; + n = n / 10; + } + + cout <<"\nSum of digits: " << sum; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_SumOfNosInRange_q5.cpp b/TanishaBanga_SumOfNosInRange_q5.cpp new file mode 100644 index 0000000..60e9a5c --- /dev/null +++ b/TanishaBanga_SumOfNosInRange_q5.cpp @@ -0,0 +1,10 @@ +#include +using namespace std; +int main() +{ + int n1, n2; + cin>>n1>>n2; + int sum = n2*(n2+1)/2 - n1*(n1+1)/2 + n1; + cout << sum; + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_SumOfnNaturalNos_q4.cpp b/TanishaBanga_SumOfnNaturalNos_q4.cpp new file mode 100644 index 0000000..00f0f3d --- /dev/null +++ b/TanishaBanga_SumOfnNaturalNos_q4.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + int sum=0; + + for(int i=1;i<=n;i++) + sum+=i; + + cout << sum; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_Sumof1stnNaturalNos_q3.cpp b/TanishaBanga_Sumof1stnNaturalNos_q3.cpp new file mode 100644 index 0000000..d8d2b66 --- /dev/null +++ b/TanishaBanga_Sumof1stnNaturalNos_q3.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; + +int main() +{ + int n; + cin >> n; + + cout << n*(n+1)/2; + + return 0; +} \ No newline at end of file From cd87fc6333a4fb9508b69f0051593bb5bfba97b3 Mon Sep 17 00:00:00 2001 From: Tanisha Banga Date: Sat, 7 Feb 2026 00:01:18 +0530 Subject: [PATCH 2/2] =?UTF-8?q?Added=20number=20system=20conversion=20prog?= =?UTF-8?q?rams=20(q31=E2=80=9336)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TanishaBanga_BinaryToDecimal_q32.cpp | 27 +++++++++++++++++++ TanishaBanga_DecimalToBinary_q33.cpp | 24 +++++++++++++++++ TanishaBanga_DecimalToOctal_q36.cpp | 25 +++++++++++++++++ TanishaBanga_GreatestComDivisor_q31.cpp | 19 +++++++++++++ TanishaBanga_HexaToDecimal_q35.cpp | 36 +++++++++++++++++++++++++ TanishaBanga_OctalToDec_q34.cpp | 29 ++++++++++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 TanishaBanga_BinaryToDecimal_q32.cpp create mode 100644 TanishaBanga_DecimalToBinary_q33.cpp create mode 100644 TanishaBanga_DecimalToOctal_q36.cpp create mode 100644 TanishaBanga_GreatestComDivisor_q31.cpp create mode 100644 TanishaBanga_HexaToDecimal_q35.cpp create mode 100644 TanishaBanga_OctalToDec_q34.cpp diff --git a/TanishaBanga_BinaryToDecimal_q32.cpp b/TanishaBanga_BinaryToDecimal_q32.cpp new file mode 100644 index 0000000..a9de09c --- /dev/null +++ b/TanishaBanga_BinaryToDecimal_q32.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +int getDecimal(long long num) +{ + int i = 0, decimal= 0; + + while (num!=0) + { + int digit = num % 10; + decimal += digit * pow(2,i); + + num /= 10; + i++; + } + return decimal; +} + +int main() +{ + long long b; + cin>>b; + + cout << getDecimal(b); + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_DecimalToBinary_q33.cpp b/TanishaBanga_DecimalToBinary_q33.cpp new file mode 100644 index 0000000..e3bfc37 --- /dev/null +++ b/TanishaBanga_DecimalToBinary_q33.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +void convertBinary(int num) +{ + int binaryArray[32]; + int i = 0; + while (num > 0) { + binaryArray[i] = num % 2; + num = num / 2; + i++; + } + + for (int j = i - 1; j >= 0; j--) + cout << binaryArray[j]; +} + +int main() +{ + int n; + cin>>n; + convertBinary(n); + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_DecimalToOctal_q36.cpp b/TanishaBanga_DecimalToOctal_q36.cpp new file mode 100644 index 0000000..c3571f0 --- /dev/null +++ b/TanishaBanga_DecimalToOctal_q36.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; + +void convertOctal(int num) +{ + int octalArray[32]; + + int i = 0; + while (num > 0) { + octalArray[i] = num % 8; + num = num / 8; + i++; + } + + for (int j = i - 1; j >= 0; j--) + cout << octalArray[j]; +} + +int main() +{ + int n; + cin>>n; + convertOctal(n); + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_GreatestComDivisor_q31.cpp b/TanishaBanga_GreatestComDivisor_q31.cpp new file mode 100644 index 0000000..d54a039 --- /dev/null +++ b/TanishaBanga_GreatestComDivisor_q31.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + int n1, n2; + cin>>n1>>n2; + + int gcd = 1; + + for(int i = 1; i <= n1 || i <= n2; i++) { + if(n1 % i == 0 && n2 % i == 0) + gcd = i; + } + + cout<<"The GCD is "<< gcd; + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_HexaToDecimal_q35.cpp b/TanishaBanga_HexaToDecimal_q35.cpp new file mode 100644 index 0000000..b7a4862 --- /dev/null +++ b/TanishaBanga_HexaToDecimal_q35.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; + +int convert(string num) +{ + int len = num.size(); + int dec = 0, index = 0; + + for(int i = len - 1; i >= 0; i--) + { + if (num[i] >= '0' && num[i] <= '9') + { + int digit = int(num[i]) - 48; + dec += digit * pow(16, index); + index++; + } + + else if (num[i] >= 'A' && num[i] <= 'F') + { + int digit = int(num[i]) - 55; + dec += digit * pow(16, index); + index++; + } + } + return dec; +} + +int main() +{ + string num; + cin >> num; + + cout << (convert(num)); + + return 0; +} \ No newline at end of file diff --git a/TanishaBanga_OctalToDec_q34.cpp b/TanishaBanga_OctalToDec_q34.cpp new file mode 100644 index 0000000..69c11c1 --- /dev/null +++ b/TanishaBanga_OctalToDec_q34.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +int getOctal(long long num) +{ + int i = 0, decimal = 0; + + int base = 8; + + while (num!=0) + { + int digit = num % 10; + decimal += digit * pow(base, i); + + num /= 10; + i++; + } + return decimal; +} + +int main() +{ + long long octal; + cin>>octal; + + cout << getOctal(octal); + + return 0; +} \ No newline at end of file