Posts

Showing posts with the label multidimensional-array

Taking strings as a 2-D char array

Taking strings as a 2-D char array I want a code such that I enter some strings one-by-one (by pressing enter) and display it. for example; Input abc def Output abc def also I want this input to be in a array so that I can select any character from the array whenever I want. For example: s[1][1] gives 'e'. I have writen a code for this problem. #include <stdio.h> #include <stdlib.h> int main() { int i, j, n, m; scanf("%d%d", &n, &m); char a[n][m]; for (i = 0; i<n; i++) scanf("%s", a[i]); for (i = 0; i<n; i++) { printf("%s", a[i]); printf("n"); } } But for this code my input/output goes like this: Input ab cd Output abcd cd Can anyone tell where am I going wrong? The input you have shown in question is missing the input value of n and m . Show the input value you are giving to n and m . – H.S. Jun 2...

What is the difference between these 2 ways of creating a list of arrays in JavaScript?

What is the difference between these 2 ways of creating a list of arrays in JavaScript? How do I dynamically create a list of arrays in JavaScript, that actually shows up in the Developer console as a list of arrays? Just rephrased this question; there are plenty of examples how to do this, and my code is working, but I'm getting 2 very different results from these 2 methods: I tried this: var volume = ; for (i = 0; i < json.length; i++) { var item = new Array(2); item[0] = json[i].json_date; item[1] = json[i].volume; volume.push(item); } So, this code works, and seems to create an array of arrays, but in the developer console the result of console.log(typeof volume[0]) is undefined. If I create the array manually, it works much better: var volume = [ [1313964000000,23.17], [1314050400000,23.78], [1314741600000,25.24], [1314828000000,24.77], [1440021600000,82.69] ]; Now console.log(typeof volume[0]) is object. And console.log(volume) res...