728x90
반응형
배열이나 문자열을 사용하지 않고 산술연산만을 이용하여 입력된 숫자가 역으로 출력되게 하는 프로그램이다.
0123456 -> 654321 맨앞 0은 표시 하지 않게 한다.. 일반적인 1234 -> 4321로 표현하는 것~!
#include <stdio.h>
int rev(int input){
int n,cnt=0,cnt1=0,sum=0,k=1;
n = input;
while(input>0){
input = input/10;
cnt++;
}
cnt1 = cnt;
while(cnt1>1){
k = k*10;
cnt1--;
}
while(n>0){
sum =sum+((n%10)*k);
n = n/10;
k=k/10;
}
printf("%d",sum);
return 0;
}
void main(){
int x,sss;
scanf("%d",&x);
sss = rev(x);
}
728x90
반응형
'C언어' 카테고리의 다른 글
퀵 소팅 알고리즘 (0) | 2010.10.15 |
---|---|
쉘정렬 알고리즘 시간 복잡도 (0) | 2010.10.15 |
합병 정렬 알고리즘 (0) | 2010.10.15 |
c언어 최대공약수 / 최소공배수 (0) | 2010.10.15 |
팩토리얼 재귀함수로 구현하기 (0) | 2009.10.19 |