By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!asking for someone to code for i am new to C++Hi there,
Have you started coding or are you asking for someone to code something for you?
lol.. good luck with that mate. I highly doubt anyone here will do your homework for you. Now, if you attempt it, and can't figure it out, then sure, you're gonna get plenty of people to help you out, as long as they can see that you actually tried. I get it... you're new to the language, and have all sorts of questions. That is normal... but don't confuse laziness for frustrationasking for someone to code for i am new to C++
#include <iostream>
using namespace std;
void swapElements(int *a, int *b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void insertionSort(int array[], int length) {
int i, j, k;
for (i = 1; i < length; i++) {
k = array[i];
j = i - 1;
while (j >= 0 && array[j] > k ) {
array[j +1 ] = array[j];
j--;
}
array[j + 1] = k;
}
}
void printArray(int array[], int length) {
for (int i = 0; i < length; i++) {
cout << array[i] << " ";
}
}
int main() {
int arrayLength, i;
int myArray[20];
cout << "How many numbers do you want to store in array? (1 - 20) " << endl;
cin >> arrayLength;
// Store numbers in array (user input)
for (i = 0 ; i < arrayLength ; i++) {
cout << "Please enter a number:" << endl;
cin >> myArray[i];
}
cout << "Array before sorting:\t";
printArray(myArray, arrayLength);
insertionSort(myArray, arrayLength);
cout << "\nArray after sorting:\t";
printArray(myArray, arrayLength);
return 0;
}
Code Forum is a community platform where coding enthusiasts can connect with other developers, engage in discussions, ask for help, and share their knowledge with a supportive community. It's a perfect place to improve your coding skills and to find a community of like-minded individuals who share your passion for coding.
We use essential cookies to make this site work, and optional cookies to enhance your experience.