레이블이 #기초컴퓨터프로그래밍인 게시물을 표시합니다. 모든 게시물 표시
레이블이 #기초컴퓨터프로그래밍인 게시물을 표시합니다. 모든 게시물 표시

4.30.2017

BMI 구하기

#include <iostream>

using namespace std;



int main() {

double i, j, k;



cout << "키를 입력해주십시오\n" << endl;

cin >> i;

cout << "몸무게를 입력해주십시오\n" << endl;

cin >> j;



k = j/ (i*i);



cout << "당신의 BMI는" << k << "입니다" << endl;



system("pause");

return 0;

}




4.13.2017

소수 구하기

#include <iostream>
using namespace std;
int divisor (int n)
{
 int i = 2;
 while (i <=n) {
  if (n % i == 0)
   return i;
  i++;
 }
 return n;
}
int main(){
 int n = 2, j = 0;
 while (n <=1000){

  if (divisor(n) == n ) {
   j++;
   cout << n <<" ";
    if(j%7==0)
    {
     cout<<endl;
    }
   }
  n++;
 }
 cout << j << endl;
system("pause");
return 0;
}

4.03.2017

기초 컴퓨터프로그래밍 과제

#include <iostream>
using namespace std;

double factorial(int n)
{
if (n == 1)
return n;
else {
return n *factorial(n - 1);
}
}

int main() {
int n;
int i = 1;
double result = 1.0;

cin >> n;

result = 1 / factorial(n);

while (i < n) {
result += 1 / factorial(n - i);
i++;
}


cout << "e=" << 1 + result << endl;

system("pause");

return 0;
}

// 다음과 같은 표를 출력하는 프로그램을 작성하여라. (1마일은 1.609 킬로미터이다)

#include <iostream>
using namespace std;

int main() {

int mile = 1;
double kilo = 1.0;

cout << "프로그램의 결과는?\nMiles\tKilometers\n" ;

while (mile <= 10) {

kilo = mile * 1.609;

cout << mile << "\t" << kilo << endl;

mile++;

}

system("pause");

return 0;

}

//2진수를 입력 받아 10진수로 변환하여 출력하는 프로그램을 작성하시오.//

#include <iostream>
using namespace std;

int main() {

int input;
int ten = 0, p = 1;

cout << "2진수 입력하기" << endl;
cin >> input;

while (input > 0) {
{
ten = (input%10)*p + ten;
input /= 10;
p *= 2;
}
}

cout << "10진수 일 때 결과는?\n" << ten << endl;

system("pause");

return 0;

}

3.30.2017

3월 30일 실습 과제

#include <iostream>
using namespace std;
int fact(int n){}
int main() {
int n, r;
cin >> n >> r;

int combi;
combi = fact(n) / (fact(r) ^ fact(n-r));
cout << combi << endl;
system("pause");
return 0;
}

3.16.2017

3월 16일 실습과제

//원화값 입력받아 달러로 출력하기
#include <iostream>
using namespace std;

int main() {
int i, k;

cout<<"원화값을 입력해주십시오"<<endl;
cin>>i;

double j;

j = i/1150.0;

cout<<j<<"달러"<<endl;

system("pause");
return 0 ;
}

====================================================
//원화값 입력받아 달러와 센트로 출력하기
#include <iostream>
using namespace std;

int main() {
int i, j, k;

cout<<"원화값을 입력해주십시오"<<endl;
cin>>i;


j = i/1150;

cout<<j<<"달러"<<endl;

k = (i%1150)/1150.0 *100;

cout<<k<<"센트"<<endl;

system("pause");
return 0 ;
}