current position:Home>Input n integers from the keyboard and store them in a pile of arrays. Put all positive numbers in the array in front of the array and negative numbers in the back to output the array

Input n integers from the keyboard and store them in a pile of arrays. Put all positive numbers in the array in front of the array and negative numbers in the back to output the array

2022-02-03 00:33:37 CSDN Q & A

img




Refer to the answer 1:
#include "stdio.h"#define N 100int main(){    int a[N],i,j,temp,n;    scanf("%d",&n);    if(n>100)         return 0;    for(i=0;i<n;i++){        scanf("%d",&a[i]);    }    for(i=0;i<n-1;i++){        if(a[i]<0){            for(j=i+1;j<n;j++){                if(a[j]>0){                    temp=a[j];                    a[j]=a[i];                    a[i]=temp;                    break;                }            }        }    }    for(i=0;i<n;i++){        printf("%d ",a[i]);    }    return 0;}

img




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030033359491.html

Random recommended