iwhonaplay
iwhonaplay
CC#
Created by iwhonaplay on 11/17/2023 in #help
Hi guys I wrote a code but I need to do it simpler
So I wrote a code on c# but I need to do it simpler to make algoritm from it can you help here is code
namespace B2Task
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Give a number of days");
int N = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Give a number of temperature");
int K = Convert.ToInt32(Console.ReadLine());
int i = 0;
int[] arr;
arr = new int[N];
while (1 > N || N > 100 || K < 20 || K > 30) ;
while (i < N)
{
Console.WriteLine("day{0}", i + 1);
arr[i] = Convert.ToInt32(Console.ReadLine());
while (arr[i] > 40 || arr[i] < 0) ;
i++;
}
int x = 0;
Console.WriteLine("The number of days with highest temperature");
for (i = 0; i < N; i++)
{
if (arr[i] > K)
{
x++;
}
}
Console.WriteLine(x);
Console.WriteLine("Days with the highest temp");
for (i=0; i < N; i++)
{
if (arr[i] > K)
{
Console.WriteLine(i+1);
}
}
}
}
}
namespace B2Task
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Give a number of days");
int N = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Give a number of temperature");
int K = Convert.ToInt32(Console.ReadLine());
int i = 0;
int[] arr;
arr = new int[N];
while (1 > N || N > 100 || K < 20 || K > 30) ;
while (i < N)
{
Console.WriteLine("day{0}", i + 1);
arr[i] = Convert.ToInt32(Console.ReadLine());
while (arr[i] > 40 || arr[i] < 0) ;
i++;
}
int x = 0;
Console.WriteLine("The number of days with highest temperature");
for (i = 0; i < N; i++)
{
if (arr[i] > K)
{
x++;
}
}
Console.WriteLine(x);
Console.WriteLine("Days with the highest temp");
for (i=0; i < N; i++)
{
if (arr[i] > K)
{
Console.WriteLine(i+1);
}
}
}
}
}
17 replies