Salut !
Toujours sur la route épineuse (pas tant que ca) de l'apprentissage du C#.
J'ai voulu faire quelque exo de pf avant de passer au POO.
Je suis tombé sur le armstrong. (le nom est un peu fort pour ce que ca vaut, certes :/)

je l'ai résolue de la manière suivante
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace ConsoleApplication1
{
 
    class exercice1
    {
        public static void Main(string[] args)
        {
            int x;
            int y;
            int z;
            string text;
            TextWriter tw = new StreamWriter("date.txt");
 
            for (x = 1; x <= 9; x++)
                for (y = 0; y <= 9; y++)
                    for (z = 0; z <= 9; z++)
                    {
                        string i; i = x.ToString();
                        string j; j = y.ToString();
                        string k; k = z.ToString();
 
                        string armstrong = (i + j + k);
                        if ((Math.Pow(x, 3) + (Math.Pow(y, 3)) + (Math.Pow(z, 3))).ToString().Equals(armstrong))
                        {
                            tw.WriteLine(armstrong + "is a armstrong number");
                        }
                        else tw.WriteLine(armstrong + "is not a armstrong number");
 
                    }
 
            tw.Close();
            Console.Read();
 
        }
    }
}

Maintenant ma question,
n y 'aurait-il pas une maniére plus fine ou intelligente pour négocier la condition ?
et si vous avez d'autre remarques sur le code, dite le moi