# Programming Videos

## Search

### Perfect Number Program in C, C++

Write a C, C++ program to check whether a given number is perfect or not. We have to write a program to check whether a input number is perfect.

Perfect Number

A perfect number, is a positive integer that is equal to the sum of its proper divisors.

For example - 6 is a perfect number.

6  = 1 + 2 + 3 (1,2,3 is it's factors).

Similarly 28 is a perfect number.

28 = 1 + 2 + 4 + 7 + 14

Let's take another example of 12. Factors of 12 is 1, 2, 3, 4, 6.

1 + 2 + 3+ 4 + 6 = 16. So we can conclude that 12 is not a perfect number.

Print factors of a number

C, C++ Interview Questions

Print prime numbers between 1 to 100

## Perfect Number Program in C

```#include <stdio.h>

int main(void) {

int num, i=1, sum=0;

printf("Enter number \n");
scanf("%d",&num);

/* Check if entered number is greater than zero. */

if( num > 0){

while(i < num){

if(num % i==0){
sum = sum + i;
}

i++;
}

/* If entered number is equal to it's proper divisiors. */

if(sum == num){

printf("\n %d is a perfect number",i);

} else {

printf("\n %d is not a perfect number",i);

}

} else {

printf("Perfect number should be greater than zero");

}

return 0;
}

```
Output :

Enter number : 6

6 is a perfect number

Enter number : 23

23 is not a perfect number

## Perfect Number Program in C++

```#include <iostream>
using namespace std;

int main() {

int num, sum = 0;

cout << " Enter a number to check whether it's a perfect or not \n";
cin >> num;

for (int i = 1; i < num; i++) {

if (num % i == 0) {

sum = sum + i;

}
}

if ( sum == num) {

cout << num << " is a Perfect number";

} else {

cout << num << " is not a Perfect number";

}

return 0;
}
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.7200142,"math_prob":0.999424,"size":2161,"snap":"2023-40-2023-50","text_gpt3_token_len":679,"char_repetition_ratio":0.19239685,"word_repetition_ratio":0.54077256,"special_character_ratio":0.37575197,"punctuation_ratio":0.14345114,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9995402,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-26T19:13:34Z\",\"WARC-Record-ID\":\"<urn:uuid:9ce66fba-a793-4c95-ab08-4bdb1729830d>\",\"Content-Length\":\"43412\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7dd176f3-8463-4566-b911-144cfa142188>\",\"WARC-Concurrent-To\":\"<urn:uuid:f87aa830-7d65-45f2-b3f0-06b830670dc1>\",\"WARC-IP-Address\":\"172.253.63.121\",\"WARC-Target-URI\":\"http://www.cprogrammingcode.com/2015/03/c-program-to-check-whether-given-number.html\",\"WARC-Payload-Digest\":\"sha1:UM4MQSSRORZ2THTAZ7JTVFHMF4LLOP2D\",\"WARC-Block-Digest\":\"sha1:DOURJFQK2SR6SH7FON5R535WAZFLH72C\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510219.5_warc_CC-MAIN-20230926175325-20230926205325-00632.warc.gz\"}"}