{"id":3565,"date":"2025-08-02T16:49:36","date_gmt":"2025-08-02T15:49:36","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=3565"},"modified":"2025-08-02T17:32:42","modified_gmt":"2025-08-02T16:32:42","slug":"exercice-formats-printf","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/exercice-formats-printf\/","title":{"rendered":"exercices formats printf"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Exercice 1: les bases<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdio.h>\n#include &lt;stdlib.h>\n\nint main()\n{\n    int age = 25;\n    float taille = 1.75f;\n    char initiale = 'J';\n    char nom[] = \"Dupont\";\n    \n    \/* Question 1.1 *\/\n    printf(\"Nom: __\\n\", nom);\n    \/* Question 1.2 *\/\n    printf(\"Initiale: __\\n\", initiale);\n    \/* Question 1.3 *\/\n    printf(\"Age: __ ans\\n\", age);\n    \/* Question 1.4 *\/\n    printf(\"Taille: __ m\\n\", taille);\n    \n    return EXIT_SUCCESS;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Questions :<\/strong><br>1.1 Compl\u00e9ter avec&nbsp;<code>%s<\/code>&nbsp;pour afficher le nom<br>1.2 Compl\u00e9ter avec&nbsp;<code>%c<\/code>&nbsp;pour l&rsquo;initiale<br>1.3 Compl\u00e9ter avec&nbsp;<code>%d<\/code>&nbsp;pour l&rsquo;\u00e2ge en d\u00e9cimal<br>1.4 Compl\u00e9ter avec&nbsp;<code>%.2f<\/code>&nbsp;pour la taille avec 2 d\u00e9cimales<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>Solution<\/summary>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">printf(\"Nom: %s\\n\", nom);\nprintf(\"Initiale: %c\\n\", initiale);\nprintf(\"Age: %d ans\\n\", age);\nprintf(\"Taille: %.2f m\\n\", taille);<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercice 2 : Notation %d vs %i<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdio.h>\n#include &lt;stdlib.h>\n\nint main()\n{\n    int b = 015;  \/* Octal *\/\n    int c = 0x15; \/* Hexad\u00e9cimal *\/\n    \n    \/* Question 2.1 *\/\n    printf(\"b (octal) avec %%d: __\\n\", b);\n    \/* Question 2.2 *\/\n    printf(\"b (octal) avec %%i: __\\n\", b);\n    \/* Question 2.3 *\/\n    printf(\"c (hexa) avec %%d: __\\n\", c);\n    \n    return EXIT_SUCCESS;\n}<\/pre>\n<\/details>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Questions :<\/strong><br>2.1 Afficher&nbsp;<code>b<\/code>&nbsp;avec&nbsp;<code>%d<\/code>&nbsp;(affiche 13)<br>2.2 Afficher&nbsp;<code>b<\/code>&nbsp;avec&nbsp;<code>%i<\/code>&nbsp;(affiche aussi 13)<br>2.3 Afficher&nbsp;<code>c<\/code>&nbsp;avec&nbsp;<code>%d<\/code>&nbsp;(affiche 21)<\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>Solution<\/summary>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">printf(\"b (octal) avec %%d: %d\\n\", b);\nprintf(\"b (octal) avec %%i: %i\\n\", b);\nprintf(\"c (hexa) avec %%d: %d\\n\", c);<\/pre>\n<\/details>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Exercice 3 : Formatage avanc\u00e9<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdio.h>\n#include &lt;stdlib.h>\n\nint main()\n{\n    double pi = 3.141592653589793;\n    \n    \/* Question 3.1 *\/\n    printf(\"Pi scientifique: __\\n\", pi);\n    \/* Question 3.2 *\/\n    printf(\"Pi 5 decimales: __\\n\", pi);\n    \n    return EXIT_SUCCESS;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Questions :<\/strong><br>3.1 Utiliser&nbsp;<code>%e<\/code>&nbsp;pour la notation scientifique<br>3.2 Utiliser&nbsp;<code>%.5f<\/code>&nbsp;pour 5 d\u00e9cimales<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>Solution:<\/summary>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">printf(\"Pi scientifique: %e\\n\", pi);\nprintf(\"Pi 5 decimales: %.5f\\n\", pi);<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Pi scientifique: 3.141593e+00\nPi 5 decimales: 3.14159<\/code><\/pre>\n<\/details>\n\n\n\n<h2 class=\"wp-block-heading\">Exercice 4 : Alignement texte<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdio.h>\n#include &lt;stdlib.h>\n\nint main()\n{\n    char prenom[] = \"Marie\";\n    \n    \/* Question 4.1 *\/\n    printf(\"Pr\u00e9nom (10c droit) : __\\n\", prenom);\n    \/* Question 4.2 *\/\n    printf(\"Pr\u00e9nom (10c gauche): __\\n\", prenom);\n    \n    return EXIT_SUCCESS;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Questions :<\/strong><br>4.1 Aligner \u00e0 droite avec&nbsp;<code>%10s<\/code><br>4.2 Aligner \u00e0 gauche avec&nbsp;<code>%-10s<\/code><\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>Solution<\/summary>\n<p class=\"wp-block-paragraph\"><\/p>\n<\/details>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">printf(\"Pr\u00e9nom (10c droit): %10s\\n\", prenom);\nprintf(\"Pr\u00e9nom (10c gauche): %-10s\\n\", prenom);<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Pr\u00e9nom (10c droit) :      Marie\nPr\u00e9nom (10c gauche): Marie  \n                     1234567890   <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercice 5 : Format combin\u00e9<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;stdio.h>\n#include &lt;stdlib.h>\n\nint main()\n{\n    int h = 14, m = 5;\n    float temp = 23.7f;\n    \n    \/* Question 5 *\/\n    printf(\"Il est __:__ et il fait __\u00b0C\\n\", h, m, temp);\n    \n    return EXIT_SUCCESS;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>Solution:<\/summary>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">printf(\"Il est %02d:%02d et il fait %.1f\u00b0C\\n\", h, m, temp);<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Il est 14:05 et il fait 23.7\u00b0C<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>D\u00e9tails du formatage :<\/strong><\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Heure (<code>%02d<\/code>)<\/strong>&nbsp;:\n<ul class=\"wp-block-list\">\n<li><code>%02d<\/code>&nbsp;formate le nombre sur&nbsp;<strong>2 chiffres<\/strong>, en ajoutant un&nbsp;<strong>z\u00e9ro devant<\/strong>&nbsp;si n\u00e9cessaire.<\/li>\n\n\n\n<li><code>m = 5<\/code>&nbsp;\u2192 affich\u00e9 comme&nbsp;<code>05<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Minutes (<code>%02d<\/code>)<\/strong>&nbsp;:\n<ul class=\"wp-block-list\">\n<li>M\u00eame principe que pour l&rsquo;heure.<\/li>\n\n\n\n<li><code>h = 14<\/code>&nbsp;\u2192 affich\u00e9 tel quel (d\u00e9j\u00e0 sur 2 chiffres).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Temp\u00e9rature (<code>%.1f<\/code>)<\/strong>&nbsp;:\n<ul class=\"wp-block-list\">\n<li><code>%.1f<\/code>&nbsp;arrondit le flottant \u00e0&nbsp;<strong>1 d\u00e9cimale<\/strong>.<\/li>\n\n\n\n<li><code>temp = 23.7<\/code>&nbsp;\u2192 affich\u00e9 comme&nbsp;<code>23.7<\/code>&nbsp;(pas d&rsquo;arrondi suppl\u00e9mentaire ici).<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<\/details>\n","protected":false},"excerpt":{"rendered":"<p>Exercice 1: les bases Questions :1.1 Compl\u00e9ter avec&nbsp;%s&nbsp;pour afficher le nom1.2 Compl\u00e9ter avec&nbsp;%c&nbsp;pour l&rsquo;initiale1.3 Compl\u00e9ter avec&nbsp;%d&nbsp;pour l&rsquo;\u00e2ge en d\u00e9cimal1.4 Compl\u00e9ter avec&nbsp;%.2f&nbsp;pour la taille avec 2 d\u00e9cimales Questions :2.1 Afficher&nbsp;b&nbsp;avec&nbsp;%d&nbsp;(affiche 13)2.2 Afficher&nbsp;b&nbsp;avec&nbsp;%i&nbsp;(affiche aussi 13)2.3 Afficher&nbsp;c&nbsp;avec&nbsp;%d&nbsp;(affiche 21) Exercice 3 : Formatage avanc\u00e9 Questions :3.1 Utiliser&nbsp;%e&nbsp;pour la notation scientifique3.2 Utiliser&nbsp;%.5f&nbsp;pour 5 d\u00e9cimales Exercice 4 : Alignement texte Questions [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-3565","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/workboot.fr\/ciela\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Exercice 1: les bases Questions :1.1 Compl\u00e9ter avec&nbsp;%s&nbsp;pour afficher le nom1.2 Compl\u00e9ter avec&nbsp;%c&nbsp;pour l&rsquo;initiale1.3 Compl\u00e9ter avec&nbsp;%d&nbsp;pour l&rsquo;\u00e2ge en d\u00e9cimal1.4 Compl\u00e9ter avec&nbsp;%.2f&nbsp;pour la taille avec 2 d\u00e9cimales Questions :2.1 Afficher&nbsp;b&nbsp;avec&nbsp;%d&nbsp;(affiche 13)2.2 Afficher&nbsp;b&nbsp;avec&nbsp;%i&nbsp;(affiche aussi 13)2.3 Afficher&nbsp;c&nbsp;avec&nbsp;%d&nbsp;(affiche 21) Exercice 3 : Formatage avanc\u00e9 Questions :3.1 Utiliser&nbsp;%e&nbsp;pour la notation scientifique3.2 Utiliser&nbsp;%.5f&nbsp;pour 5 d\u00e9cimales Exercice 4 : Alignement texte Questions\u2026","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/comments?post=3565"}],"version-history":[{"count":15,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3565\/revisions"}],"predecessor-version":[{"id":3589,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3565\/revisions\/3589"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=3565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}