C# Program to print 1,4,7,10,13… series up to N

/* C# Program to print 1,4,7,10,13… series up to N */
using System;
public class Demo
{
    public static void Main(string[] args)
    {
        int a, i;

        Console.WriteLine("Enter Last Number : ");
        a = Convert.ToInt32(Console.ReadLine());
        for(i = 0;i <= a;i++)
        {
            if(i % 3 == 1)
            {
                Console.Write("{0},", i);
            }
        }
        Console.ReadLine();
    }
}

Output :
Enter Last Number : 25
1,4,7,10,13,16,19,22,25,



Leave a comment