calling array in function [closed] - c

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am new to C , and i am working on a program in C to evaluate RHS of green's theorem
Those who don't know about green's theorem here is
LINK
from wikipedia.
Now concerning the Right hand side (RHS) of green's theorem , it requires partial differentiation and double integrtation .
I have coded a program in C to calculate partial differentiation of M and L wrt x and y respectively.
Here is the code for it .
Now here comes the problem as you can see that f() is a function which is to be integrated , and our case it is e[i]-d[j] from the first code . Now the problem is e[i]-d[j] is an array of points so when the function f(u,v) call its value it should return the corresponding values of function at that point. Thus say for example we get f(1,0.8) , then the function e[i]-d[j] should return the value at i=1 and j=0.8 which is not possible subscript of array can't be of float type. So here i am stuck how to call the values from function f.
Any help would be gratly appreciated .

Where do you get the values between 0 and 1? Do you just compute the value from i,j on the fly? On your first part of the program only value with int index is computed.
No way to store value using float i,j as array index. If you insist on using the float as index. May be c++ STL map can help you. You can just use i+j as the key to index the values.

Multiply the number of points you are playing with by a constant factor - say 10 for your example. Then you can multiply your array subscript by the same. In your example, 1, 0.8 becomes (10, 8) and works fine. This is a variation on fixed point math if you are interested.

Related

How to plan out a theatre using labels [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
For a school project, we have to develop a theatre booking system, with a graphical representation of the theatre, which is labelled in a really annoying way. Our tutor said we should represent the theatre with a 2-d array of labels, but referencing each label to change the colour is tricky, say if the user booked seat 10,10 then that wouldn't be 10,10 in the array.
Does anyone know of any good methods of solving this? Because I am stumped.
Here is a link to the seating plan: http://i.stack.imgur.com/U14ut.png
I would suggest that you use an array of labels for each row. For example for row A create labels named lblRowA with indexes 1 to 14 and repeat for the other rows (having an array for each row). That should make it easy to map requests onto real world seating.
In addition to the 2-D array of labels, you can use two 2-D arrays of the same size, one for the row letter and one for number of each seat represented by the array of labels.
For example, for labels(4, 7) the seat number might be seatNumbers(4,7) and the row letter might be rowLetters(4,7).
If you know how (or can figure it out), you use one 2D array of a class or structure where each member contains the two values, and possibly reservation information, etc. In that case, you could address the seat information with something like seats(4,7).rowLetter, seats(4,7).seatNumber, and seats(4,7).reserved. You could also have a reference to the seat labels in the seats class.

How to implement Foulke's algorithm in C [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Foulke's algorithm is defined by
(In + U)2 = In+ U + U2
with:
In : the identity matrix
U : square adjacent matrix
I want to implement this algorithm in C by recurrence.
Any help is appreciated.
Your formula is wrong. Substitute U with identity matrix and you will see that the equality does not hold. You need to change it to (In + U)^2 = In+ 2*U + U^2. Just like numbers. Makes sense, huh?
Otherwise all you need to do is to implement a function that multiplies to two-dimensional matrices and returns the result in a two-dimensional array. I don't think using recursion for this problem is a good option.
I recommend you to use BLAS library. Or you want to make all yourself without any algebra-library?

Sorting with just one loop. Help me with its efficiency [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have came up with a new sorting algorithm with just one do while loop in it, but i don't
know how to calculate the efficiency of it in best,average and worst case so please help me in calculating it.
The loop starts with i=1 and the end condition for while loop is i<=n-2 and some times the value of i increases in the loop and some times i value will be decremented based on some condition.
I think i will better understand if u illustrate through simple examples.
please help me............
Thank you in advance for those who help me.....
some times i value will be decremented based on some condition
This vagueness makes it impossible to analyze. If the "condition" is always true and i is decremented to zero, then the loop runs forever. So based on what you say, the time complexity could be anything from Theta(n) to infinity.
The way to work out time complexity is to calculate (or put an upper bound on) the number of operations performed, as a function of n. "Operations" in the case of sorting usually means comparisons and copies/moves, but if your algorithm does anything unusual then of course that has to be included.

How to write a C program of two bodies exerting a gravitational force on each other? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I 've been set the following problem and don't have a clue how to start any help would be much appreciated.
In 2-D, read in the initial positions, velocities and masses of two bodies (suns, stars etc) . You will need to define suitable units for these. Then using the gravitational equation, calculate the force on each body from the other, and use Newton’s 3rd law to calculate the acceleration of that body. Generate a file with the positions of both bodies at each timestep for a long time period. Use this file to plot the paths of the two bodies.
Store the initial position, velocity and masses.
Calculate the magnitude and direction of the gravitational force.
Knowing the force, you can calculate the acceleration of each body.
Knowing the acceleration you can calculate the new velocity.
Knowing the velocity you can calculate the new position.
Using suitably small time steps you can get a reasonably good approximation to continuous motion.

adding the middle 20 values of array 0-99 [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
This may seem quiete easy to everyone else but I am struggling to comprehend it.
I have to add up the numbers held in the middle 20 indexes of an array 0-99
but I cant work out from what index to what index I should add.
Is it from 40-60? or is that 22 values?
if you are having trouble counting things in lists of consecutive integers that are not starting at one then just imagine subtract the lowest index from all of them and then add 1. Then you will have a lsit of consecutive integers starting from 1 so whatever the top index is will be the count of the thing.
So in the case of 40-60 you can subtract 40 from everything and add one to see that these indexes map to the numbers 1 to 21.
To get your correct answer a simple extension of this can be used. 0-99 is 100 values (just add one to all of them to see this). That means you need to skip 40 values and then take the next 20.
So to work out the ones you skip you want to start at 0 and then take 40 items. You can easily see that after adding one to the list you want your top index to be 40 (so your indexes map to 1-40) which means the actual indexes are 0-39. So 40 then starts your list and in a similar way you can say that if 40 is your first index (40-39=1) then your last index will be 59 (since 59-39 = 20).
Thus the answer is that you are lookign at indexes 40-59.
I hope this not only helps you get the answer here but helps you work out how to do it on your own.
index 40 - index 59 is your middle-range ;)

Resources