kalponikoronno

app

Mar 23rd, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.84 KB | None | 0 0
  1. calender
  2. =========================
  3. #include<stdio.h>
  4.  
  5. #define TRUE    1
  6. #define FALSE   0
  7.  
  8.  
  9.  
  10.  
  11. int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  12. char *months[]=
  13. {
  14.     " ",
  15.     "\n\n\nJanuary",
  16.     "\n\n\nFebruary",
  17.     "\n\n\nMarch",
  18.     "\n\n\nApril",
  19.     "\n\n\nMay",
  20.     "\n\n\nJune",
  21.     "\n\n\nJuly",
  22.     "\n\n\nAugust",
  23.     "\n\n\nSeptember",
  24.     "\n\n\nOctober",
  25.     "\n\n\nNovember",
  26.     "\n\n\nDecember"
  27. };
  28.  
  29.  
  30. int inputyear()
  31. {
  32.     int year;
  33.  
  34.     printf("Please enter a year you want to see the calendar for (example: 2015) : ");
  35.     scanf("%d", &year);
  36.     return year;
  37. }
  38.  
  39.  
  40. int determinedaycode(int year)
  41. {
  42.     int daycode;
  43.     int d1, d2, d3;
  44.  
  45.     d1 = (year - 1.)/ 4.0;
  46.     d2 = (year - 1.)/ 100.;
  47.     d3 = (year - 1.)/ 400.;
  48.     daycode = (year + d1 - d2 + d3) %7;
  49.     return daycode;
  50. }
  51.  
  52.  
  53. int determineleapyear(int year){
  54.     if(year% 4 == FALSE && year%100 != FALSE || year%400 == FALSE)
  55.     {
  56.         days_in_month[2] = 29;
  57.         return TRUE;
  58.     }
  59.     else
  60.     {
  61.         days_in_month[2] = 28;
  62.         return FALSE;
  63.     }
  64. }
  65.  
  66. calendar(int year, int daycode){
  67.  
  68.     int month, day;
  69.  
  70.     for ( month = 1; month <= 12; month++ )
  71.     {
  72.         printf("%s", months[month]);
  73.         printf("\n\nSun  Mon  Tue  Wed  Thu  Fri  Sat\n" );
  74.  
  75.  
  76.         for ( day = 1; day <= 1 + daycode * 5; day++ )
  77.         {
  78.             printf(" ");
  79.         }
  80.  
  81.  
  82.         for ( day = 1; day <= days_in_month[month]; day++ )
  83.         {
  84.             printf("%2d", day );
  85.  
  86.  
  87.             if ( ( day + daycode ) % 7 > 0 )
  88.                 printf("   " );
  89.             else
  90.                 printf("\n " );
  91.         }
  92.  
  93.             daycode = ( daycode + days_in_month[month] ) % 7;
  94.     }
  95. }
  96.  
  97.  
  98. int main()
  99. {
  100.     int year, daycode, leapyear;
  101.  
  102.     year = inputyear();
  103.     daycode = determinedaycode(year);
  104.     determineleapyear(year);
  105.     calendar(year, daycode);
  106.     printf("\n");
  107.  
  108.  
  109.  
  110. }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. calculator
  128. =======================
  129. #include<stdio.h>
  130.  
  131.  
  132. int sum(int a,int b){int sum=a+b;
  133. return sum;
  134. }
  135. int sub(int a,int b){
  136. int sub=a-b;
  137. return sub;
  138. }
  139. int mul(int a,int b){
  140. int mul=a*b;
  141. return mul;
  142. }
  143. int div(int a,int b){
  144. int div=a/b;
  145. return div;
  146. }
  147. int mod(int a,int b){
  148. int mod=a%b;
  149. return mod;
  150. }
  151. int sqrr(int a){
  152. int sqrr=a*a;
  153. return sqrr;
  154. }
  155. double squareroot(int a){
  156. double squareroot= sqrt(a);
  157. return squareroot;
  158. }
  159.  
  160. int main(){
  161.     float x,y,s,su,m,d,r,sq,sqr,q,v;
  162.     do{
  163.     printf("Calculate something: \n1=+\n2=-\n3=*\n4=/\n5=%%\n6=square\n7=square root\n");
  164.     scanf("%f",&q);
  165.     printf("Enter your number :\n");
  166.     scanf("%f",&x);
  167.     if(q==1||q==2||q==3||q==4||q==5){
  168.     printf("Enter your second number :\n");
  169.     scanf("%f",&y);
  170.     }
  171.  
  172.     if(q==1){
  173.         s=sum(x,y);
  174.         printf("Sum is : %.2f\n",s);
  175.     }else if(q==2){
  176.         su=sub(x,y);
  177.         printf("Sub is : %.2f\n",su);
  178.     }else if(q==3){
  179.         m=mul(x,y);
  180.         printf("mul is : %.2f\n",m);
  181.     }else if(q==4){
  182.         d=div(x,y);
  183.         printf("Div is :%.2f\n",d);
  184.     }else if(q==5){
  185.         r=mod(x,y);
  186.         printf("Remainder is : %.2f\n",r);
  187.     }
  188.  
  189.  
  190.     if(q==6){
  191.         sq=sqrr(x);
  192.         printf("Square is : %f\n",sq);
  193.     }else if(q==7){
  194.         sqr=squareroot(x);
  195.         printf("Square root is : %f\n",sqr);
  196.     }
  197.  
  198.     printf("want to calculate again?\n press 1 for yes and 2 for no");
  199.     scanf("%f",&v);
  200.     }
  201.     while(v==1);
  202.  
  203.     return 0;
  204. }
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222. countdown timer
  223. ==============================
  224.  
  225. #include <stdio.h>
  226. #include <time.h>
  227.  
  228. int sec_wait ( int sec ) {
  229.  
  230.  
  231.         clock_t wait_till_end;
  232.  
  233.  
  234.  
  235.  
  236.         wait_till_end = clock () + sec * CLOCKS_PER_SEC ;
  237.  
  238.  
  239.  
  240.         while (clock() < wait_till_end) {}
  241.  
  242.  
  243.  
  244. }
  245.  
  246.  
  247.  
  248. int main () {
  249.         int i;
  250.         printf ("Starting countdown...\n");
  251.         for (i=60; i>0; i--) {
  252.                  printf ("%d\n",i);
  253.                  sec_wait (1);
  254.                  if ( i == 3 )
  255.                         printf ("Engine started...\n");
  256.         }
  257.        printf ("and lift off....\n");
  258.        return 0;
  259. }
Advertisement
Add Comment
Please, Sign In to add comment