I am trying to reverse this array explain why it is not working and fix it thank you!
Also can you explain what ncurses.h is and its utalizations. Thanks!
#include <stdio.h>
array[10] = {1,2,3,4,5,6,7,8,9,10};
int i,j,temp;
int
main(){
for(i = 0; i < 10; i++) {
for (j = 9; j >= 0; j--) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
for(i = 0; i < 10; i++) {
printf(" %d", array[i]);
}
}
If the answer helps you please upvote, and in case you have any doubts please comment and get it clarified,.
You are using the wrong algorithm to reverse the array. We use only one loop to reverse an array.
Swap elements in the first half with elements in the second half to reverse the array.
element at index 0 = 1 swapped with element at index 9-0 = 9 = 10 element at index 1 = 2 swapped with element at index 9-1 = 8 = 9 element at index 2 = 3 swapped with element at index 9-2 = 7 = 8 element at index 3 = 4 swapped with element at index 9-3 = 6 = 7 element at index 4 = 5 swapped with element at index 9-4 = 5 = 6

Output:

Ncurses is a library in c, it is accessed using ncurses.h. It is a library used for developing GUI_like application software that runs under a terminal emulator. It is used for developing terminal applications.
I am trying to reverse this array explain why it is not working and fix it...
why can't I reveerse my array at all please help quickly due in about 1 hour #include <stdio.h> #include <stdlib.h> int a[10] = {1,2,3,4,5,6,7,8,9,10}; int reverse_order[10]; int main(){ for (int i = 0; i < 9; i++){ int temp = a[i]; temp = reverse_order[9-i]; a[i] = temp; } for(int j = 0; j < 9; j++){ printf(" %d",reverse_order[j]); } }
I'm trying to code a C program so it sorts an array of integer numbers of size n in ascending order. My code is written below but its not working properly, its giving me errors, I think my sort and swap functions aren't done right maybe, please help and fix. It says "undefined reference to "SelectionSort" as an error. But the question asks to not change the PrintArray and Main function. #include <stdio.h> void PrintArray(int size, int array[]) { for...
#include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...
4. (3 points) Consider the following function reverse, that attempts to reverse an array in place (i.e. without the use of additional storage). It does it by interchanging the first and last elements, then the second and second from last etc. All of the interchanges are done by calling function interchange. Here are the two functions and a main program: #include <iostream> using namespace std; void interchange(int x, int y) int temp: temp = x; x=y: y - tempi }...
Please help in C: with the following code, i am getting a random 127 printed in front of my reverse display of the array. The file i am pulling (data.txt) is: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 when the reverse prints, it prints: 127 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 not sure why...please...
I am trying to figure out why my C code is outputting "exited, segmentation fault". The game is supposed to generate 4 random numbers and store them in the "secret" array. Then the user is suppose to guess the secret code. The program also calculates the score of the user's guess. For now, I printed out the random secret code that has been generated, but when the game continues, it will output "exited, segmentation fault". Also, the GetSecretCode function has...
I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) { int i, j; int rowA, colA, rowB, colB; int A[10][10], B[10][10]; int sum[10][10]; char str1[10]; printf("This is a matrix calculator\n"); //read in size from user MATRIX A printf("Enter in matrix A....\n"); printf("\t#row = "); scanf("%d", &rowA); printf("\t#col = "); ...
i want to fix the solution and provide an explanation why the pthread_join is not working as intended? #include <stdio.h> /* standard I/O routines */ #include <pthread.h> /* pthread functions and data structures */ void* PrintHello(void* data) { pthread_t tid = (pthread_t)data; /* data received by thread */ pthread_join(tid, NULL); /* wait for thread tid */ printf("Hello from new thread %u - got %u\n", pthread_self(), data); pthread_exit(NULL); /* terminate the thread */ } /* like any C program, program's execution...
Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct { char name[MAX_SIZE1]; int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...
^^^ Q3. I am trying to implement double linked list but I was failed to write the code so anyone gives the main Code in the main function THANK YOU FOR ADVANCE #include<stdio.h> #include<stdlib.h> #include<alloc.h> struct node { int info; struct node *lptr,*rptr; }; typedef struct node DL; DL *delete( ) , *insert ( ); void display(); DL *delete(DL *start,int x) { DL *left,*right,*curr; curr = start; if( start == NULL) { printf("\nDoubly...