program to check if a number is "perfect number".



program to check if a number is "perfect number"...

Answer / athresh

public boolean isPerfect(int number)
{
int i = sumFactors(number);
if (i == number)
{
return true;
}
else
return false;
}


public int sumFactors(int number)
{
int factor = 0, sum = 0;
for (int i = 1; i < number; i++){
if (!(number % i)){
factor = i;
sum += factor;
}
}
return sum;
}

Is This Answer Correct ?    13 Yes 13 No

Post New Answer

More C Sharp Code Interview Questions

How to add a value from textBox over an existing certain column in SQL Server

0 Answers  


how to get the table names via c sharp and column names also?

2 Answers   Sify,


Code for IP Address Comparison and Conversion in C#?

0 Answers  


Write a program to convert postfix expression to infix expression.

0 Answers   Mind Tree,


Write a program to count the number of characters, number of words, number of line in file.

2 Answers   Mind Tree,






Can you declare an array of mixed Types?

1 Answers   HCL,


How to Create a Treeview Menu in ASP.NET with C#?

1 Answers  


Code for Searching for Multiple Matches with the MatchCollection Class?

0 Answers   TCS,


Give the code for Handling Mouse Events?

0 Answers  


"c sharp" code for factorial using static variables

9 Answers  


c# coding for a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors not using the Big-integer and Exponential Function's.

1 Answers   TCS,


program to reverse the order of digits in a given number of any length.

1 Answers   Mind Tree,


Categories
  • ASP.NET Code Interview Questions ASP.NET Code (46)
  • VB.NET Code Interview Questions VB.NET Code (9)
  • C Sharp Code Interview Questions C Sharp Code (51)
  • ADO.NET Code Interview Questions ADO.NET Code (8)