当前位置:网站首页>C # find perfect numbers, output daffodils and use of classes
C # find perfect numbers, output daffodils and use of classes
2022-07-27 19:59:00 【Hua Weiyun】
Perfect number
If a positive integer is equal to the sum of all divisors except itself , Call it a perfect number .
Perfect number
for(int i = 1; i < 1000; i++)
{
int sum = 0;
for(int j = 1; j < i; j++)
{
if (i % j == 0)
{
sum += j;
}
}
if (sum == i)
{
Console.WriteLine(i);
}
Code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp3{ class Program { static void Main(string[] args) { for(int i = 1; i < 1000; i++) { int sum = 0; for(int j = 1; j < i; j++) { if (i % j == 0) { sum += j; } } if (sum == i) { Console.WriteLine(i); } } Console.ReadKey(); } }}result

Previous perfect numbers within 6 28 496
Output all Narcissus
The number of daffodils is a three digit number , The cube sum of its digits is equal to the number itself
daffodils
int a, b, c;
for(int i = 100; i < 1000; i++)
{
a = i / 100;
b = i / 10 %10;
c = i % 10;
if (a * a * a + b * b * b + c * c * c == i)
{
Console.WriteLine(i);
}
Code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp4{ class Program { static void Main(string[] args) { int a, b, c; for(int i = 100; i < 1000; i++) { a = i / 100; b = i / 10 %10; c = i % 10; if (a * a * a + b * b * b + c * c * c == i) { Console.WriteLine(i); } } Console.ReadKey(); } }}result

The number of daffodils is 153 370 371 407
The use of the class
Code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp6{ class Student { public string name; public string sex; public int age; public Student(string name, string sex) { } public Student(string name, string sex,int age) { this.name = name; this.sex = sex; this.age = age; } public void Inderduce() { Console.WriteLine(" My name is "+this.name+" I am a "+this.sex+" Child , I this year "+this.age+" year "); } } class Program { static void Main(string[] args) { Student s1 = new Student(" Xiaohua "," male ",20); Student s2 = new Student(" floret "," Woman ",18); s1.Inderduce(); s2.Inderduce(); Console.ReadKey(); } }}Output results

边栏推荐
- Gestureoverlayview (gesture recognition 2)
- [basic knowledge of deep learning - 42] detailed explanation of logistic regression
- mysql函数汇总之系统信息函数
- ContextMenu (context menu)
- Datepicker and TimePicker
- JS event listening mouse keyboard form page onclick onkeydown onchange
- C170:复试筛选
- JVM概述和内存管理(未完待续)
- [basic knowledge of deep learning - 37] solve the imbalance between positive and negative samples
- SQlife(数据库)
猜你喜欢

2022爱分析·智慧社区厂商全景报告 厂商征集

AutoCompleteTextView (input box pre match)

JS event listening mouse keyboard form page onclick onkeydown onchange

ECU的软硬件架构

vlan试验2021.1.14

PC博物馆(3) MITS Altair 8800

Qt的QTextToSpeech类实现语音播报功能
![In a real case, college students were cheated when taking orders. I hope you won't be cheated [painful lesson]](/img/7d/142e69d6da1899cefbcc99d7929fba.png)
In a real case, college students were cheated when taking orders. I hope you won't be cheated [painful lesson]

Detailed interpretation of IEC104 protocol (I) protocol structure

Application pool has been disabled
随机推荐
pytorch tensor的基本函数
VS2017#include 'xxx.h'
Basic functions of pytorch tensor
JVM概述和内存管理(未完待续)
文件操作防护
Common errors reported by pytorch
Detailed interpretation of IEC104 protocol (I) protocol structure
剑指 Offer 25. 合并两个排序的链表
电容串联与并联以及电容串联与平衡电阻
[论文阅读] Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation
[basic knowledge of deep learning - 44] the method of realizing multiple classification by logistic regression
11.5.OSPF
Influxdb series (IV) TSM engine (storage principle)
Datepicker and TimePicker
dp(动态规划)
Sqlife (database)
Container summary
Turn Hyper-V on and off
统一建模语言 (UML) 规范
Introduction to reinforcement learning