Question Calculate the sum of the elements of an array for which a given inequality is satisfied

metal_hard

New member
Joined
Nov 1, 2020
Messages
4
Programming Experience
Beginner
Hello, help write a console solution). Create an array with elements, Z_ (k, n) = f (k) + sin (k) * f (k), where n, k = 1… N, N is an integer entered using the keyboard. Function values tmp1 = Math.Abs (Math.Sin ((2 * x) - 1.5) + 3 * Math.Sin ((x * x)) + 2.38);

Array value display. Calculate the number of array elements for which the inequality Z_ (k, n)> 3 is satisfied and the sum of elements whose value is less than 9.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,409
Location
Chesapeake, VA
Programming Experience
10+
We are not a code writing service. Show us your work and tell us where you are stuck, and we'll try to help you.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,448
Location
Sydney, Australia
Programming Experience
10+
Yeah, it's not really acceptable for you to copy and paste your homework questions and expect us to do the work for you. We're generally quite careful about helping with homework because it's cheating if we just do it for you. That doesn't mean that we won't help though. As suggested, you need to do everything you can first and then show us that and explain exactly where you're stuck. If you don't know how to do anything then you really need to go back and review your coursework first, because you will have been taught most, if not all, of what you need. At the very least, you should be able to break down the problem into parts and work out the logic such that you can write an algorithm, even if you can't implement all of that algorithm in code. If you have done at least that then you certainly haven't done everything you can.
 

metal_hard

New member
Joined
Nov 1, 2020
Messages
4
Programming Experience
Beginner
Hello, please help me, I am best of all Calculate the number of array elements for which the inequality m [k, n]> 3 is satisfied, and the sum of the elements whose value is less than 9. I don’t know how best to write it down, help pzh love advice!


C#:
            int k;
            int n;
             //   double sum = 0;
            k = Int32.Parse(Console.ReadLine());
            n = k;
            double[,] m = new double[k, n];
            Console.WriteLine(" ");
            for (int x = 1; x <= k; x++)
            {
                for (int y = 1; y <= n; y++)
                {
                    double z;
                    z = y * Math.Abs(Math.Sin((2 * x) - 1.5) + 3 * Math.Sin((x * x)) + 2.38) + Math.Sin(x) *
                      Math.Abs(Math.Sin((2 * y) - 1.5) + 3 * Math.Sin((y * y)) + 2.38);
                    m[x - 1, y - 1] = z;
                }
            }
            for (int i = 0; i < k; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.WriteLine(m[i,j]);
                    //Console.Write($"{m[i, j]} \t");
                }
                Console.WriteLine();
            }
            Console.WriteLine(" ");
            Console.WriteLine(" ");
 
Last edited by a moderator:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,409
Location
Chesapeake, VA
Programming Experience
10+
You already have a thread about this open. Merging threads...
 

Sheepings

Retired Programmer
Staff member
Joined
Sep 5, 2018
Messages
1,877
Location
UK
Programming Experience
10+
You neglected to ask a valid question.

Don't assume we know what you are trying to do. The explaining is for you to do. Put some effort into explaining your problem.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,448
Location
Sydney, Australia
Programming Experience
10+
So many people seem to think that programming exists in a vacuum and ignore the logic that they use every day to perform tasks. If someone gave you a piece of paper containing a list of numbers and asked you to manually count and sum that numbers in that list that satisfied a specific condition then how would you do it? That's how you do it in code. It should be fairly obvious that you would store a running count and sum somewhere and they would both start at zero. You would test the numbers in the list, one by one, and if the current number satisfied the condition, you would add that number to the sum and increment the count by 1. I don't se any running sum or count or even an if statement in your code, so you clearly haven't considered the logic that your code actually has to implement. You should have started by working out the logic involved, formalising that into an algorithm and then implementing the algorithm in code. You should be able to build it up one step at a time, not moving onto the next step until the current step is working. When someone has multiple steps half-working, you know that they haven't actually considered the steps.
 
Top Bottom