---
title: "How do I make a C# program that checks for given array by user which elements are perfect numbers?"  
description: "How do I make a C# program that checks for given array by user which elements are perfect numbers?"  
author: "Mukul Goenka"  
published: 2021-11-14  
updated: 2021-11-14  
canonical: https://www.mindstick.com/forum/156830/how-do-i-make-a-c-sharp-program-that-checks-for-given-array-by-user-which-elements-are-perfect-numbers  
category: "c#"  
tags: ["c#", "for loop"]  
reading_time: 1 minute  

---

# How do I make a C# program that checks for given array by user which elements are perfect numbers?

How do I make a [C# program](https://www.mindstick.com/forum/156831/can-you-tell-me-the-code-to-write-a-c-sharp-program) that checks for given [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) by [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) which [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) are perfect numbers?

## Replies

### Reply by Ravi Vishwakarma

```
using System;class HelloWorld {    static void Main() {        int[] myNum = {10, 6, 20, 28, 30, 40, 496, 500};        HelloWorld hw = new HelloWorld();        hw.printPrimeNumber(myNum);    }    public void printPrimeNumber(int[] array){        for(int i=0; i<array.Length; i++)            if(checkPerfectNo(array[i]))                Console.WriteLine(array[i] + ' is prime number');            else                Console.WriteLine(array[i] + ' is not prime number');    }    public bool checkPerfectNo(int num){    int sum = 0;    for(int i= 1; i<=num/2; i++)        if(num % i == 0)            sum+=i;    return num == sum ;    }}
```

Output.

```
10 is not prime number
6 is prime number
20 is not prime number
28 is prime number
30 is not prime number
40 is not prime number
496 is prime number
500 is not prime number
```


---

Original Source: https://www.mindstick.com/forum/156830/how-do-i-make-a-c-sharp-program-that-checks-for-given-array-by-user-which-elements-are-perfect-numbers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
