리힛 [351540] · 쪽지

2011-04-17 22:23:23
조회수 286

그럼 전 이만..

게시글 주소: https://orbi.kr/0001054850

1. 다음 프로그램을 작성하고, 결과 값을 분석해 본다.
#include <stdio.h>
main(){
        int a = 3, b = 4, c;
        float d, e;


        c = a / b;
        d = (float) a / b;
        e = (float)(a / b);


        printf("%f %f %f\n", (float)c, d, e);
}
/* c는 상수끼리의 계산이니까 0.000000이라는 수치가 나온다.
   d는 a가 소수로 변했기 때문에 계산 후에 0.750000 이라는 수치로 나온다.
   e는 이미 상수끼리 계산해서 0이 나온 결과값을 소수로 만든것이다. */



2.Write exactly the result printed when executing the following program.


#include <stdio.h>
int compute_sum(int  n);


int main(void)
{   int n = 3, sum;


    printf("%d\n", n);
    sum= compute_sum(n);
    printf("%d\n", n);
    printf("%d\n", sum);
    return 0;
}
int compute_sum(int  n)
{   int sum=0;


    printf("%d\n", ++n);
    for (; n>0 ; --n){
       sum += n;
       printf("%d\n",sum);} 
    printf("%d\n", n++);
    printf("%d\n", sum+1);
    return sum;
}


/*
3
4
4
7
9
10
0
11
3
10
*/


3. Write exactly the result printed when executing the following program.[10]


#include <stdio.h>
int main()
{
     int  i, j;
     for (i = 1 ; i <= 5 ; i++){
         if (i == 3) 
             continue;
         else
             printf("%d\n",i);
     }
     for (j = 1 ; j <= 5 ; j++){
         if (j == 3) 
             break;
         else
             printf("%d\n",j);
     }
     return 0;
}



4.Write a function definition all_equal() that takes three integers as inputs and returns the value 1 if they are all equal otherwise returns the value 0.[20]  



int all_equal(int a, int b, int c)
{
 /* write the codes that takes three integers as inputs and returns the value 1 if they are all equal otherwise returns the value 0.*/


 }



5.Convert the following switch statement to an if-else statement.[15]
switch (op)
{
   case 1:
      printf("AAA\n");
      break;
   case 2:
   case 3:
      printf("BBCC\n");
      break;
   default:
      printf("nothing\n");
      break;
}


이런걸 하러....전 어서 가봐야겠습니다
아직 3문제나 남았군요 핳핳.

0 XDK (+0)

  1. 유익한 글을 읽었다면 작성자에게 XDK를 선물하세요.