Skip to main content

Posts

Armstrong Number in C

  Before going to write the c program to check whether the number is Armstrong or not, let's understand what is Armstrong number. Armstrong number  is  a number that is equal to the sum of cubes of its digits . For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers. Let's try to understand why  153  is an Armstrong number. 153 = (1*1*1)+(5*5*5)+(3*3*3)   where:   (1*1*1)=1   (5*5*5)=125   (3*3*3)=27   So:   1+125+27=153   Let's try to understand why  371  is an Armstrong number. 371 = (3*3*3)+(7*7*7)+(1*1*1)   where:   (3*3*3)=27   (7*7*7)=343   (1*1*1)=1   So:   27+343+1=371   Let's see the c program to check Armstrong Number in C. #include<stdio.h>      int  main()     {     int  n,r,sum=0,temp;   ...

C program to check whether a number is perfect number or not

Write a C program to input a number and check whether the number is Perfect number or not. How to check perfect number in C programming using loop. Logic to check perfect number in C programming. Example Input Input any number: 6 Output 6 is PERFECT NUMBER Required knowledge Basic C programming ,  If else ,  For loop What is Perfect number? Perfect number  is a positive integer which is equal to the sum of its proper positive divisors. For example: 6 is the first perfect number Proper divisors of 6 are 1, 2, 3 Sum of its proper divisors = 1 + 2 + 3 = 6. Hence 6 is a perfect number. Logic to check Perfect number Step by step descriptive logic to check Perfect number. Input a number from user. Store it in some variable say  num . Initialize another variable to store sum of proper positive divisors, say  sum = 0 . Run a loop from 1 to  num/2 , increment 1 in each iteration. The loop structure should look like  for(i=1; i<=num/2; i++) .Why iterating fro...

C program to find perfect numbers between 1 to n

  Write a C program to find all Perfect numbers between 1 to n. C program to find all perfect numbers between given range. How to generate all perfect numbers between given interval using loop in C programming. Logic to find all perfect numbers in a given range in C programming. Example Input Input upper limit: 100 Output Perfect numbers between 1 to 100: 6, 28 Required knowledge Basic C programming ,  If statement ,  For loop ,  Nested loop Must know –  Program to check divisibility. What is Perfect number? Perfect number  is a positive integer which is equal to the sum of its proper positive divisors. For example: 6 is the first perfect number Proper divisors of 6 are 1, 2, 3 Sum of its proper divisors = 1 + 2 + 3 = 6. Hence 6 is a perfect number. Logic to find all Perfect number between 1 to n Step by step descriptive logic to find Perfect numbers from 1 to n. Input upper limit from user to find Perfect numbers. Store it in a variable say  end . Run...