본문 바로가기

Embeded C/C언어 예제

C언어로 초 입력시 분과 초로 변환하는 프로그램

C언어로 초 입력시 분과 초로 변환하는 프로그램를 작성하여 보겠습니다

예상결과>>
출력) Input Seconds :  100
 Output :  1 min 40 sec

Input Seconds :  80
 Output :  1 min 20 sec

Input Seconds :  -1
 프로그램 종료!!!

1) 프로그램을 무한 반복하지만 종료시점은 넣는다
2) 확실하게 분과 초로 표지 400 - 1min 340sec(x)


#include <stdio.h>

int main()
{
 int N;
 int M = 0;
 int S;
  
 for(;;)
 {
  printf("Input Seconds : ");
  scanf("%d", &N);
 
  if(N >= 60) 
  {
   
   M++;
   while(N>=60)
   {
    M++;
    N = N-60;
   }
   S=N;
      
   printf("Output : %d min %d sec\n", M, S);
   
  }
  else if(N < 0)
  {
   printf("프로그램을 종료합니다!\n");
   break;
  }
  N=0;
 }
 return 0;
}