Friday 1 December 2017

C# Program to Negate the Positive Elements of Array


Code:

using System;
using System.Collections.Generic;
using System.Text;
namespace program
{
    class negate
    {
        public static void Main()
        {
            int[] a = new int[10];
            Console.WriteLine("Enter 5 Elements : ");
            for (int i = 0; i < 5; i++)
            {
                a[i] = Convert.ToInt16(Console.ReadLine());
                if (a[i] > 0)
                    a[i] = -a[i];
            }
            Console.WriteLine("Elements:");
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(a[i]);
            }
            Console.ReadLine();
        }
    }
}


Output:

Enter 5 Elements :
10
7
8
45
67
Elements :
-10
-7
-8
-45
-67



More C# Programs:

















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...