Write C# program to count total number of negative elements in array


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1.  
  2. using System;
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. int[] arr = new int[100];
  8. int i, num;
  9.  
  10. //Enter size of array
  11. Console.WriteLine("Enter size of the array: ");
  12. num = Convert.ToInt32(Console.ReadLine());
  13.  
  14. //Reading elements of array
  15. Console.WriteLine("Enter elements in array: ");
  16. for(i=0; i<num; i++)
  17. {
  18. arr[i] = Convert.ToInt32(Console.ReadLine());
  19. }
  20.  
  21. Console.WriteLine("All negative elements in array are: ");
  22. for(i=0; i<num; i++)
  23. {
  24. //Printing negative elements
  25. if(arr[i] < 0)
  26. {
  27. Console.WriteLine(arr[i]);
  28. }
  29. }
  30. Console.ReadLine();
  31. }
  32.  
  33. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts