Skip to content
Loading
+1
  • Midhun Tp
    0
    Hi,
    Try this code -
    for (int i = 1; i < 10; i++)
    {
    if (i % 3 != 0)
    Console.WriteLine(i);
    else
    Console.WriteLine("a");
    }
    0
  • 0
    Hi Lee,
    Use modulo operator for number position like,
    class Program
    {
    static void Main()
    {
    int position = 3;
    string importCharacter = "a";
    int n = 9;
    for (int i = 1; i <=n; i++)
    {
    if (i % position != 0)
    Console.WriteLine(i);
    else
    Console.WriteLine(importCharacter);
    }
    Console.ReadLine();
    }
    }
    0
  • Tapan Patel
    0
    Here is how you can do using Linq.
    1. Enumerable.Range(1,10).ToList().ForEach(i=>{if(i%3==0) Console.WriteLine('a');else Console.WriteLine(i);});
    Please mark it as an answer if it addresses the issue.
    0
  • 0
    Hi,
    Try this
    for(int i=1;i<=9;i++)
    {
       if (i % 3 == 0)
          Response.Write("a");
       else
          Response.Write(i);
       Response.Write("
    ");
    }
    0
  • Bikesh Srivastava
    0
    Hi,
    Its working fine.
    1. usingSystem;
    2. usingSystem.Collections.Generic;
    3. usingSystem.Linq;
    4. usingSystem.Text;
    5. usingSystem.Threading.Tasks;
    6. namespaceConsoleApplication1
    7. {
    8. usingSystem;
    9. usingSystem.Collections.Generic;
    10. usingSystem.Linq;
    11. usingSystem.Text;
    12. namespaceRohit_Test
    13. {
    14. classProgram
    15. {
    16. staticvoidMain()
    17. {
    18. intposition=3;
    19. stringimportCharacter="a";
    20. intn=9;
    21. for(inti=1;i<=n;i++)
    22. {
    23. if(i%position!=0)
    24. Console.WriteLine(i);
    25. else
    26. Console.WriteLine(importCharacter);
    27. }
    28. Console.ReadLine();
    29. }
    30. }
    31. }
    32. }
    0
  • 0
    thanks
    0