C프로그래밍실습
본 자료는 4페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
해당 자료는 4페이지 까지만 미리보기를 제공합니다.
4페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

C프로그래밍실습에 대한 보고서 자료입니다.

본문내용

,b;
float c;
char ch;
printf(\"연산자를 입력하시오(+,-,*,/) : \");
scanf(\"%c\", &ch);
printf(\"%c 하고자 하는 숫자를 입력하시오 : \", ch);
scanf(\"%d%d\", &a, &b);
if(ch == \'+\')
c = a+b;
else if(ch == \'-\')
c = a-b;
(1) else if(ch == \'*\')
c = a*b;
(2) else if( ch == \'/\')
(3) c = (float)a/b;
else
printf(\"연산자 입력 오류\");
printf(\"연산 결과는 %f 입니다\\n\", c);
}
8. 다음의 실행결과를 쓰시오. (10)
#include
void f_call(int a)
{
a *= 5;
printf(\"함수 f_call에서 값 출력 : %d \\n\", a);
}
void main()
{
int a;
printf(\"숫자를 입력하시오 : \");
scanf(\"%d\", &a);
f_call(a);
printf(\"-------------\\n\");
}
답 :
숫자를 입력하시오 : 4
함수 f_call에서 값 출력 : 20
-------------
1. 다음 프로그램을 작성하고 보기의 각 경우의 실행 결과를 쓰시오(각 5점).
#include
int mul(int i, int j)
{
return(i*j);
}
float divide(int i, int j)
{
return((float)i/j);
}
void main()
{
int a, b;
char op;
float result;
printf(\"연산자를 입력하시오\\n\");
scanf(\"%c\",&op);
printf(\"두 정수를 입력하시오\\n\");
scanf(\"%d%d\", &a, &b);
if(op == \'*\')
printf(\"result => %d \\n\", mul(a,b));
else if(op == \'/\')
{
if(b != 0)
printf(\"result => %f \\n\",divide(a,b));
else printf(\"0으로 나눌 수 없음\\n\");
}
else printf(\"연산자 error\\n\");
}
-보기-
(1)연산자 : * 두 정수 : 8,9
(2)연산자 : / 두 정수 : 5,0
(3)연산자 : - 두 정수 : 4,3
(1)연산자를 입력하시오
*
두 정수를 입력하시오
8
9
result => 72
(2)연산자를 입력하시오
/
두 정수를 입력하시오
5
0
0으로 나눌 수 없음
(3)연산자를 입력하시오
-
두 정수를 입력하시오
4
3
연산자 error
2. 다음 프로그램을 작성하고 각 연산에 대한 실행 결과를 쓰시오. 이때 입력은 1+2의 형태로 한다.(각 5점)
#include
void fun(float a, float b, char op)
{
float result;
if(op == \'+\')
result = a+b;
else if(op == \'-\')
result = a-b;
else if(op == \'*\')
result = a*b;
else if(op == \'/\')
result = a/b;
printf(\"result = %f\", result);
}
void main()
{
float a,b;
char op;
scanf(\"%f%c%f\", &a,&op,&b);
fun(a,b,op);
}
4. 다음과 같이 위 3번의 main함수 부분이 수정되었을 때 3번과 실행결과와 같은 결과를 보이도록 fun함수를 수정하시오.(10점)
void main()
{
float a,b,result;
char op;
scanf(\"%f%c%f\", &a,&op,&b);
result=fun(a,b,op);
printf(\"%f\", result);
}
답 : float fun(float a, float b, char op)
{
float result;
if(op == \'+\')
result = a+b;
else if(op == \'-\')
result = a-b;
else if(op == \'*\')
result = a*b;
else if(op == \'/\')
result = a/b;
return(result);
}
4. 문자를 입력받아서 대소문자를 구별하는 프로그램이다, 대소문자의 경우를 모두 입력하고 그 실행결과를 쓰시오.(5점)
(A: 65 B:66...Z:90 a : 97 b:98 ...z:122)
#include
void main()
{
char ch;
scanf(\"%c\", &ch);
if((ch>=65 && ch<=90))
printf(\"대문자 \\n\");
else if( (ch >=97) && (ch<=122))
printf(\"소문자 \\n\");
else printf(\" 알파벳이 아님!\\n\");
}
5. 문자를 입력받아서 대소문자를 구별하는 프로그램을 함수를 이용하여 작성하시오.(1,3,4번 각 5점/ 2번 10점 )
void alpha( (1)char c )
{
(2) if((ch>=65 && ch<=90))
printf(\"대문자 \\n\");
else if( (ch >=97) && (ch<=122))
printf(\"소문자 \\n\");
else printf(\" 알파벳이 아님!\\n\");
}
void main()
{
(3)char ch;
printf(\"문자를 입력하시오\\n\");
scanf(\"%c\", &ch);
alpha( (4) ch);
}
7. 정수를 입력받아서 짝수/홀수를 구별하는 프로그램을 작성하시오. 이때 짝.홀수를 구별하는 부분은 함수 호출을 이용하시오.(20점)
예) 수를 입력하시오
30
짝수입니다.
void my_function(int i)
{
if(i % 2 == 0)
printf(\"짝수\");
else
printf(\"홀수\");
}
void main()
{
int num;
printf(\"정수를 입력하시오\\n\");
scanf(\"%d\", &num);
my_function(num);
}

키워드

  • 가격무료
  • 페이지수14페이지
  • 등록일2010.05.11
  • 저작시기2005.10
  • 파일형식한글(hwp)
  • 자료번호#609782
본 자료는 최근 2주간 다운받은 회원이 없습니다.
다운로드 장바구니