suryawarior44

tgl char

Nov 17th, 2020
673
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. void main(){
  4.     char tgl1[8] ={0, 0, 0, 0, 0, 0, 0, 0} ;
  5.     char tgl2[8] ={0, 0, 0, 0, 0, 0, 0, 0} ;
  6.     printf("Tanggal Pertama :");
  7.     scanf("%s", &tgl1);
  8.     printf("Tanggal Kedua   :");
  9.     scanf("%s", &tgl2);
  10.  
  11.     int hari1  = (tgl1[0] - '0') * 10 + tgl1[1] - '0';
  12.     int bulan1 = (tgl1[3] - '0') * 10 + tgl1[4] - '0';
  13.     int tahun1 = (tgl1[6] - '0') * 10 + tgl1[7] - '0';
  14.  
  15.    
  16.     int hari2  = (tgl2[0] - '0') * 10 + tgl2[1] - '0';
  17.     int bulan2 = (tgl2[3] - '0') * 10 + tgl2[4] - '0';
  18.     int tahun2 = (tgl2[6] - '0') * 10 + tgl2[7] - '0';
  19.    
  20.     //printf("\n%d %d %d \n", hari1, bulan1, tahun1);
  21.     //printf("\n%d %d %d \n", hari2, bulan2, tahun2);
  22.  
  23.     int total1 = hari1 + (bulan1 * 30) + (tahun1 * 365);
  24.     int total2 = hari2 + (bulan2 * 30) + (tahun2 * 365);
  25.    
  26.     int total;
  27.     if(total1>total2){
  28.         total= total1 - total2;
  29.     } else {
  30.         total=total2 - total1;
  31.     }
  32.    
  33.     printf("Jarak Hari : %d", total);
  34. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×