Top Banner
Frequently asked c programs in interview 1. Find out the perfect number using c program Code 1: 1. C program to check perfect number #include<stdio.h> int main(){ int n,i=1,sum=0; printf("Enter a number: "); scanf("%d",&n); while(i<n){ if(n%i==0) sum=sum+i; i++; } if(sum==n) printf("%d is a perfect number",i); else printf("%d is not a perfect number",i); return 0; } Sample output: Enter a number: 6 6 is a perfect number
60

Frequently Asked c Programs in Interview(15)

Dec 17, 2015

Download

Documents

Chandu Jonty

FAQ in Interview
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Frequently asked c programs in interview1. Find out the perfect number using c program

Code 1:1.C program to check perfect number

#includeintmain(){intn,i=1,sum=0;

printf("Enter a number: "); scanf("%d",&n);

while(i