aboutsummaryrefslogtreecommitdiff
path: root/semestre 2/informatique/td/2- exemples/boucle.c
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-01-31 15:39:30 +0100
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-01-31 15:39:30 +0100
commitd7c69934248f3fab4988c0d37c11feba25d653b8 (patch)
tree6c396257cb21374e13a26b8f78c05353806220bc /semestre 2/informatique/td/2- exemples/boucle.c
parented631f52ee7af474625e37c6855c7c55903317fc (diff)
Ajout du début du deuxième semestre
Diffstat (limited to 'semestre 2/informatique/td/2- exemples/boucle.c')
-rw-r--r--semestre 2/informatique/td/2- exemples/boucle.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/semestre 2/informatique/td/2- exemples/boucle.c b/semestre 2/informatique/td/2- exemples/boucle.c
new file mode 100644
index 0000000..b582080
--- /dev/null
+++ b/semestre 2/informatique/td/2- exemples/boucle.c
@@ -0,0 +1,25 @@
+#include <assert.h>
+
+int somme_carres_while(int m, int n){
+ int s = 0, i = m;
+ while (i <= n){
+ s += i*i;
+ i++;
+ }
+ return s;
+}
+
+int somme_carres_for(int m, int n){
+ int s = 0;
+ for (int i = m; i <= n; i++){
+ s += i*i;
+ }
+ return s;
+}
+
+int main(){
+ assert(somme_carres_while(0, 5) == somme_carres_for(0, 5));
+ assert(somme_carres_while(3, 5) == somme_carres_for(3, 5));
+ assert(somme_carres_while(15, 25) == somme_carres_for(15, 25));
+ return 0;
+}