C
C#13mo ago
iwhonaplay

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);
}
}
}
}
}
7 Replies
Angius
Angius13mo ago
Why do you need it to be simpler?
iwhonaplay
iwhonaplayOP13mo ago
Yep But at the same time I want to be able to make algorithm from it Oh I read question incorrect I need to do algorithm and also Just want to learn different Way
Angius
Angius13mo ago
It already is an algorithm, so no need to change anything there
iwhonaplay
iwhonaplayOP13mo ago
Okay Do you know how to write algorithms?
Angius
Angius13mo ago
Any piece of code that does something is an algorithm
iwhonaplay
iwhonaplayOP13mo ago
I mean This
Want results from more Discord servers?
Add your server