Différences entre les versions de « Modèle:Code »
De Wikip
m (1 version) |
|||
Ligne 1 : | Ligne 1 : | ||
<includeonly> | <includeonly>{{#tag:syntaxhighlight|{{{code|}}}|lang={{{lang|text}}}}}</includeonly><noinclude> | ||
{{#tag:syntaxhighlight|{{{code|}}}|lang={{{lang|text}}} }}</includeonly><noinclude> | |||
{{Model | {{Model | ||
|class=lang | |class=lang | ||
Ligne 14 : | Ligne 13 : | ||
Exemple : | Exemple : | ||
<nowiki>{{code|lang=cpp|code= | <nowiki>{{code|lang=cpp|code= | ||
#include <time.h> | #include <time.h> | ||
#include <stdio.h> | #include <stdio.h> | ||
void sleep( time_t nb_sec ) | void sleep( time_t nb_sec ) | ||
{ | { | ||
time_t limit, top; | time_t limit, top; time(&top); limit = top + nb_sec ; | ||
while (top < limit) | while (top < limit) | ||
{ | { | ||
Ligne 29 : | Ligne 26 : | ||
int main( int argc, char * argv[] ) | int main( int argc, char * argv[] ) | ||
{ | { | ||
time_t start, stop; | time_t start, stop; time(&start); sleep( 5 ) ; time(&stop); printf("start : %ld\n",start ); printf("stop : %ld\n",stop ); printf("in seconds: %f\n",difftime(stop,start)); | ||
} | } | ||
}}</nowiki> | }}</nowiki> | ||
Ligne 46 : | Ligne 37 : | ||
void sleep( time_t nb_sec ) | void sleep( time_t nb_sec ) | ||
{ | { | ||
time_t limit, top; | time_t limit, top; time(&top); limit = top + nb_sec ; | ||
while (top < limit) | while (top < limit) | ||
{ | { | ||
Ligne 56 : | Ligne 45 : | ||
int main( int argc, char * argv[] ) | int main( int argc, char * argv[] ) | ||
{ | { | ||
time_t start, stop; | time_t start, stop; time(&start); sleep( 5 ) ; time(&stop); printf("start : %ld\n",start ); printf("stop : %ld\n",stop ); printf("in seconds: %f\n",difftime(stop,start)); | ||
} | } | ||
}} | }} | ||
</noinclude> | </noinclude> |
Version du 2 novembre 2014 à 09:52
Version : 1.36.1 1047 (2014-11-2) 20141102095201
Auteurs :
Arthur Torossian
Résumé :
Ce modèle sert présenter un code programmation.
{{code|lang=|code=}}
- lang=
- c++ php …
- code=
- le code
Exemple :
{{code|lang=cpp|code= #include <time.h> #include <stdio.h> void sleep( time_t nb_sec ) { time_t limit, top; time(&top); limit = top + nb_sec ; while (top < limit) { time(&top); } }; int main( int argc, char * argv[] ) { time_t start, stop; time(&start); sleep( 5 ) ; time(&stop); printf("start : %ld\n",start ); printf("stop : %ld\n",stop ); printf("in seconds: %f\n",difftime(stop,start)); } }}
donnera :
#include <time.h>
#include <stdio.h>
void sleep( time_t nb_sec )
{
time_t limit, top; time(&top); limit = top + nb_sec ;
while (top < limit)
{
time(&top);
}
};
int main( int argc, char * argv[] )
{
time_t start, stop; time(&start); sleep( 5 ) ; time(&stop); printf("start : %ld\n",start ); printf("stop : %ld\n",stop ); printf("in seconds: %f\n",difftime(stop,start));
}