Sajo
Member
- Joined
- Jul 22, 2020
- Messages
- 17
- Programming Experience
- Beginner
Hello everybody. I have problem with the task. The task is:"
Write a C # program that loads the value of manufactured goods in m manufacturing sectors from users over n months and then determines and prints the month in which productivity was lowest."
I realized that productivity is lowest in the month where the value of the goods produced is lowest. My problem is how to write the month where the lowest value is. First I have to find the smallest value of all the elements in the matrix. As you can see, that's what I did. To find the month in which that value is located, I need to find the row in which that value is located. Month=row(Example January is first month and it is first row). Unfortunately I don’t know how to write code for that part. Can you help me?
Write a C # program that loads the value of manufactured goods in m manufacturing sectors from users over n months and then determines and prints the month in which productivity was lowest."
I realized that productivity is lowest in the month where the value of the goods produced is lowest. My problem is how to write the month where the lowest value is. First I have to find the smallest value of all the elements in the matrix. As you can see, that's what I did. To find the month in which that value is located, I need to find the row in which that value is located. Month=row(Example January is first month and it is first row). Unfortunately I don’t know how to write code for that part. Can you help me?
Code for this task:
static void Main(string[] args)
{
Console.WriteLine(" Enter the number of months for which the value of the products is calculated ");
int n = int.Parse(Console.ReadLine());
Console.WriteLine(" Enter the number of manufacturing sectors ");
int m = int.Parse(Console.ReadLine());
int[,] c = new int[m, p];
Console.WriteLine(" Enter the price for each month in each manufacturing sectors");
for (int i = 0; i < n; i++)
{
Console.WriteLine("Month {0}:", i + 1);
for (int j = 0; j < m; j++)
{
Console.WriteLine("Manufacturing sector {0}: ", j + 1);
c[i, j] = int.Parse(Console.ReadLine());
}
}
int small = c[0 ,0];
for (int i = 0; i < n; i++)
{ for(int j = 0; j < m; j++)
{
if (small > c[i,j])
{
small = c[i, j];
}
}
}
Console.WriteLine(small);