Last active
January 1, 2016 10:19
-
-
Save novnan/8130835 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 有10个整数组成一个数组a,其中整数x出现了若干次,删除多余的x | |
只保留一个x,显示删除了的x的个数和最后的数组a */ | |
//假如要删除1 | |
#include <stdio.h> | |
#define N 100 | |
void main() | |
{ | |
int x, i, count = 0; | |
int a[10] = {5, 1, 2, 1, 1, 4, 3, 1, 1, 6}; | |
int b[N]; | |
printf("输入要删除的整数:"); | |
scanf("%d", &x); | |
int position = 0; | |
int isXSaved = 0; | |
for(i = 0; i < 10; i++) { | |
if(a[i] == x) { | |
count++; | |
if (isXSaved == 0) { | |
b[position] = a[i]; | |
position++; | |
isXSaved = 1; | |
} | |
} else { | |
b[position] = a[i]; | |
position++; | |
} | |
} | |
printf("删除了%d个所要删除的整数\n", count = count - 1); | |
printf("最后的数组a是:\n"); | |
for (i = 0; i < 10 - count; i++) { | |
printf("%d ", b[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment