본문 바로가기
반응형

반복문4

3. Loop[C Basic] 3.1. Write a program that inputs a series of 5 numbers and determines and prints the largest of the numbers Use ‘do-while’ statement #include int main() { int i=0, num, largest; do { printf("Enter the number:"); scanf("%d", &num); if (i == 0) largest = num; if (largest < num) largest = num; } while (++i < 5); printf("Largest is %d", largest); return 0; } 3.2. Write a program that prints a table .. 2021. 11. 7.
2. Loop[C Basic] 2.1. Write a program that (1) inputs two integers (integer1 and integer 2) (2) prints sum of all integers between integer1 and integer2 (3) Use while() statement #include int main() { int n1, n2, sum=0, temp; printf("Enter two integers : "); scanf("%d %d", &n1, &n2); temp = n1; if (n1 > n2) { temp = n2; n2 = n1; n1 = temp; } while (n1 0) { if (n % 10 == 7) cnt++; n /= 10; } printf("The number %d.. 2021. 11. 6.
Chapter 5. Loops(2)[Java Basic] 5.H - π 계산 Time Limit: 1s Memory Limit: 128MB DESCRIPTION 당신은 다음 계산식을 통해서 pi를 계산할 수 있습니다. i를 입력으로 받아 pi를 계산하는 프로그램을 작성하세요. You can approximate pi by using the following series: Write a program that displays the pi value for i. INPUT * Line 1 : 테스트케이스 T (1~1,000) * Line 2 ~ T+1 : 정수 i (1~1,00000) OUTPUT * Line 1 ~ T : pi(소수점 네번째 자리까지 출력, 예: 11.713243의 경우 11.7132로 출력하고 11.0000의 경우 11.0000로 출력) SAM.. 2021. 11. 5.
Chapter 5. Loops(1)[Java Basic] 5.A - 두명의 하이스코어 Time Limit: 1s Memory Limit: 128MB DESCRIPTION N명의 학생의 이름과 성적을 입력으로 받아, 1등과 2등을 한 학생의 이름과 성적을 출력하는 프로그램을 작성하세요. Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score and the student with the second-highest score. INPUT * Line 1 : 학생수 N (2~10) * Line 2 ~ N+1 : 이름 점수 - 이름은 길이가.. 2021. 11. 5.
반응형