01: #include <stdio.h>
02: #include <stdlib.h>
03: #include <string.h>
04: 
05: int numandstring(char* arr, int size);
06: int Sum(int a);
07: int main(void)
08: {
09:         char str[30];
10:         int result;
11:         int lang;
12:         int sum;
13:         fgets(str, sizeof(str),stdin);
14:         lang = strlen(str);
15:         result = numandstring(str, lang);
16:         sum = Sum(result);
17:         printf("%d \n" , sum);
18:         return 0;
19: 
20: }
21: 
22: int numandstring(char* arr, int size)
23: {       
24:         int add = 0; 
25:         int i,j,k=0;
26:         for(i=0 ; i<size ; i++)
27:         {       
28:                 if(k == 1) 
29:                 {
30:                         i=0;
31:                         k=0;
32:                 }
33:                 if((65<=arr[i] && arr[i]<=90) || (97<=arr[i] && arr[i] <=122)) 
34:                 {
35:                         for(j=i ; j<size ; j++) arr[j] = arr[j+1];
36:                         size--;
37:                         k++;
38:                 }
39:         }
40: 
41:         return atoi(arr);
42: }
43: 
44: int Sum(int a)
45: {       
46:         int temp=0;
47: 
48:         while(a != 0)
49:         {
50:                 temp += a%10;
51:                 a = a/10;
52:         }
53:         return temp;
54: }
 
이 문제 답안은 정말 짧구나 ..
그렇지만 .. 시간을 들여 푼 문제이기에 남겨 둬야 겠다.!
좀 부끄럽기도 하지만 ....이렇게 짠거에 대해 ....
그래도 언젠가는 나도 늘겠지 !! 

01: #include <stdio.h>
02: 
03: void DesSort(int *arr, int size);
04: 
05: int main(void)
06: {       
07:         int data[7];
08:         int i;
09:         for(i=0 ; i<7 ; i++)
10:         {
11:                 scanf("%d" , &data[i]);
12:         }
13:         DesSort(data, sizeof(data)/sizeof(int));
14: 
15:         for(i=0 ; i<7 ; i++){
16:                 printf("%d ",data[i]); 
17:         }
18:         printf("\n");
19:         return 0;
20: }       
21: 
22: void DesSort(int *arr, int size)
23: {
24:         int i,j,temp;
25:         for(i=0 ; i<size ; i++)
26:         {
27:                 for(j=0 ; j<size-i ; j++)
28:                 {
29:                         if(arr[j] < arr[j+1]){
30:                                 temp = arr[j];
31:                                 arr[j] = arr[j+1];
32:                                 arr[j+1] = temp;
33:                         }
34:                 }
35:         }
36: }

'C.C++ > 열혈강의 C' 카테고리의 다른 글

연습문제 21_2 >문제1번  (0) 2010.01.21
도전프로그래밍ONE_도전6번  (0) 2010.01.18
도전 프로그래밍 ONE_도전5번  (0) 2010.01.18
도전프로그래밍ONE_도전3번  (0) 2010.01.13
도전프로그래밍 ONE_도전2번  (0) 2010.01.13
01: #include <stdio.h>
02: 
03: int main(void)
04: {
05:         int second;
06:         int h,m,s;
07: 
08: 
09:         printf("초(second) 입력: ");
10:         scanf("%d" , &second);
11:         
12:         s = second%60;
13:         second = second/60;
14:         m = second%60;
15:         second = second/60;
16:         h =second%60;
17: 
18:         printf("h: %d, m: %d, s: %d \n" , h,m,s);
19:         return 0;
20: }       

'C.C++ > 열혈강의 C' 카테고리의 다른 글

연습문제 21_2 >문제1번  (0) 2010.01.21
도전프로그래밍 TWO_도전5번  (0) 2010.01.18
도전 프로그래밍 ONE_도전5번  (0) 2010.01.18
도전프로그래밍ONE_도전3번  (0) 2010.01.13
도전프로그래밍 ONE_도전2번  (0) 2010.01.13
01: #include <stdio.h>
02: 
03: int main(void)
04: {
05:         int temp;
06:         int i;
07:         int num;
08:         for(temp=2 ; temp<30 ; temp++)
09:         {
10:                 num = 0;
11:                 for(i=2; i<=temp; i++){
12:                         if(temp%i == 0){
13:                                 num++;
14:                         }
15:                 }
16:                 if(num == 1) printf("%d ",temp);
17:         }
18:         printf("\n");
19:         return 0;
20: }       

01: #include <stdio.h>
02:  
03:  int main(void)
04:  {
05:          int temp1, temp2, temp3 ;
06:          int i=2;
07:                  int j=0;
08:                  printf("1보다 큰 두 수를 넣어 주세요 ! ");
09:          scanf("%d %d" , &temp1 , &temp2);
10:  
11:          while(i<=temp1)
12:          {
13:                  if((temp1%i == 0) && (temp2%i ==0)){
14:                    temp3 = i;
15:                  }
16:                                  else {
17:                                         j=1;
18:                                         break;
19:                                  }
20:                  i++;
21:  
22:  
23:          }
24:                  if(j==0) printf("G C M :  %d \n" ,temp3);
25:                  else printf("없습니다. \n");
26:                 return 0;
27:  }
01: #include <stdio.h>
02: 
03: int main(void)
04: {
05:         int temp1, temp2, temp3 ;
06:         int i,j;
07:         scanf("%d %d" , &temp1 , &temp2);
08: 
09:         if(temp1 > temp2)
10:         {
11:                 temp3 = temp1;
12:                 temp1 = temp2;
13:                 temp2 = temp3;
14:         }
15:         for(i=temp1 ; i<=temp2 ; i++){
16:                 for(j=1 ; j<10 ; j++)
17:                 {
18:                         printf("%d * %d = %d \n", i, j, i*j);
19:                 }
20:                 printf("\n");
21:         }
22:         return 0;
23: }
24: 
01: #include <stdio.h>
02: 
03: int main(void)
04: {
05:         int temp;
06: 
07:         scanf("%d" , &temp);
08: 
09:         printf("%x \n" , temp);
10: }
11: 
01: #include <stdio.h>
02: 
03: int main(void)
04: {
05:         int arr[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
06:         int temp[4][4];
07:         int i,j;
08:         for(i=0 ; i<4 ; i++){
09:                 for(j=0 ; j<4 ; j++){
10:                         temp[i][j] = arr[3-j][i];
11:                 }
12:         } 
13: 
14:         for(i=0 ; i<4 ; i++){
15:                 for(j=0 ; j<4 ; j++){
16:                         printf("%4d " , temp[i][j]);
17:                 }
18:                 printf("\n");
19:         } 
20:         return 0;
21: }
22: 

+ Recent posts