The document contains code snippets that check various types of numbers:
1) A happy number check that sums the squares of digits until reaching 1 or 4.
2) A disarium number check that sums the powers of digits based on their position.
3) A harshad number check that sums the digits and checks if the number is divisible by the sum.
4) A pronic number check that checks if a number is the product of consecutive integers.
Each code example prints whether the input number has the property or not.
The document contains code snippets that check various types of numbers:
1) A happy number check that sums the squares of digits until reaching 1 or 4.
2) A disarium number check that sums the powers of digits based on their position.
3) A harshad number check that sums the digits and checks if the number is divisible by the sum.
4) A pronic number check that checks if a number is the product of consecutive integers.
Each code example prints whether the input number has the property or not.
The document contains code snippets that check various types of numbers:
1) A happy number check that sums the squares of digits until reaching 1 or 4.
2) A disarium number check that sums the powers of digits based on their position.
3) A harshad number check that sums the digits and checks if the number is divisible by the sum.
4) A pronic number check that checks if a number is the product of consecutive integers.
Each code example prints whether the input number has the property or not.
#include<stdio.h> int main() { int num,sum=0,rem; printf("Enter the number:"); scanf("%d",&num); while(sum!=1 && sum!=4) { sum=0; while(num!=0) { rem=num%10; sum+=(rem*rem); num/=10; } num=sum; } if(sum==1) printf("It is a Happy Number."); else printf("It is not a Happy Number."); } OUTPUT ------------ Enter the number:23 It is a Happy Number.
2./*TO CHECK IF NUM IS DISARIUM NUMBER OR NOT*/
#include <math.h> #include<stdio.h> int main() { int num,c=0,a,sum=0; printf("Enter the number:"); scanf("%d",&num); int temp=num; int b=num; while(temp!=0) { temp=temp/10; c++; } while(c!=0) { a=num%10; sum += pow(a,c); num=num/10; c--; } if(sum==b) printf("it is a disarium number"); else printf("it is not a disarium number");
} OUTPUT ---------- Enter the number:175 it is a disarium number
3./*TO CHECK IF NUM IS HARSHAD NUMBER OR NOT*/
#include <math.h> #include<stdio.h> int main() { int n,a,sum=0; printf("Enter the number:"); scanf("%d",&n); int temp=n; while(n!=0) { a=n%10; sum+=a; n/=10; } if(temp%sum==0) printf("it is a harshad number"); else printf("it is not a harshad number");
} OUTPUT -------------- Enter the number:156 it is a harshad number
4./*program to check if pronic or not */
#include <stdio.h> void main() { int n,i,div; printf("Enter a number:"); scanf("%d",&n); for(i=1;i<n;i++) { if(i*(i+1)==n) { printf("is pronic"); break; } else continue; } if(i==n) { printf("is not pronic"); } } OUTPUT ------------- Enter a number:45 is not pronic