SKRIVER UT ÅLDERN ex. 22
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define thisYear 2009
#define thisMonth 03
#define thisDay 20
//* UPPGIFT 1, funktionen räknar ut hur gammal man är*//
int getageinyear(int year[], int month[], int day[]){
int a,b,c;
a=year[0]*1000+year[1]*100+year[2]*10+year[3]; //=1987 (tusental)
b=month[0]*10+month[1]; //=01(tiotal)
c=day[0]*10+day[1]; //=28(tiotal)
a=thisYear-a;
b=thisMonth-b;
c=thisDay-c;
if (b<0) a=a-1;
if (b==0)
if(c<=0) a--;
return a;
}
int main(void){
char *date = "19870128-8949";
char str[30];
int year[4]={1,9,8,7};
int month [2]={0,1};
int day [2]={2,8};
int number[4]={8,9,4,9};
printf("%d \n\n",getageinyear(year, month, day));
getch();
return 0;
}
#include<conio.h>
#include<string.h>
#define thisYear 2009
#define thisMonth 03
#define thisDay 20
//* UPPGIFT 1, funktionen räknar ut hur gammal man är*//
int getageinyear(int year[], int month[], int day[]){
int a,b,c;
a=year[0]*1000+year[1]*100+year[2]*10+year[3]; //=1987 (tusental)
b=month[0]*10+month[1]; //=01(tiotal)
c=day[0]*10+day[1]; //=28(tiotal)
a=thisYear-a;
b=thisMonth-b;
c=thisDay-c;
if (b<0) a=a-1;
if (b==0)
if(c<=0) a--;
return a;
}
int main(void){
char *date = "19870128-8949";
char str[30];
int year[4]={1,9,8,7};
int month [2]={0,1};
int day [2]={2,8};
int number[4]={8,9,4,9};
printf("%d \n\n",getageinyear(year, month, day));
getch();
return 0;
}
Kommentarer
Trackback