Enter a number: 6 6 is a perfect number Program 2 C program to print perfect numbers from 1 to 100 #include<stdio.h> int main(){ int n,i,sum; printf("Perfect numbers are: "); for(n=1;n<=100;n++){ i=1; sum = 0; while(i<n){ if(n%i==0) sum=sum+i; i++; } i...
in)); String CPN; int i,x,Number,m; System.out.print("Check Number to Prime or Not : "); CPN=Prime.readLine(); Number=Integer.parseInt(CPN); x=0; for(i=2;i<=Number-1;i++) { m=Number%i; if(m==0) { System.out.println(Number +" Number is not Prime"...
*perfect number, if a number equals the sum of it's factor,then it is a perfect number. **/ #include<stdio.h> int factorSum(int n) { int sum = 0; for(int i = 1;i < n;i++) { if(0 == n % i) sum += i; } return sum; } int isPerNum(int m) { if(m == factor...
System.out.print("Sum of digits of number "+tempNum+" is "+total); } } Output: Enter a Number : 5385 Sum of digits of number 5385 is 21 That’s all about Java program to add digits of number.
How to swap two numbers without using temporary variables in java Reverse number in java Even odd program in java Java program for sum of digits of number Java program to calculate average marks Java program to print table of number Happy Number program in Java Find Perfect Number in JavaShare...
import java.util.*; public class Main{ public static void main(String args[]){ mainLoop: while (true) { Scanner sc = new Scanner( System.in ); System.out.println("\n***Menu***"); System.out.println("1. Check for Integer"); System.out.println("2. Check for Double"); System....
In Java, checking whether a number is a perfect square or not is a common task. A number is called a perfect square if it can be expressed as the product of an integer with itself. For example, 16 is a perfect square because it is the result of multiplying 4 × 4. ...
# Define a function for checking perfect number# and print that numberdefcheckPerfectNum(n):# initialisationi=2sum=1# iterating till n//2 valuewhilei<=n //2:# if proper divisor then add it.ifn % i==0:sum+=i# incrementing i by onei +=1# check sum equal to n or notifsum...
//C# program to check the given number is a//perfect number or not.usingSystem;classCheckPerfect{staticboolIsPerfect(intnumber){intsum=0;intiLoop=0;for(iLoop=1;iLoop<number;iLoop++){if(number%iLoop==0)sum=sum+iLoop;}if(sum==number){returntrue;}returnfalse;}staticvoidMain(string[]args)...
for(inti=2;i<=num/2;i++){temp=num%i;if(temp==0){isPrime=false;break;}} with this: inti=2;while(i<=num/2){if(num%i==0){isPrime=false;break;}i++;} Top Related Articles: Sunny Number Program in Java Java Program to reverse the Array ...