반응형 while문2 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. 이전 1 다음 반응형