Advertisement
lpuarmy

Soal 6 Struct 1

Jan 4th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. int kab (int);
  5.  
  6. struct date {
  7. int tgl, bln, thn;
  8. };
  9.  
  10. main() {
  11. struct date today;
  12. struct date tomorrow;
  13. int bln[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
  14.  
  15. puts("========== PERCOBAAN 6 PRAKTIKUM STRUCT 1 ==========\n");
  16. printf("Masukkan tanggal : "); scanf("%d", &today.tgl);
  17. printf("Masukkan bulan : "); scanf("%d", &today.bln);
  18. printf("Masukkan tahun : "); scanf("%d", &today.thn);
  19.  
  20. if(kab(today.thn))
  21. bln[2] = 29;
  22.  
  23. tomorrow.tgl = today.tgl+1;
  24. tomorrow.bln = today.bln;
  25. tomorrow.thn = today.thn;
  26.  
  27. while(tomorrow.tgl > bln[tomorrow.bln]) {
  28. tomorrow.tgl -= bln[tomorrow.bln];
  29. tomorrow.bln += 1;
  30. if(tomorrow.bln > 12) {
  31. tomorrow.bln = 1;
  32. tomorrow.thn += 1;
  33. }
  34. }
  35.  
  36. puts("----------------------------------------------------");
  37. printf("Today : \nTanggal : %d\n", today.tgl);
  38. printf("Bulan : %d\n", today.bln);
  39. printf("Tahun : %d\n\n", today.thn);
  40.  
  41. printf("Tomorrow : \nTanggal : %d\n", tomorrow.tgl);
  42. printf("Bulan : %d\n", tomorrow.bln);
  43. printf("Tahun : %d\n", tomorrow.thn);
  44.  
  45. getch();
  46. return 0;
  47. }
  48.  
  49. int kab (int x) {
  50. int a;
  51. if(x % 400 == 0)
  52. a = 1;
  53. else if(x % 100 == 0)
  54. a = 0;
  55. else if(x % 4 == 0)
  56. a = 1;
  57. else
  58. a = 0;
  59.  
  60. return (a);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement