Écrire un programme qui demande deux nombres m et n à l’utilisateur et l’informe ensuite si le produit de ces deux nombres est positif ou négatif. On inclut dans le programme le cas où le produit peut être nul.
******** En Algorithme ********
Algorithme Variables m,n:réels Debut Ecrire(" Entrer un nombre:") Lire(m) Ecrire(" Entrer un nombre:") Lire(n) Si( n == 0 ou m == 0) alors Ecrire("Le produit est nul!!") FinSi Si( m*n < 0) alors Ecrire("Le produit est négatif") FinSi Si( m*n > 0) alors Ecrire("Le produit est positif") FinSi Fin Résultat ==> Entrer un nombre: -7.4 Entrer un nombre: 2 Le produit est négatif
Retour vers la liste d'exercices
******** En C ********
#include <stdio.h> int main() { float m,n ; printf(" Entrer un nombre:"); scanf("%f",&m); printf(" Entrer un nombre:"); scanf("%f",&n); if( n == 0 || m == 0) printf("le produit est nul!!"); if ( m*n < 0) printf("le produit est negatif" ); if ( m*n > 0) printf("le produit est positif" ); return 0; }
Retour vers la liste d'exercices
******** En C++ ********
#include <iostream>
using namespace std;
int main() {
float m,n ;
cout<<" Entrer un nombre:"; cin>>m;
cout<<" Entrer un nombre:"; cin>>n;
if( n == 0 || m == 0)
cout<<"Le produit est nul!!";
if ( m*n < 0)
cout<<"Le produit est negatif";
if ( m*n > 0)
cout<<"Le produit est positif";
return 0;
}
******** En Python ********
******** En Python ********
A = float(input("Entrer un Entier A:"))
B = float(input("Entrer un Entier B:"))
if A*B < 0 :
print("Le produit de",A,"et",B,"est négatif")
elif A*B > 0:
print("Le produit de",A,"et",B,"est positif")
else :
print("Le produit de",A,"et",B,"est nul ")
******** En JAVA ********
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("Entrer la note :");
int m = sc.nextInt();
System.out.print("Entrer la note :");
int n = sc.nextInt();
if( n == 0 || m == 0)
System.out.print("le produit est nul!!");
if ( m*n < 0)
System.out.print("le produit est negatif" );
if ( m*n > 0)
System.out.print("le produit est positif" );
}
}
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.print("Entrer la note :");
int m = sc.nextInt();
System.out.print("Entrer la note :");
int n = sc.nextInt();
if( n == 0 || m == 0)
System.out.print("le produit est nul!!");
if ( m*n < 0)
System.out.print("le produit est negatif" );
if ( m*n > 0)
System.out.print("le produit est positif" );
}
}
********* En C# *******
using System;
public class Ex7 {
public static void Main(string[] args)
{ float m,n;
Console.Write("Entrer m:");
m=float.Parse(System.Console.ReadLine());
Console.Write("Entrer n:");
n=float.Parse(System.Console.ReadLine());
if (n*m <0 )
Console.WriteLine ("le produit est negatif");
if (n*m>0)
Console.WriteLine ("le produit est positif");
if (n*m==0)
Console.WriteLine ("le produit est nul");
}
}
using System;
public class Ex7 {
public static void Main(string[] args)
{ float m,n;
Console.Write("Entrer m:");
m=float.Parse(System.Console.ReadLine());
Console.Write("Entrer n:");
n=float.Parse(System.Console.ReadLine());
if (n*m <0 )
Console.WriteLine ("le produit est negatif");
if (n*m>0)
Console.WriteLine ("le produit est positif");
if (n*m==0)
Console.WriteLine ("le produit est nul");
}
}
0 Commentaires