static int SaisiePositive()
Console.WriteLine("Entrez un nombre strictement positif");
n = int.Parse(Console.ReadLine());
static bool EstStrictementPositif(int nombre)
static bool EstBissextile(int annee)
return (annee % 4 == 0 && annee % 100 != 0) || annee % 400 == 0;
static void TestAnneeBissextile()
Console.WriteLine("Saisir une année ou 'stop' pour arrêter");
entree = Console.ReadLine();
while (entree.ToLower() != "stop")
if (int.TryParse(entree, out annee))
if (EstBissextile(annee))
Console.WriteLine($"{annee} est bissextile");
Console.WriteLine($"{annee} n'est pas bissextile");
Console.WriteLine("Veuillez saisir une année valide.");
Console.WriteLine("Saisir une autre année ou 'stop' pour arrêter");
entree = Console.ReadLine();
static int SommeElements(int a, int b)
for (int i = a; i <= b; i++)
int a = SaisiePositive();
int b = SaisiePositive();
int s = SommeElements(a, b);
Console.WriteLine($"La somme des nombres de {a} jusqu'à {b} est {s}");
static int EstPlusGrand(int val1, int val2)
static int Factorielle(int value)
for (int i=value-1; i>1;i--)
static int NombreOccurences(string s, char c)
for (int i = 0; i < s.Length; i++)
static bool EstPresent(string s, char c)
return NombreOccurences(s, c) > 0;
static bool EstPresent2(string s, char c)
for (int i = 0; i < s.Length && !present; i++)
static bool EstPremier(int value)
for(int i = 0; i*i<value; i++)
static bool EstPair(int value)
bool resultat = (value%2==0);
static int PosNeg(int nb, int nb2)
if (nombre1<0 && nombre2>0)
int PlusieursPremiers(int debut, int fin, bool affiche)
for (int i = debut; i <= fin; i++)
if (affiche) Console.WriteLine(i);
bool EstPalindrome(string s)
string reverse = new string(s.Reverse().ToArray());
Console.Write("Entrez une chaîne : ");
string s = Console.ReadLine();
Console.WriteLine(EstPalindrome(s) ? "C'est un palindrome." : "Ce n'est pas un palindrome.");
bool EstContenu(string s1, string s2) => s1.Contains(s2);
Console.Write("Entrez la première chaîne : ");
string s1 = Console.ReadLine();
Console.Write("Entrez la deuxième chaîne : ");
string s2 = Console.ReadLine();
Console.WriteLine(EstContenu(s1, s2) ? "s2 est contenu dans s1." : "s2 n'est pas contenu dans s1.");
bool Debut(string s1, string s2)
if (string.IsNullOrEmpty(s1) || string.IsNullOrEmpty(s2)) return false;
return char.ToLower(s1[0]) == char.ToLower(s2[0]);
Console.Write("Entrez la première chaîne : ");
string s1 = Console.ReadLine();
Console.Write("Entrez la deuxième chaîne : ");
string s2 = Console.ReadLine();
Console.WriteLine(Debut(s1, s2) ? "Les deux chaînes commencent par la même lettre." : "Les lettres sont différentes.");
string SousChaine(string s, int debut, int longueur)
if (debut < 0 || debut >= s.Length) return "";
if (debut + longueur > s.Length) longueur = s.Length - debut;
return s.Substring(debut, longueur);
Console.Write("Entrez une chaîne : ");
string s = Console.ReadLine();
Console.WriteLine("Sous-chaîne : " + SousChaine(s, 0, 10));
bool TailleEgale(string s1, string s2) => s1.Length == s2.Length;
Console.Write("Entrez la première chaîne : ");
string s1 = Console.ReadLine();
Console.Write("Entrez la deuxième chaîne : ");
string s2 = Console.ReadLine();
Console.WriteLine(TailleEgale(s1, s2) ? "Les chaînes ont la même taille." : "Les chaînes n'ont pas la même taille.");
public static void Main()