المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : switch case algorithme


gina87
2016-02-15, 19:35
Salem Alaikoum


SVP j'ai besoin de savoir comment ecrir un algorithme en utilisant la structure switch case
Merci

nana47
2016-02-17, 13:08
switch(المتغير الذي نريد ان نعمل عليه test)

case و نكتب الحالة الاولى التي ممكن يكون عليها المتغير
ثم نكتب ما هي الاجراءات التي يجب اتخاذها عند اخذ المتغير هاته القيمة
كل حالة نعملهها كيز التي تخصها
اليك مثال
2 ce code est une fonction(langage C) qui verifie un choix d'entier entre 1 et

void print_cas(int choix)
{
switch (choix)
{

case 1 : printf("tu a choisir le premier choix "); break;
case 2 : printf("tu a choisir le deuxieme choix"); break;

default : printf("tu a choisi un numero faut\n");


}
}

gina87
2016-02-17, 16:27
merci pour votre réponse ; je cherche le switch case en algo pas en code c

nana47
2016-02-17, 16:44
merci pour votre réponse ; je cherche le switch case en algo pas en code c

en algorithmique switch s'ecrit comme des if successive cad chaque choix se represente par un if





{si( choix = 1) alors{ afficher votre choix est le num 1

sinon
{si (choix =2) alors {afficher votre choix est num 2
sinon
afficher erreur
}
sinon

gina87
2016-02-18, 19:16
Merci beaucoup

~عابر سبيل~
2016-02-19, 00:08
السلام عليكم ~


selon choix
case 1 : instruction 1
case2 : instr 2
.
.

case n : instr n.
autre : cas d'erreur ou...