TRENDING NEWS

POPULAR NEWS

How Do I Make Two Arrays Equal To Each Other Objective C

How do I add two arrays in Java and initialize the third array with the sum of the two corresponding elements from the two arrays?

Hi,Please find below 2 programs :addition of 1D arrays elements:public class Demo7 {public static void main(String[] args) {int[]a={6,2,3};int b[]={4,5,6};int c[]=new int[a.length];for(int i=0;i<=a.length-1;i++){c[i]=a[i]+b[i]; //ADDING}System.out.println("SUM OF TWO ARRY");for( int j=0;j<=c.length-1;j++){System.out.println(c[j]); //DISPLAYING}}}2) Addition of 2 matrix :public class Demo3 {public static void main(String[] args) {int a[][]={{10,20},{10,20}};int b[][]={{25,20},{45,20}};Addition add=new Addition(a,b);}}class Addition{int add[][]=new int[5][5];Addition(int a[][],int b[][]){for(int i=0;i<=a.length-1;i++){for(int j=0 ;j<=b[i].length-1;j++){add[i][j]=a[i][j]+b[i][j];System.out.print("\t\t"+add[i][j]);}System.out.println();}}}I hope seeing above program you get some idea..!Regards,Shivananda Rai

How can I divide an array into two arrays in C++?

Wow! Vectors and what not in the answers. Why not a simple code? This is an integer array.int full[size];
int fir[size/2], sec[size/2], i;
for(i = 0; i < (size/2); ++i){
fir[i] = full[i];
}
for(; i < size; ++i){
sec[i - (size/2)] = full[i];
}
That can be it. Simple enough.

How do I write a C function that accepts two arrays of the same size and add each element of the array together and place values in the third array?

#include
int main(int argc, const char * argv[]) {
char s[10] = {1,2,3,4,5,6,7,8,9,0};
char t[10] = {2,3,4,5,6,7,8,9,0,1};
char res[10];
for(int i = 0; i < 10; i++){
res[i] = s[i] + t[i];
printf("res[%d] = %d\n", i, res[i]);
}
return 0;
}

res[0] = 3
res[1] = 5
res[2] = 7
res[3] = 9
res[4] = 11
res[5] = 13
res[6] = 15
res[7] = 17
res[8] = 9
res[9] = 1

What is meant by pointer to array?

A pointer to an array is a reference to the array or data so that its contents can be read or manipulated. It gives you a handle to the array so that you can access it. In low level terms, a pointer does first level indirection. You read the actual value of the pointer and that value will give you the location of the data element you wish to access.

How can we make a program to find the sum and average of array values? Please help?

Its simple. int main(){int array[]={1,2,3,4,5,6}; /* for example*/int sum=0,i;float average;for(i=0;i<6;i++){sum=sum+array[I];}average=sum/6.0;return 0;}I guess you might have understood declaration part. Then the loop variable will increase for each iteration. And for each iteration one by one elements of array will be added to variable sum. Finally when we get the sum , to obtain average we just have to divide it by total number of array elements. I.e. 6. You can make this dynamic by taking input for array size and values from user. And using that value as limit value for loop variable I.e. I in our example and same for dividing the sum which is 6 in the above snippet.

In Swift, how do you get the total number of elements in an array of arrays?

let a = [[1,2,3],[4,5,6],[7,8,9]]
let arrayLength = 0

for i in 0...(a.count-1) {
arrayLength += a[i].count
}
Longer, but more readable

Java Programming: is this correct?

Just a few questions ...

What are the values of i and sum after this code sequence is executed?

int i = 0;
int sum = 0;
for ( i = 0; i < = 40; i++)
{

if ( i % 10 = = 0)

sum += i ;

}

(IS IT RIGHT IF I SAID THE i = 40 and sum = 60 or is i =41 ) ;/ )

SECOND QUESTION:
Given code:

public abstract class A{ }
public class B extends A
{
}

The following code sequence would correctly create an object reference of class A holding an object reference for an object of class B:

A c;
c = new B();


Is this true? (or not?)

THIRD QUESTION:

int x = 7;
int y = 9;

Expression: ( y – x == 0 || ( x + 2 ) != y)

This is false right? :O

AND ONE MORE :

double [] cellbills = new double[5];

double [] cellbills = { 45.24, 54.67, 42.55, 44.61, 65.29};

Which one of these will instantiate a double array of 6 elements starting with array index element 0 :O?

or do both do it...? or even neither?

Please and thanks in advance ~

TRENDING NEWS