Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0d80d06

Browse files
program to check if a number is automorpihc or not:
1 parent ca59d96 commit 0d80d06

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

‎General Programs/AutomorphicNumber.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<iostream>
2+
#include<math.h>
3+
4+
using namespace std;
5+
6+
void isAutomorphic(int n)
7+
{
8+
int sq = (n*n);
9+
int count = 0;
10+
int nn = n;
11+
//counting number of digits of n
12+
while(nn)
13+
{
14+
count++;
15+
nn /= 10;
16+
}
17+
int dig = pow(10,count);
18+
19+
int d = (sq % dig);
20+
if(d==n) cout<<"Automorpihc";
21+
22+
else cout<<"Not Automorphic";
23+
}
24+
25+
26+
int main()
27+
{
28+
isAutomorphic(76);
29+
return 0;
30+
}

‎General Programs/CheckDigits.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ int fun(int n,int m)
99
int s = sum;
1010
int c1 = 0,c2=0;
1111
int nn = n;
12-
while(s>0)
12+
while(s /= 10)
1313
{
1414
c1++;
15-
s /= 10;
15+
1616

1717
}
1818

19-
while(nn>0)
19+
while(nn /= 10)
2020
{
2121
c2++;
22-
nn /= 10;
22+
2323
}
2424

2525
if(c1==c2) return sum;
@@ -29,6 +29,6 @@ int fun(int n,int m)
2929

3030
int main()
3131
{
32-
cout<<fun(10,121);
32+
cout<<fun(100,121);
3333
return 0;
3434
}

‎General Programs/SetBits.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,29 @@ int CountSet(int n)
2929
while(n)
3030
{
3131
count += n & 1;
32-
n >>= 1; //simply right shift the no by 1
33-
32+
// n >>= 1; //simply right shift the no by 1
33+
//right shift is equivalent to division by 2
34+
n /= 2;
3435
}
3536

3637
return count;
3738
}
3839

40+
//int countUnset(int n){
41+
//
42+
// int count = 0;
43+
// while(n)
44+
// {
45+
// count += n | 1;
46+
//
47+
// n /= 2;
48+
// }
49+
//}
50+
3951
int main()
4052
{
41-
//cout<<CountSet(10);
42-
int n = __builtin_popcount(7);
53+
cout<<CountSet(7);
54+
// cout<<endl<<countUnset(5);
4355

44-
cout<<n;
4556
return 0;
4657
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /