Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
Kindly tell me how to initialize an array in Assembly Language e.g
Initialize an array named as “Even”, which contain first ten EVEN numbers.
Even = 0,2,4,6,8,10,12,14,16,18
Initialize an array named as “Odd”, which contain first ten ODD numbers.
Odd=1,3,5,7,9,11,13,15,17,19,21
Add Both arrays (index wise) into a third array named as “Sum”.
SUM [0] = Even [0] + Odd [0]
SUM 1 = Even 1 + Odd 1
Up to
SUM [n] = Even [n] + Odd [n]
There are many ways of doing this. The simplest to create the array in a declaration:
EVEN:
.WORD 0, 2, 4
ODD:
.WORD 1, 3, 5
Using whatever size data you want.
To add them, you can:
Unroll the loop
Us a macro
Call a recursive function
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is anyone here who can explain me how to print the permutations of a array of strings in iterative method without using recursion. Please explain with code.
If the string is "abcd", put all of the "a" chars in position 0 for the first n-1! arrays, in position 1 for the next n-1! arrays, etc. Then put all of the "b" chars in position 1 for the first n-2! arrays, etc, all of the "c" chars in position 2 for the first n-3! arrays, etc, and all of the "d" chars in position 3 for the first n-4! arrays, etc, using modulo n arithmetic in each case to move from position 3 to position 0 as you are filling out the arrays.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I don't get what I should put in the place of: "α" and "β" in order to print all the 3 digit numbers which are different from 0 and from one another.
It is required to replace those 2 variables, with some code
We are entering G(0)!!!
It's from an exam paper, I really don't get it, please help.
void G(int k)
{int i;
for(i=1;i<=α;i++)
{ p[k]=i;
if(β)G(k+1);
else
printf("%d%d%d\n",p[0],p[1],p[2]);
}
}
For any of this to make sense, it must be that p is declared as a global int array of dimension at least 3. I assume for the purposes of this answer that it is in fact so declared.
Note that the function sets p[k] = i, but it later reads back only p[0], p[1], and p[2]. This should give you a pretty good idea about what makes sense for expression β, which controls whether to recurse (increasing k) or print.
Note also that the function sets p[k] = i, and that when it reads back those p[k] for various k, it wants to get values ranging from 1 to 9 (no more and no less). This should give you a pretty good idea of what expression makes sense for α, the inclusive upper bound on i.
Having figured those out, it remains to satisfy yourself that the natural substitutions for those expressions indeed produce a resulting function that behaves as required when initially called as G(0). I suspect that you will find that easier than you did discerning the needed expressions.
(Details are left as an exercise.)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm having trouble on thinking of away to attack this problem.
X is defined below. For n=1,x=0.5,n=2,x=0.833.As you add more terms, X increases. Calculate n for which X becomes larger than 4. First write the algorithm and then implement the code in C.
x= 1/2+1/3+...1/n+1 answer: n = 83
The only thing I'm sure of is that it uses a for loop.At first I was thinking something like
For(int i = 0; i <= n.....
That doesn't seem close though.I dunno..Can I get a hint on where to start?
You will obviously compute the partial sums X.n and stop when X.n<4 and X.n+1>4.
To compute the partial sums, keep an accumulator variable and add the fractions one after the other
n= 0
S= 0
// Repeat the following instructions
n+= 1
S+= 1/(n+1) // Now, S = X.n
Remains to find the stopping condition. As the value of S goes increasing from 0, we will stop as soon as S exceeds 4. In other words, continue as long as S remains below 4.
n= 0
S= 0
while S < 4
n+= 1
S+= 1/(n+1) // Now, S = X.n
Translate that to C syntax.
Remains to look closer at the possibility that X.n = 4.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
The code is question is:
unsigned int iomask[]={1UL<<4};
I understand the left shift binary operation, but I do not understand the function of the {} and []. Could anyone help?
The [] tells you that iomask is an array whose size is determined by its initializer. The {} is that initializer. It can be used to initialized arrays or structs.
In this case, the initializer contains a single element, so iomask is an array of 1 element.
[ ] simply indicates how many elements (or, dimension) are in the array, however, C compilers allow the array dimension to be omitted, and will infer the number based on the number of elements listed.
int iomask[] = {1,2,3,4,5};
is equal to
int iomask[5] = {1,2,3,4,5};
where the { } contain the initializers for the elements of the array.
In your example, iomask has 1 element, the 1UL<<4
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Write an algorithm called occurrences that, given an array of numbers A, prints all the distinct values in A each followed by its number of occurrences.
For example, if A = <28, 1, 0, 1, 0, 3, 4, 0, 0, 3>, the algorithm should output the following five lines (here separated by a semicolon 28 1; 1 2; 0 4; 3 2; 4 1.
The algorithm may modify the content of A, but may not use any other memory.
Each distinct value must be printed exactly once.
Values may be printed in any order.
Possible solution will have 2 steps:
Sort your array
Iterate on array storing current value and number of its occurrences and printing current value/count pair when current value changes
This solution does not require extra memory and has complexity O(n*log(n)) as sorting is the "heaviest" part of algorithm