#include
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[50][50];
int i,j,n1,n2;
printf("enter size of array no of rows-");
scanf("%d",&n1);
printf("enter size of array no of columns-");
scanf("%d",&n2);
for (i=0;i<n1;i++)
{
for (j=0;j<n2;j++)
{
printf("enter elemnt");
scanf("%d",&arr[i][j]);
}
}
getch();
}
#include<stdio.h>
#include<assert.h>
/* sum the given 2D array */
int sum_array (const int* arr, const unsigned int rows, const unsigned int cols) {
unsigned int x, y;
int sum;
sum = 0;
if (!arr) return sum;
for (x=0; x<rows; ++x)
for (y=0; y<cols; ++y)
sum += arr[x*cols+y];
return sum;
}
int main (void) {
const unsigned int rows=5;
const unsigned int cols=6;
int sum;
int a[rows][cols];
unsigned int x, y;
for (x=0; x<rows; ++x)
for (y=0; y<cols; ++y)
a[x][y] = (x+1)*(y+1);
sum = sum_array ((int*)a, rows, cols);
printf ("The sum of the array is: %d\n", sum);
assert(sum == 315);
return 0;
}
If the arrays are fixed-length, summing them is reasonably trivial:
int a[5] = {1, 2, 3, 4, 5};
int b[5] = {10, 20, 30, 40, 50};
int c[5];
for (unsigned i=0; i<5; ++i) {
c[i] = a[i] + b[i];
}
Note that a, b, and c must all be of the same size. With fixed-length arrays it's a good idea to store the size in a constant variable:
const unsigned size = 5;
int a[size] = {1, 2, 3, 4, 5};
int b[size] = {10, 20, 30, 40, 50};
int c[size];
for (unsigned i=0; i<size; ++i) {
c[i] = a[i] + b[i];
}
Summing variable-length arrays is a bit more complex, but we can simplify with a function:
int* sum (int* a, int* b, const unsigned size) {
int* p = malloc (size * sizeof (int));
if (p == NULL) return NULL; // sanity check!
for (unsigned i=0; i<size; ++i) {
p[i] = a[i] + b[i];
}
return p;
}
The sanity check is necessary to ensure the memory was actually allocated. If successful, the caller is responsible for releasing the allocated memory:
void f (int* a, int* b, const unsigned size) {
int* p = sum (a, b, size);
if (p == NULL) return; // sanity-check!
// ...
free (p);
}
Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.
To determine if an array is symmetric, the array must be square. If so, check each element against its transpose. If all elements are equal, the array is symmetric.For a two-dimensional array (a matrix) of order n, the following code will determine if it is symmetric or not:templatebool symmetric(const std::array& matrix){for (size_t r=0 ; r
Reference:cprogramming-bd.com/c_page1.aspx# array programming
How to write a program for mouse in microprocessor?
To write a C++ program to display the student details using class and array of object.
array type
Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.
import java.util.Arrays; public class arraysort { public static void main(String[] a) { int array[] = { 2, 5, -2, 6, -3 }; Arrays.sort(array); for (int i : array) { System.out.println(i); } } }
To determine if an array is symmetric, the array must be square. If so, check each element against its transpose. If all elements are equal, the array is symmetric.For a two-dimensional array (a matrix) of order n, the following code will determine if it is symmetric or not:templatebool symmetric(const std::array& matrix){for (size_t r=0 ; r
Reference:cprogramming-bd.com/c_page1.aspx# array programming
How to write a program for mouse in microprocessor?
To write a C++ program to display the student details using class and array of object.
Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.
int sumArray(int N, int* A) { int sum = 0; do sum += A[N-1] while (N-- > 1); return sum; }
write an assembly language program to find sum of N numbers
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
maxValue = function (array) {mxm = array[0];for (i=0; i<array.length; i++) {if (array[i]>mxm) {mxm = array[i];}}return mxm;}; i don't know