Skip to main content

C Program to Check whether a given Number is Perfect Number




Here is source code :


  1. /*
  2.  * C Program to Check whether a given Number is Perfect Number
  3.  */
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8.     int number, rem, sum = 0, i;
  9.  
  10.     printf("Enter a Number\n");
  11.     scanf("%d", &number);
  12.     for (i = 1; i <= (number - 1); i++)
  13.     {
  14.         rem = number % i;
  15.  if (rem == 0)
  16.         {
  17.             sum = sum + i;
  18.         }
  19.     }
  20.     if (sum == number)
  21.         printf("Entered Number is perfect number");
  22.     else
  23.         printf("Entered Number is not a perfect number");
  24.     return 0;
  25. }



Output :

Enter a Number
6
Entered Number is perfect number
 
Enter a Number
100
Entered Number is not a perfect number



Explanation :

Number is 6 .
Its positive divisors are 1,2,3
1+2+3=6

therefore 6 is perfect number.













Comments

Popular posts from this blog

Momo suicide game

Microsoft clamps down on sick 'Momo suicide game' in 'Minecraft' Microsoft is clamping down on the sick “Momo suicide challenge,” which recently infiltrated the wildly popular online game “Minecraft.”The tech giant owns “Minecraft” developer Mojang. The vile “Momo suicide game” has been garnering attention after spreading on WhatsApp, prompting police warnings. "Momo" is a viral challenge that asks people to add a contact via WhatsApp - they are then   urged   to commit self-harm or suicide. The "game" has fueled comparisons to the sinister " Blue Whale challenge " that led to reports of suicides in Russia and the U.S, as well as the online fictional character of "Slender Man." In 2014 two 12-year-old girls in Wisconsin  attempted to kill   a classmate in an attempt to please the horror character. The Buenos Aires Times recently  reported  that police in Argentina are investigating whether “Momo” is linked to the suicide of a 12-y...

Create WAR file in Spring Boot

This is just a three step simple procedure to package your application into war. Extending Main Class First, we extend our main class to SpringBootServletInitializer. This tells spring that your main class will be the entry point to initialize your project in server. ? 1 2 3 4 5 6 7 @SpringBootApplication public class Application extends SpringBootServletInitializer{        public static void main(String[] args) {          SpringApplication.run(Application. class , args);      } } Overriding configure method Next, we overload the configure method of SpringBootServletInitializer. We tell spring to build the sources from our Main class. Your final Main class should look like this: ? 1 2 3 4 5 6 7 8 9 10 11 12 @SpringBootApplication public class Application extends SpringBootServletInitializer{        public static void main(String[] args) {     ...

Kali Linux 2017.2

Most Advanced Penetration Testing Distribution, Ever. New and Updated Packages in Kali 2017.2 In addition to all of the standard security and package updates that come to us via Debian Testing, we have also added more than a dozen new tools to the repositories, a few of which are listed below. There are some really nice additions so we encourage you to ‘apt install’ the ones that pique your interest and check them out. hurl  – a useful little hexadecimal and URL encoder/decoder phishery  – phishery lets you inject SSL-enabled basic auth phishing URLs into a .docx Word document ssh-audit  – an SSH server auditor that checks for encryption types, banners, compression, and more apt2  – an Automated Penetration Testing Toolkit that runs its own scans or imports results from various scanners, and takes action on them bloodhound  – uses graph theory to reveal the hidden or unintended relationships within Active Directory crackmapexec  – a post-expl...