using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Exemple5_1_P74 { class Program { static void Main(string[] args) { /*Énoncé Écrir une adaptation du premier exemple du carré, de façon qu’il puisse exploiter l'indice à l’intérieur de la boucle,. */ //Solution avec doWhile //Déclaration des variables //int nombre,i=0; //do //{ // Console.Write("Donnez-moi le nombre : "); // //Lécture du nombre // nombre = int.Parse(Console.ReadLine()); // if (nombre != 0) // { // Console.Write("Le carré : " + nombre * nombre + "\n"); // i = i + 1; // } //} //while (nombre != 0); //Console.Write("Vous avez calculé "+i+" carré(s)"); //solution avec While int nombre, i = 0; Console.Write("Donnez-moi le nombre : "); //Lécture du nombre nombre = int.Parse(Console.ReadLine()); while (nombre != 0) { if (nombre != 0) { i = i + 1; if (i == 1) { Console.Write("\nLe carré du " + i + " er nombre: " + nombre * nombre + "\n"); } else { Console.Write("\nLe carré du " + i + " ème nombre: " + nombre * nombre + "\n"); } } Console.Write("Donnez-moi le nombre : "); //Lécture du nombre nombre = int.Parse(Console.ReadLine()); } Console.Write("\nVous avez calculé " + i + " carré(s)"); Console.Write("\nBay Bay"); Console.Read(); } } }