63 214
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #22011 in C# for Gudimella vathsalya

Question #22011
1. Write a console-program to create an array of integers. Initialize the array and assign the values in array. Define a method to pass the array and modify array elements. Display array elements by using for-each loop
->actually for the above question u have answered the code as progrm thanku......but i need explanation for it and show output also
Expert's answer
/* Include this header file to be able to use getch() function */
#include <conio.h>
/* Include this header to use C++ input/output streams (cout, cin) */
#include <iostream>

/* This line of code allows you to call the functions
from the 'std' namespace without specifying their full name.
It means that you will be able to have access for example
to the C++ standard output stream writing 'cout' instead of 'std::cout' */
using namespace std;

/* This function increases every element of the given array by delta.
Note that we also pass the length of the array
for not to have the array overflow */
void increment_array_elements(int array[], int arrayLength, int delta)
{
for (int c = 0; c < arrayLength; c++)
array[c] += delta;
}

void main()
{
int array[10]; //declare an array of 10 integer values

/* Fill the array with the squares of indices of each array element */
for (int k = 0; k < 10; k++)
array[k] = k * k;

/* Increase each array element by 3 */
increment_array_elements(array, 10, 3);

for (int i = 0; i < 10; i++)
cout << array[i] << endl;

/* This function waits for the user input (a single key press).
When the key is pressed it's not displayed on the console.
It's a simple way to delay a program before exit */
getch();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions