---++ Anno Bisestile Lanno bisestile è lanno durante il quale viene aggiunto un giorno extra nel mese di Febbraio. Lanno bisestile è ogni anno che sia divisibile per 400 o divisibile per 4 ma non divisibile per 100. Ad esempio, lanno 1996 è un anno bisestile in quanto divisibile per 4 ma non divisibile per 100. Il 1700, il 1800, il 1900 non sono bisestili, mentre il 1600 e il 2000 sono anni bisestili in quanto divisibili per 400. --- * <b>Codice in C</b> <PRE style="background: lightgrey;"> <verbatim> #include <stdio.h> int main() { /* la variabile in cui inseriremo l'anno */ int year; /* legge da stdin l'anno */ scanf("%d", &year); /* come abbiamo detto, per vedere se l'anno e' bisestile facciamo * le divisioni per 4, 100, 400, ma delle divisioni non prenderemo * il quoziente, ma bensi' il resto, infatti useremo "year % 4" (% = modulo) * In una divisione, per vedere se un numero intero e' divisibile * per un altro, dobbiamo guardare se il resto e' uguale a 0 e * ignorare il quoziente. Il seguente test(if) fa in modo che: * "se year e' divisibile per 4 e non e' divisibile per 100 oppure, * e' divisibile per 400, stampa "bisestile" altrimenti, stampa * "non bisestile" */ if((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) printf("bisestile\n"); else printf("non bisestile\n"); return 0; } </verbatim> </pre> -- Users.MarcoEsposito - 15 Nov 2002 * [[%ATTACHURL%/annobis.c][annobis.c]]: Programma di esempio
Attachments
Attachments
Topic attachments
I
Attachment
History
Action
Size
Date
Who
Comment
c
annobis.c
r1
manage
0.9 K
2002-11-15 - 22:45
MarcoEsposito
Programma di esempio
This topic: Programmazione1/AA0506/PZ
>
WebHome
>
AppuntiEsercitazioni2002
>
AnnoBisestile
Topic revision: r3 - 2003-10-04 - AndreaSterbini
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback