Computer Science, asked by SwagnikChakraborty, 2 months ago

Print Even Numbers from the given number (Using c#)
Get any starting number from the user. Print the next 10 even numbers.

Sample Input 1:
Enter starting number : 21

Sample Output 1:
22 24 26 28 30 32 34 36 38 40

Sample Input 2:
Enter starting number : 210

Sample Output 2:
212 214 216 218 220 222 224 226 228 230

Answers

Answered by allysia
2

Language:

C#

Program:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;  

namespace SoloLearn

{ class Program  { static void Main(string[] args)

{             Console.Write("Enter a number: ");

           int num=Convert.ToInt32(Console.ReadLine());

           Console.Write(num);

           Console.WriteLine();

          int n=0;

          while (n<10){

              num=num+1;

              if(num%2==0){

                             Console.Write(num + " ");

                  n=n+1; }  } }} }

Output:

Enter a number: 8

10 12 14 16 18 20 22 24 26 28

Explanation:

  • Take input though type casting.
  • Use integer input with while loop
  • print if the number is divisible by 2.
  • print in the same line using Console.write();

Attachments:

Attachments:
Similar questions