Профил
Loading...
delor avatar delor -3 Точки

Проблем с по-сложни цикли с++

Здравейте, на следните задачи като ги реша джъджа ми дава грешка може ли да ми погнете

11.Enter Even Number

using System;

namespace Greatest_Common_Divisor
{
    class greatestCommonDivisor
    {
        static void Main(string[] args)
        {
            int num1 = int.Parse(Console.ReadLine());
            int num2 = int.Parse(Console.ReadLine());

            while (num2 != 0)
            {
                int oldNum2 = num2;
                num2 = num1 % num2;
                num1 = oldNum2;
            }
            Console.WriteLine(num1);
        }
    }
}

12. Fibonacci

using System;

namespace Fibonacci
{
    class fibonacci
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            if (n < 2)
            {
                Console.WriteLine("1");
                return;
            }

            int fibNum1 = 1;
            int fibNum2 = 1;
            int fibNumNext = 0;

            for (int i = 0; i < n - 1; i++)
            {
                fibNumNext = fibNum1 + fibNum2;

                fibNum1 = fibNum2;
                fibNum2 = fibNumNext;
            }

            Console.WriteLine(fibNumNext);
        }
    }
}

 

13. Number Pyramid

using System;

namespace Number_Pyramid
{
    class numPyramid
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int num = 1;
            for (int row = 1; row <= n; row++)
            {
                for (int col = 1; col <= row; col++)
                {
                    Console.Write($"{num} ");
                    num++;
                    if (num > n)
                    {
                        break;
                    }
                }
                Console.WriteLine();
                if (num > n)
                {
                    break;
                }
            }
        }
    }
}

 

14. Number Table

using System;

namespace numTable
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int num = 0;

            for (int row = 0; row < n; row++)
            {
                for (int col = 0; col < n; col++)
                {
                    num = row + col + 1;
                    if (num > n)
                    {
                        num = 2 * n - num;
                    }
                    Console.Write($"{num} ");
                }
                Console.WriteLine();
            }
        }
    }
}

07. Greatest Common Divisor (CGD)

using System;

namespace Greatest_Common_Divisor
{
    class greatestCommonDivisor
    {
        static void Main(string[] args)
        {
            int num1 = int.Parse(Console.ReadLine());
            int num2 = int.Parse(Console.ReadLine());

            while (num2 != 0)
            {
                int oldNum2 = num2;
                num2 = num1 % num2;
                num1 = oldNum2;
            }
            Console.WriteLine(num1);
        }
    }
}

 

 

donsavage avatar donsavage 4 Точки

Това не е C++, а C# има огромна разлика

0