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
I am using an array,i want to call 4 element from the array at the same time so i can use them in an equation ,any one knows how.
example
int a[10]={1,2,3,4,5,6,7,8};
I want 1234+15
how?
using C#:
1234 = 1*1000 + 2*100 + 3*10 + 4*1
double result = 0;
int ex = 3; // Math.Pow(10,3) = 1000.00
for(int i = 0; i < 4 0; i++)
{
result += a[i] * Math.Pow(10, ex);
ex--;
}
result += 15;
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 last year.
Improve this question
I have a list of number : -1.5 , - 1 , -0,5 , ... , 100.
I want to assign them to an array.
E.g :
a[0] = -1.5;
a[1] = -1;
....
a[202] = 100;
Can you show me how to do it ?
Thanks.
If you want to initialize array with several values, you can use this:
int a[4] = {1, 2, 3, 4};
But it should not be used, if you have a lot of numbers. If you need to assign list of numbers, that you stated in question, you should describe them with mathmetical expression in cycle:
for(int i = 0; i < 203; i++)
{
a[i] = -1.5 + 0.5 * i;
}
If you want to assign array with list of values, that can't be described with mathematical expression, you should read them from file.
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 1 year ago.
Improve this question
basically, I want to create a Position/location ruler which shows each numeric position starting at 1. let's say, if the characters in the above statement are 20 then in the next line 12345678901234567890 should be printed. similarly, if the characters are 30 then 123456789012345678901234567890 should be printed.
how can I do that?
Let's say n is the length you need to match
int n = 20; // or 30, or whatever
for (int i = 0; i < n; i++) printf("%d", (i + 1) % 10);
puts(""); // add newline
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 4 years ago.
Improve this question
I have to add elements in array.
I have function:
function d = kronDel(j,k)
if j == k
d = 1;
else
d = 0;
end
And i have n=0:31.
I tried this:
x2=j*kronDel(n-2,0);
Why doesnt this work?
I only get x2=0;
You want to make a kronecker delta function but you don't need it.
x2 = j(n==2)
or, if you want to keep the zeros
x2 = j.*(n==2)
If you really want to make the function, just adapt it to:
function d = kronDel(j,k)
d = j==k;
From your comment: "x2=[0,0,j,0,0,0,0...to the 31 all 0s] j=sqrt(-1)"
x2=zeros(1,31);x2(3)=i
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 6 years ago.
Improve this question
I have a int variable in which I am storing the integer value. Now I want to get only the suffix. e.g:
int num = 12;
int num = 17;
etc
from the above num variables, I want to store the suffix like 2, 7 etc.
What is the efficient way to do that?
Thanks in advance...
The modulo (%) gives you the remainder when divided by a number which will be 10.
int num1 = 12;
int num2 = 17;
int suffix1 = num1 % 10;
int suffix2 = num2 % 10;
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 9 years ago.
Improve this question
I have a 4*4 array-
int arr[4][4] = {{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}};
want to convert this into 2*2 array -
int final[2][2];
that should have
final[0][0] = (arr[0][0]+arr[0][1]+arr[1][0]+arr[1][1])/4;
final[0][1] = (arr[0][2]+arr[0][3]+arr[1][2]+arr[1][3])/4;
Is it possible to extract the value from array using lookup table.
Thanks in advance
As has been well commented, you basically have this, but just for completeness:
for ( i=0; i<2; i++ )
for ( j=0; j<2; j++ )
final[i][j] = (arr[i*2][j*2]+arr[i*2][j*2+1]+arr[i*2+1][j*2]+arr[i*2+1][j*2+1])/4;