Skip to content
Snippets Groups Projects
Verified Commit ea6626fd authored by orestis.malaspin's avatar orestis.malaspin
Browse files

date

parent 20a194c7
No related branches found
No related tags found
No related merge requests found
Pipeline #37877 passed
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Ce programme prend en argument deux
// entiers se trouvant chacun
// sur une nouvelle ligne et affiche
// la somme des deux entiers en argument
// sur une nouvelle ligne.
// Ex:
// 12
// 19
//
// 31
void sum_two() {
int a, b;
scanf("%d %d", &a, &b);
printf("\n%d\n", a + b);
}
// Ce programme prend en argument 12 nombres à
// virgule flottante se trouvant chacun
// sur une nouvelle ligne. Multiplie chaque
// nombre par deux et affiche leur somme
// sur une nouvelle ligne suivi de CHF.
// Ex:
// 12.2
// 45.5
// 1.5
// 65.1
// 89.4
// 567.6
// 112.8
// 67.0
// 35.1
// 112.2
// 3.3
// 9.8
//
// 2243.000000 CHF
void sum_array() {
float sum = 0.0;
for (int i = 0; i < 12; ++i) {
float a = 0.0;
scanf("%f", &a);
a *= 2.0;
sum += a;
}
printf("\n%f CHF\n", sum);
}
// Ce programme prend en argument 2 chaînes de
// caractères sur des lignes séparées (longueur
// max de 80), les sépare au milieu et retourne
// les 4 chaînes chacune sur une nouvelle ligne
// (si la longueur N est paire on sépare en 2
// chaînes de longueur N/2, sinon la première
// aura une longueur de N/2 et la seconde N/2+1).
// Ex:
// abcdefgh
// asdfghjkl
//
// abcd
// efgh
// asdf
// ghjkl
void split_mid() {
char str_one[2][41], str_two[2][41];
for (int j = 0; j < 2; ++j) {
char str[81];
scanf("%s", str);
int n = strlen(str);
int n1 = n / 2;
int n2 = n - n1;
for (int i = 0; i < n1; ++i) {
str_one[j][i] = str[i];
}
str_one[j][n1] = '\0';
for (int i = 0; i < n2; ++i) {
str_two[j][i] = str[n1 + i];
}
str_two[j][n2] = '\0';
}
printf("\n");
for (int j = 0; j < 2; ++j) {
printf("%s\n", str_one[j]);
printf("%s\n", str_two[j]);
}
}
int main() {
/* sum_two(); */
sum_array();
/* split_mid(); */
}
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Enter n: "); // affichage chaine de caractères
int n = 0; // déclaration et initialisation de n
scanf("%d", &n); // entrée au clavier
int sum = 0; // déclaration et initialisation de sum
for (int i = 0; i <= n; ++i) { // boucle for
sum += i;
}
printf("The sum of the %d first integers is: %d\n", n, sum); // affichage de n et sum
printf("The analytical formula is %d * (%d + 1) / 2 = %d.\n", n, n, n*(n+1)/2); // on peut mettre n'importe quelle expression
if (sum != n * (n+1) / 2) { // branchement conditionnel
printf("Error: The answer we computed is wrong.\n");
return EXIT_FAILURE; // code d'erreur
}
return EXIT_SUCCESS; // code de réussite
}
\ No newline at end of file
---
title: "Dojo"
date: "2024-02-21"
date: "2025-02-21"
---
# Le Dojo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment