TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Identify The Given Number Is Perfect Or Not In C#
Vijayaragavan S
Aug 27
2016
Code
2.2
k
0
2
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System;
class
Perfect {
static
void
Main() {
int
number, sum = 0, n;
Console.Write(
"Enter the Number : "
);
number = Convert.ToInt16(Console.ReadLine());
n = number;
for
(
int
i = 1; i < number; i++) {
if
(number % i == 0) {
sum = sum + i;
}
}
if
(sum == n) {
Console.WriteLine(
"\n Given number is a perfect number"
);
Console.ReadKey();
}
else
{
Console.WriteLine(
"\n Given number is not a perfect number"
);
Console.ReadKey();
}
}
}
Perfect Number
C#