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

exemples ajoutés

parent 097ce03e
Branches
No related tags found
No related merge requests found
CC=gcc
OPTIONS=-Wall -Wextra -pedantic -fsanitize=address
LIBS=-fsanitize=address -lm
alot_of_scanfs: alot_of_scanfs.o
$(CC) -o $@ $< $(LIBS)
alot_of_scanfs.o: alot_of_scanfs.c
$(CC) -c $^ $(OPTIONS)
clean:
rm -f *.o alot_of_scanfs
#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();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment