/* Write a program that asks the user
* to enter the starting point and end
* point of the counting range and the
* increment value and displays the total
* of the numbers within that range
*/
int start;
int end;
int increment;
int sum = 0;
int count= 0;
Console.WriteLine(" Enter the start number ");
start = Int32.Parse(Console.ReadLine());
Console.WriteLine(" Enter the end number ");
end = Int32.Parse(Console.ReadLine());
Console.WriteLine(" Enter the increment number ");
increment = Int32.Parse(Console.ReadLine());
for (start = ; end <= start ; count = count + increment )
{
Console.WriteLine(" Number is: " + count);
}
Console.WriteLine(" Sum is: " + sum);
Console.ReadKey();
답변
나는 의심의 여지가 여기 없다
/* Write a program that asks the user
* to enter the starting point and end
* point of the counting range and the
* increment value and displays the total
* of the numbers within that range
*/
int start;
int end;
int increment;
int sum = 0;
int count= 0;
Console.WriteLine(" Enter the start number ");
start = Int32.Parse(Console.ReadLine());
Console.WriteLine(" Enter the end number ");
end = Int32.Parse(Console.ReadLine());
Console.WriteLine(" Enter the increment number ");
increment = Int32.Parse(Console.ReadLine());
for (count = start; //init value for count
count <= end ; //check every loop. if count still satify condition, then do thing inside tho loop
count += increment //change count every a loop done
)
{
sum += count;
Console.WriteLine(" Number is: " + count);
}
Console.WriteLine(" Sum is: " + sum);
Console.ReadKey();
이것이 작동하는 것 같습니다! 고맙습니다 ! 도 for 문을 설명 할 수 있습니까? 1. 초기화 횟수 = 시작? 2. 가드 ... 카운트가 끝나지 않은 동안? 3. 진행하십시오 ... count = count + increment –
위의 코드를 설명하려고하지만 자세한 내용은 https://www.dotnetperls.com/for를 참조하는 것이 좋습니다. – zquanghoangz
당신은 start
< end
동안 루프를 원하고, 그 조건이 충족 될 때마다, 카운터는 increment
증가합니다.
이 루프의 구조가 될 것이다 :
for (int i = start; i < end; i += increment)
{
// Add to total and display current value
}
시작 번호 이 가 증가 번호를 입력 끝 번호 입력 번호는 : 0 합이다 : 0 이 콘솔 창은 다시 나에게 묻지 무엇입니까 ?? –
루프 앞에서'count'를 선언하지 마십시오. 루프는'for (int count = start; count
- 1. 누구나이 VHDL 코드를 도와 줄 수 있습니까? (현재 오작동하고 있습니까?)
- 2. 누군가이 자바 루프를 수정하도록 도와 줄 수 있습니까? 내가이 바로
- 3. 나를 도와 줄 수 있습니까?
- 4. 청취자를 도와 줄 수 있습니까?
- 5. 누구나이 오류의 원인을 알려 줄 수 있습니까?
- 6. 누구든지이 작업을 도와 줄 수 있습니까?
- 7. 누구든지이 쿼리를 도와 줄 수 있습니까?
- 8. 누구나이 간단한 코드로 나를 도울 수 있습니까?
- 9. 누군가가 파스칼 배열을 도와 줄 수 있습니까
- 10. 누구나 구문을 도와 줄 수 있습니까?
- 11. 누구나이 스택 오버플로의 원인을 알려 줄 수 있습니까?
- 12. 누군가 나를 phpmailer로 도와 줄 수 있습니까?
- 13. 누군가 페이지 매김을 도와 줄 수 있습니까?
- 14. 누구나 정규 표현식을 도와 줄 수 있습니까?
- 15. 프레임 워크 선택을 도와 줄 수 있습니까?
- 16. 누군가가 3D 배열을 도와 줄 수 있습니까
- 17. 누군가 트윗 버튼을 도와 줄 수 있습니까?
- 18. 누구든지이 오류로 나를 도와 줄 수 있습니까?
- 19. Android datepicker에서 아무도 도와 줄 수 있습니까?
- 20. GetManifestResourceStream - 어떻게 캐싱을 도와 줄 수 있습니까?
- 21. 누군가가 의사 코드를 도와 줄 수 있습니까?
- 22. 누구나 지킬 설치를 도와 줄 수 있습니까?
- 23. 누군가이 문법을 이해하도록 도와 줄 수 있습니까?
- 24. 누군가이 JAX SAXParser를 도와 줄 수 있습니까?
- 25. 누군가이 계산 논리를 도와 줄 수 있습니까?
- 26. 누구나 jQuery 선택자를 도와 줄 수 있습니까?
- 27. 누구든지 Zoom RelativeLayout을 도와 줄 수 있습니까?
- 28. 누군가이 예제를 도와 줄 수 있습니까?
- 29. MinGW 설치를 도와 줄 수 있습니까?
- 30. for 루프를 사용한 간단한 함수
가 루프 – yashpandey
잘못 귀하의 코드를 약간 수정 다만 숙제와 일부 코드. 당신이 갇혀있는 것에 대해 명확히하고, 예상되는 결과와 실제 결과, 오류 메시지 등을 명확히하십시오. –
2 일 안에 루프를 테스트하기위한 준비를하고 있습니다. 이것은 샘플 질문입니다. 이것은 내가 돌아 오는 것입니다. 시작 번호를 입력하십시오. 1 종료 번호를 입력하십시오. 10 증분 번호를 입력하십시오. 2 숫자 : 0 합계 : 0 이것은 콘솔 창에서 다시 묻는 메시지입니다. –