Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Thursday, 18 April 2019

Check whether a given number is Automorphic number or not

// C program to check whether the number is automorphic or not
#include<stdio.h>
bool isAutomorphic(int N)
{
int sq = N * N;
while (N > 0)
{
if (N % 10 != sq % 10)
return false;
// Reduce N and square
N /= 10;
sq /= 10;
}
return true;
}
int main()
{
//Fill the code
int N;
scanf(“%d”,&N);
isAutomorphic(N) ? printf(“Automorphic”) : printf(“Not Automorphic”);
return 0;
}

Program to check if a given number is a strong number or not

Program to check if a given number is a strong number or not is discussed here. A strong number is a number in which the sum of the factorial of the digits is equal to the number itself.
check if a given number is strong number or not
#include<bits/stdc++.h>
using namespace std;
int fact(int num)
{
int res=1;
while(num>0)
{
res*=(num--);
}
return res;
}
bool isStrong(int num)
{
int p=num;
int res=0;
while(p>0)
{
res+=fact(p%10);
p/=10;
}
if(res==num)
return 1;
return 0;
}



int main()
{
int num=123;
cout<<isStrong(num);
}

Program to Find if number is Armstrong Number or Not in C++ C

#include<bits/stdc++.h>
using namespace std;
bool isArm(int num)
{
int ans=0;
int p=num;
while(num>0)
{
int x=num%10;
ans+=x*x*x;
num/=10;
}
if(p==ans)
return 1;
return 0;
}
int main()
{
cout<<isArm(371);
}

Program to check number is Prime or Not in C++

#include<bits/stdc++.h>
using namespace std;
bool isPrime(int num)
{
int p=num;
if(num%2==0)
return 0;
for(int i=3;i*i<=p;i+=2)
{
if(num%i==0)
return 0;
}
return 1;
}

int main()
{
int num=91;
cout<<isPrime(num);
}

LCM of Two Number Program in C++

// LCM of two number is a*b divided by gcd/hcf of two number
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int __gcd(int a,int b)
{
if(b==0)
return a;
return __gcd(b,a%b);
}
int main()
{
int a=12;
int b=6;
int lcm=(a*b)/__gcd(a,b);
cout<<lcm;
}

Program to Calculate GCD or HCF of Two Numbers in C++ (No STL)

// mail me @ mujtaba.aamir1@gmail.com for c++,python notes for free.....
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int __gcd(int a,int b)
{
if(b==0)
return a;
return __gcd(b,a%b);
}
int main()
{
int a=12;
int b=6;
cout<<__gcd(a,b);
}

Amazon1Ads