A씨는 게시판 프로그램을 작성하고 있다.
A씨는 게시물의 총 건수와 한 페이지에 보여줄 게시물수를 입력으로 주었을 때 총 페이지수를 리턴하는 프로그램이 필요하다고 한다.
입력 : 총건수(m), 한페이지에 보여줄 게시물수(n) (단 n은 1보다 크거나 같다. n >= 1)
출력 : 총페이지수
A씨가 필요한 프로그램을 작성하시오.
예) 프로그램 수행 시 다음과 같은 결과값이 나와야 함.
| m | n | 출력 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 1 | 10 | 1 |
| 10 | 10 | 1 |
| 11 | 10 | 2 |
class Page
{
private:
int m, n = 0;
public:
int page = 0;
Page()
{
cout << "총 건수 : ";
cin >> m;
cout << "한 페이지에 보여줄 게시물 수 : ";
cin >> n;
if (n >= 1)
{
if (m / n > 0)
{
if (m % n == 0)
page = m / n;
else
{
page = m / n + 1;
}
}
else
{
page = 0;
}
};
}
};
int main()
{
Page p;
cout << p.page << endl;
}
#include <stdio.h>
int main() {
int m, n, result;
int i, ii;
printf("게시물 수를 입력하세요 : ");
scanf_s("%d", &m);
if (m == 0) {
printf("1 이상의 게시물 수를 입력하세요 : ");
scanf_s("%d", &m);
}
printf("한 페이지에 보여줄 게시물 수를 입력하세요 : ");
scanf_s("%d", &n);
if (m == 0) {
printf("1 이상의 수를 입력하세요 : ");
scanf_s("%d", &n);
}
i = m / n;
ii = m % n;
if (i == 0)
printf("총 페이지수는 %d입니다", 1);
else if(ii==0)
printf("총 페이지수는 %d입니다", i);
else
printf("총 페이지수는 %d입니다", i+1);
return 0;
}
C언어로 작성했습니다
#include <iostream>
using namespace std;
void math(int a,int b) {
int output;
if (a == 0)output = 0;
else if (a > b)output = 2;
else if (a == b || a < b)output = 1;
cout << "output : " << output << endl;
}
int main()
{
math(0, 1);
math(1, 1);
math(2, 1);
math(1, 10);
math(10, 10);
math(11, 10);
}
#include <iostream>
using namespace std;
int main()
{
int a, b, output;
cin >> a >> b;
while (b < 1) {
cout << "b >= 1" << endl;
cin >> a >> b;
}
if (a == 0)output = 0;
else if (a > b)output = 2;
else if (a == b || a < b)output = 1;
cout << "output : " << output;
}
C++
2020年07月02日 14:51
#include <iostream>
using namespace std;
//m=총 게시물수, n=페이지 당 보여줄 게시물
void Page(int m, int n) {
int result = 0;
if (m == 0) { cout << " 출력:" << result << endl;
return;}
int mok = m / n;
int namerge = m%n;
result = mok;
if (namerge >= 1)++result;
cout << " 출력:" << result << endl;
}
int main() {
cout << "m=0, n=1";
Page(0, 1);
cout << "m=1, n=1";
Page(1, 1);
cout << "m=2, n=1";
Page(2, 1);
cout << "m=1, n=10";
Page(1, 10);
cout << "m=10, n=10";
Page(10, 10);
cout << "m=11, n=10";
Page(11, 10);
cout << "m=19, n=10";
Page(19, 10);
cout << "m=20, n=10";
Page(20, 10);
cout << "m=21, n=10";
Page(21, 10);
}
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
int m, n, output;
printf("총 게시물 건수를 입력해주십시오.\n");
scanf("%d", &m);
printf("한 페이지에 보여줄 게시물 수를 입력해주십시오.\n");
scanf("%d", &n);
if (m % n == 0)
{
output = m / n;
}
else
{
output = m / n + 1;
}
printf("총 페이지 수는 %d 입니다.", output);
}
2020年03月09日 16:20
#include <iostream>
using namespace std;
int main() {
int TotalFileNum, FilePerPage;
cout << "총 건수와 페이지당 보여줄 게시물수를 입력하세요 : ";
cin >> TotalFileNum >> FilePerPage;
int share = TotalFileNum / FilePerPage;
int rest = TotalFileNum % FilePerPage;
if (TotalFileNum < FilePerPage) {
cout << rest << endl;
}
else {
cout << rest + share << endl;
}
return 0;
}
2020年01月22日 00:03
#include<stdio.h>
main()
{
int m, n,result=0;
printf("게시물의 총 건수와 한 페이지에 보여줄 게시물 수를 입력하세요.\n");
scanf_s("%d %d", &m, &n);
if (m > n) {
if (m % n != 0) {
result = m / n;
++result;
}
else if (m % n == 0) {
result = m / n;
}
}
else if (m == n) {
result = m / n;
}
else if (m < n) {
result = 1;
}
else
result = 0;
printf("필요한 총페이지수는 %d\n", result);
}
풀이 작성