Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cours_prog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
yassin.elhakoun
cours_prog
Commits
da810b2d
Commit
da810b2d
authored
4 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
exemples ajoutés
parent
097ce03e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
exemples/Makefile
+12
-0
12 additions, 0 deletions
exemples/Makefile
exemples/alot_of_scanfs.c
+96
-0
96 additions, 0 deletions
exemples/alot_of_scanfs.c
with
108 additions
and
0 deletions
exemples/Makefile
0 → 100644
+
12
−
0
View file @
da810b2d
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
This diff is collapsed.
Click to expand it.
exemples/alot_of_scanfs.c
0 → 100644
+
96
−
0
View file @
da810b2d
#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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment