write a program to ask the user 8 integer numbers. your program will then move all negative elements of your array to the end of the array without changing the order of positive elements and negative elements
C
#include <stdio.h>
#include <stdlib.h>
void rearrange_alternate_positions(int arr[], int n){
int i,j;
j = 0;
for(i = 0; i < n; i++){
if(arr[i] < 0){
if(i != j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
j++;
}
}
}
int main(){
int n,i;
printf("\nEnter the number of elements : ");
scanf("%d",&n);
int arr[n];
printf("\nInput the array elements : ");
for(i = 0; i < n; i++){
scanf("%d",&arr[i]);
}
printf("\nOriginal array : ");
for(i = 0; i < n; i++){
printf("%d ",arr[i]);
}
printf("\n");
rearrange_alternate_positions(arr, n);
printf("\nRearranged array : ");
for(i = 0; i < n; i++){
printf("%d ",arr[i]);
}
printf("\n");return 0;
}
Also in C:
- Title
- kadane's algorithm
- Category
- C
- Title
- c copy string
- Category
- C
- Title
- fa fa-facebook
- Category
- C
- Title
- how to get random numbers in c
- Category
- C
- Title
- c bit access union
- Category
- C
- Title
- c how to define a variable
- Category
- C
- Title
- c program to find the sum of given number
- Category
- C
- Title
- delete string function in c
- Category
- C
- Title
- how to go to top of file in vim
- Category
- C
- Title
- read from stdin c
- Category
- C
- Title
- sustituir un dígito por otro
- Category
- C
- Title
- CL/cl.h: No such file or directory
- Category
- C
- Title
- passing 2d array as parameter to function in c
- Category
- C
- Title
- vbnet create and write on file
- Category
- C
- Title
- how to comment in arduino
- Category
- C
- Title
- c printf right pad with space
- Category
- C
- Title
- buscar caracter
- Category
- C
- Title
- mediawiki upload size
- Category
- C
- Title
- set timezone in debian terminal
- Category
- C
- Title
- change plot line color in matplotlib
- Category
- C
- Title
- lazer codechef
- Category
- C
- Title
- multiplicacion recursiva
- Category
- C
- Title
- print in c
- Category
- C
- Title
- how to remove button decoration
- Category
- C
- Title
- char to int c
- Category
- C
- Title
- convert string to float c
- Category
- C
- Title
- c vs python
- Category
- C
- Title
- uninstall elgg from hostgtor
- Category
- C
- Title
- c list
- Category
- C
- Title
- double return type in c
- Category
- C
- Title
- fibonacci series using recursion
- Category
- C
- Title
- classification report to excel
- Category
- C
- Title
- how to find the ith row of pascal's triangle in c
- Category
- C
- Title
- hello world
- Category
- C
- Title
- what is conio.h
- Category
- C
- Title
- string to int c
- Category
- C
- Title
- c radians
- Category
- C
- Title
- how to do matrix multiplication in c
- Category
- C
- Title
- c print array
- Category
- C
- Title
- code wars responsable drinker
- Category
- C
- Title
- how to pass an array to a thread in c?
- Category
- C
- Title
- diferencia entre * y & en c
- Category
- C
- Title
- How to pull images from Docker Registry
- Category
- C
- Title
- primo
- Category
- C
- Title
- c bit access struct
- Category
- C
- Title
- boolean function c
- Category
- C
- Title
- error: ‘cout’ was not declared in this scope
- Category
- C
- Title
- what is strikethrough in markdown
- Category
- C
- Title
- turn a char array into double C
- Category
- C
- Title
- how to get user input in c
- Category
- C
- Title
- heitai bestial
- Category
- C
- Title
- C largest unsigned int
- Category
- C
- Title
- how to make a linked list in c
- Category
- C
- Title
- how to check the size of a file in linux c
- Category
- C
- Title
- factorial of a given number in c
- Category
- C
- Title
- division recursiva
- Category
- C
- Title
- how to do Employing defensive code in the UI to ensure that the current frame is the most top level window
- Category
- C
- Title
- read a binary file c
- Category
- C
- Title
- write array of char to file in c
- Category
- C
- Title
- error: ‘istringstream’ is not a member of ‘std’
- Category
- C
- Title
- accessing elements of 1d array using pointers
- Category
- C
- Title
- entete c/c++
- Category
- C
- Title
- bella ciao lyrics
- Category
- C
- Title
- how to download file in powershell
- Category
- C
- Title
- hopw to check how many duplicates in an array c
- Category
- C
- Title
- '&&' within '||'
- Category
- C
- Title
- mostrar lista recursiva
- Category
- C
- Title
- How to setup a line length marker in vim
- Category
- C
- Title
- matrix c declaration
- Category
- C
- Title
- california
- Category
- C
- Title
- how to put a struct in another struct C
- Category
- C
- Title
- c matrix sintax
- Category
- C
- Title
- python web crawler
- Category
- C
- Title
- how to open chrome using cmd
- Category
- C
- Title
- where is /dev/kvm
- Category
- C
- Title
- enum c
- Category
- C
- Title
- atoi c
- Category
- C
- Title
- disable gnu++11 option
- Category
- C
- Title
- c bitwise operators
- Category
- C
- Title
- printf n characters c
- Category
- C
- Title
- vbl share price
- Category
- C
- Title
- Couldn't create temporary file to work with
- Category
- C
- Title
- version of libgcc
- Category
- C
- Title
- how to put quotes inside string c
- Category
- C
- Title
- docker logs follow
- Category
- C
- Title
- update ubuntu in terminal
- Category
- C
- Title
- switch case c
- Category
- C
- Title
- matplotlib pyplot legend location
- Category
- C
- Title
- find string in all files powershell
- Category
- C
- Title
- v
- Category
- C
- Title
- ordenar un vector
- Category
- C
- Title
- docker images command
- Category
- C
- Title
- Difference between ** and *
- Category
- C
- Title
- arduino vscode upload choosing sketch
- Category
- C
- Title
- arduino knn
- Category
- C
- Title
- Declare macro
- Category
- C
- Title
- printf("%3d ",XX);
- Category
- C
- Title
- jock cranley
- Category
- C
- Title
- write in file in c
- Category
- C
- Title
- slug urls django
- Category
- C