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

Source code and discussion for six programming assignments in c language focusing on using loops to solve various problems. Students will learn how to write algorithms using while and for loops, find prime numbers, calculate sum of squares, and reverse the digits of a given number.

Typology: Essays (university)

2018/2019

Uploaded on 04/16/2019

kim-jongho
kim-jongho 🇰🇷

5

(2)

8 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
컴퓨터 프로그래밍
여섯 번째 과제
담당 교수 :
: 전자공학부
: 201411340
:
pf3
pf4
pf5

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);