TP n° 01: Révisions sur les Variables

ère
I.U.T. Marseille / Dép. Mesures Physiques / TP d’Informatique 1
Année
AFaire du TP n° 01 - 2 page(s)
TP n° 01: Révisions sur les Variables - Structures Conditionnelles (1).
Programmes 1: Code correspondant à l’exercice 2.
Visual Basic
Langage C
Option Explicit
#include <stdio.h>
Private Sub pgr05()
Dim a&, b&, d!, aff$
a = CLng(Val(InputBox("Entrez un entier", "Entrez a", 10)))
b = CLng(Val(InputBox("Entrez un entier", "Entrez b", 5)))
If (b = 0&) Then
aff = "Divison par zero"
Else
d = CSng(a) / CSng(b)
aff = CStr(a) & " / " & CStr(b) & " = " & Format(d, "0.0###")
End If
Call MsgBox(aff)
End Sub
void main(void)
{
long a,b;
float d;
printf("Entrez un entier: ");
scanf("%li", &a);
printf("Entrez un entier: ");
scanf("%li", &b);
If (b == 0)
{
printf("Divison par zero");
}
Else
{
d = (float)a / (float)b;
Printf(“%li / %li = %f“,a,b,d) ;
}
}
Complétez le tableau suivant :
Question
Délimitation d’un programme
Déclaration d’un entier long
Déclaration d’un réel simple
Saisie d’un entier
Instruction de test « Oui/Non »
Visual Basic
Langage C
Conversion en réel
Version 02
Erick LAZARIDÈS ©.
1 / 6
ère
I.U.T. Marseille / Dép. Mesures Physiques / TP d’Informatique 1
Année
AFaire du TP n° 01 - 2 page(s)
Programmes 2: Code correspondant à l’exercice 5.
Visual Basic
Langage C
Option Explicit
#include <stdio.h>
Private Sub Prog06()
Dim coul As String, aff$
coul = InputBox("Entrez l'initiale de la couleur")
Select Case coul
Case "R", “r”
aff = "L'initiale est celle du Rouge"
Case "J", "j"
aff = "L'initiale est celle du Jaune"
Case Chr(66), Chr(98)
aff = "L'initiale est celle du Bleu"
Case Else
aff = "Mauvaise frappe"
End Select
Call MsgBox(aff)
End Sub
void main(void)
{
char coul;
printf("Entrez l'initiale de la couleur");
scanf("%c",&coul);
switch(coul)
{
case ‘R’:
case ‘r’:
printf("\n L'initiale est celle du Rouge");
break;
case ‘J’:
case ‘j’:
printf("\n L'initiale est celle du Jaune");
break;
case ‘B’:
case ‘b’:
printf("\n L'initiale est celle du Bleu");
break;
default: printf("\n Mauvaise frappe");
}
}
Complétez le tableau suivant :
Question
Déclaration d’une chaine
Saisie d’une chaîne
Visual Basic
Langage C
Instruction de test multiple
Version 02
Erick LAZARIDÈS ©.
2 / 6
ère
I.U.T. Marseille / Dépt Mesures Physiques / TP d’Informatique 1
Année
AFaire du TP n° 02
TP n° 02: Structures Conditionnelles (2). - Structures Répétitives (1).
Programmes : Code correspondant a l’exercice 2.
Visual Basic
Langage C
Option Explicit
#include <stdio.h>
Private Sub pgr02a()
Dim a&, b&, d!, aff$
a = CLng(Val(InputBox("Entrez un entier", "Entrez a", 10)))
Do
b = CLng(Val(InputBox("Entrez un entier", "Entrez b", 5)))
Loop While (b = 0)
d = CSng(a) / CSng(b)
aff = CStr(a) & " / " & CStr(b) & " = " & Format(d, "0.0###")
Call MsgBox(aff, vbInformation + vbYesNoCancel + vbDefaultButton2,
"Exercice 2")
End Sub
void main(void)
{
long a,b;
float d;
printf("Entrez un entier: ");
scanf("%li", &a);
do
{
printf("Entrez un entier non nul: ");
scanf("%li", &b);
}while (b==0);
d = (float)a / (float)b;
Printf(“la division de %li par %li = %f“;a,b,d) ;
}
#include <stdio.h>
Option Explicit
Private Sub pgr02b()
Dim a&, b&, d!, aff$
a = CLng(Val(InputBox("Entrez un entier", "Entrez a", 10)))
b = CLng(Val(InputBox("Entrez un entier", "Entrez b", 5)))
While (b = 0)
b = CLng(Val(InputBox("vous avez rentré un entier nul, autre valeur",
"Entrez b", 5)))
Wend
d = CSng(a) / CSng(b)
aff = CStr(a) & " / " & CStr(b) & " = " & Format(d, "0.0###")
Call MsgBox(aff, vbInformation + vbYesNoCancel + vbDefaultButton2,
"Exercice 2")
End Sub
Version 02
void main(void)
{
long a,b;
float d;
printf("Entrez un entier: ");
scanf("%li", &a);
printf("Entrez un entier non nul: ");
scanf("%li", &b);
While (b==0)
{
printf("vous avez rentré un entier nul, autre valeur: ");
scanf("%li", &b);
}
d = (float)a / (float)b;
Printf(“la division de %li par %li = %f“;a,b,d) ;
}
Erick LAZARIDÈS ©.
3 / 6
ère
I.U.T. Marseille / Dépt Mesures Physiques / TP d’Informatique 1
Année
AFaire du TP n° 02
Complétez le tableau suivant :
Question
Action de « Option Explicit »
Action de « #include <stdio.h> »
Délimitation d’un programme
Délimitation d’une ligne
Déclaration d’un entier long
Déclaration d’un réel simple
Saisie d’un entier
Instruction de boucle (test en début)
Instruction de boucle (test en fin)
Conversion en réel
Version 02
Visual Basic
Langage C
Erick LAZARIDÈS ©.
4 / 6
ère
I.U.T. Marseille / Dépt Mesures Physiques / TP d’Informatique 1
Année
AFaire du TP n° 03
TP n° 3: Structure Répétitives (2) - Tableaux.
Programmes 1: Traduisez en C le Code suivant :
Visual Basic
Option Explicit
Private Sub pgr01()
Dim aff$
Dim n%
Dim r!
n = CInt(InputBox("Entrez un entier", "Saisie"))
If (n > 0) Then
r = Sqr(n)
aff = "La racine carrée de " & Str(n) & " est " & Format(r, "0.00##")
Else
If (n = 0) Then
aff = "L'entier est nul"
Else
r = CSng(n) * CSng(n)
aff = "Le carré de " & Str(n) & " est " & Format(r, "0.00##")
End If
End If
Call MsgBox(aff)
End Sub
Version 02
Erick LAZARIDÈS ©.
5 / 6
ère
I.U.T. Marseille / Dépt Mesures Physiques / TP d’Informatique 1
Année
AFaire du TP n° 03
Programmes 2: Traduisez en C le Code suivant :
Visual Basic
Option Explicit
Private Sub pgr04()
Dim n%, m%
Dim i%, c%, af$
Do
n = CInt(InputBox("Entrez le premier entier"))
Loop While (n < 0)
Do
m = CInt(InputBox("Entrez le deuxième entier"))
Loop While (m < n)
af = ""
For i = n To m Step 1
c = i ^ 3
af = af & "Le cube de " & Str$(i) & " vaut " & Str(c) & VbCr
Next i
Call MsgBox(af)
End Sub
Version 02
Erick LAZARIDÈS ©.
6 / 6