Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/
24 changes: 24 additions & 0 deletions TanishaBanga_AbundantNo_q27.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <bits/stdc++.h>
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;
}
34 changes: 34 additions & 0 deletions TanishaBanga_ArmstrongNo_q14.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
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;
}
34 changes: 34 additions & 0 deletions TanishaBanga_ArmstrongWithinRange_q15.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
#include <cmath>
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;
}
22 changes: 22 additions & 0 deletions TanishaBanga_AutomorphicNo_q25.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>
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;
}
27 changes: 27 additions & 0 deletions TanishaBanga_BinaryToDecimal_q32.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<bits/stdc++.h>
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;
}
24 changes: 24 additions & 0 deletions TanishaBanga_DecimalToBinary_q33.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<iostream>
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;
}
25 changes: 25 additions & 0 deletions TanishaBanga_DecimalToOctal_q36.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<iostream>
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;
}
16 changes: 16 additions & 0 deletions TanishaBanga_FactorOfaNo_q20.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <bits/stdc++.h>
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 << " ";
}
}
18 changes: 18 additions & 0 deletions TanishaBanga_FactorialOfNo_q18.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<bits/stdc++.h>
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;
}
23 changes: 23 additions & 0 deletions TanishaBanga_Fibonacci_q16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <bits/stdc++.h>
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;
}
29 changes: 29 additions & 0 deletions TanishaBanga_FriendlyPair_q28.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
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";


}
19 changes: 19 additions & 0 deletions TanishaBanga_GreatestComDivisor_q31.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<iostream>
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;
}
15 changes: 15 additions & 0 deletions TanishaBanga_GreatestOf2Nos_q6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <bits/stdc++.h>
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;
}
17 changes: 17 additions & 0 deletions TanishaBanga_Greatestof3Nos_q7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <bits/stdc++.h>
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;
}
16 changes: 16 additions & 0 deletions TanishaBanga_HCFof2No_q29.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <bits/stdc++.h>
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;
}
21 changes: 21 additions & 0 deletions TanishaBanga_HarshadNo_q26.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <bits/stdc++.h>
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;
}
Loading