안녕하세요 저는 C#에 약간 새로운 것이므로 오늘 1 주일이 지났습니다. 필자는 이것을 멀리까지 얻을 수 있었지만, 나는 그냥 짝수의 합을 넣은 것처럼 보였다. 나는 전체 출력을 얻었고, 마지막 숫자는 마지막으로 보여주고 싶을 뿐이라는 것을 제외하고는 합계되었다. 어떤 도움이라도 몹시 고맙고 끔찍한 코드에 사과드립니다. 감사합니다C#의 숫자와 큐브 숫자의 합
using System;
public class Test
{
public static void Main()
{
int j = 0; //Declaring + Assigning the interger j with 0
int Evennums = 0; // Declaring + Assigning the interger Evennums with 0
int Oddnums = 0; //Declaring + Assigning the interger Oddnums with 0
System.Console.WriteLine("Calculate the sum of all even numbers between 0 and the user’s number then cube it!"); //Telling console to write what is in ""
Console.WriteLine("Please enter a number");
uint i = uint.Parse(Console.ReadLine());
Console.WriteLine("You entered: " + i);
Console.WriteLine("Your number cubed: " + i*i*i);
if (i % 2 == 0)
while (j <= i * i * i)
{
if(j % 2 == 0)
{
Evennums += j; //or sum = sum + j;
Console.WriteLine("Even numbers summed together " + Evennums);
}
//increment j
j++;
}
else if(i%2 != 0)
//reset j to 0 like this: j=0;
j=0;
while (j<= i * i * i)
{
if (j%2 == 0)
{
Oddnums += j;
//Console.WriteLine(Oddnums);
}
//increment j
j++;
}
}
}
콘솔 출력에게 그것은 단순한 것을 몰랐어요 작동 – Robin