didactics (1)

  • docx
  • 02.05.2020
Публикация на сайте для учителей

Публикация педагогических разработок

Бесплатное участие. Свидетельство автора сразу.
Мгновенные 10 документов в портфолио.

Иконка файла материала didactics (1).docx

In this tutorial I will show how to generate Odd numbers in c#. I have given two example first example is very simple. First example I have used simple for loop to find Odd numbers. Second example I have created a Boolean type function then used the function for finding Odd Numbers. Both the examples check reminder of a number. If the reminder not 0 then the number must be odd number.

 

Generate Odd number in c#

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace OddNumber

{

    class Program

    {

        static void Main()

        {

 

            Console.WriteLine("--First Odd numbers Example--");

 

            for (int i = 0; i <= 20; i++)

            {

                if (i % 2 != 0)

                {

                    Console.WriteLine(i);

                }

             

            }

            Console.WriteLine("--Second  Odd numbers Example--");

            for (int i = 0; i <= 10; i++)

            {

                if (IsOdd(i))

                {

                    Console.WriteLine(i);

                }

            }

 

            Console.ReadLine();

        }

 

        public static bool IsOdd(int value)

        {

            return value % 2 != 0;

        }

      

    }

}

 

 

Out Put

odd_number_c_sharp


 

Посмотрите также