Docsity

C Programming Assignments: Solving Problems with Loops, Essays (university) of Programming Methodologies

Partial preview of the text

Download C Programming Assignments: Solving Problems with Loops and more Essays (university) Programming Methodologies in PDF only on Docsity!

3. source code

#include <stdio.h> int main(void) { int x, y, z; for (y = 0; y < 7; y++) { { for (x = 1; x < (7 - y); x++) printf(" "); for (z = 1; z < (y + 2); z++) printf("*"); } printf("\n"); } return 0; }

4. source code

#include <stdio.h> int main(void) {

while (y < (x + 1)) { if ((x % y) == 0) num = (num + 1); y++; } if (num == 2) printf("%d ", x); x++; } } printf("\n"); return 0; }

11. source code

/1^2 +2^2 +3^2 +...+n^2 의 값을 계산하여 출력하는 프로그램/ #include <stdio.h> int main(void) { int x = 1, n, answer = 0; printf("n의 값을 입력하시오: "); scanf("%d", &n); while (x < (n + 1))

answer = (answer + x*x); x++; } printf("계산값은 %d입니다.\n", answer); return 0; }

14. source code

#include <stdio.h> int main(void) { int N, x; printf("정수를 입력하시오: "); scanf("%d", &N); if (N < 0) printf("오류! 양수를 입력하시오."); else do { x = N % 10; printf("%d", x); N = N / 10; } while (N > 0);