Demo entry 6361502

c

   

Submitted by anonymous on May 04, 2017 at 14:55
Language: C. Code size: 1.0 kB.

#include <stdio.h>

int main(void)
{
	int repeat, ri;
	int nScores;
	int Scores[80];
	int i, j;
	
	printf("Input the time of repeat: ");
	scanf("%d", &repeat);
	printf("\n");
	for(ri = 0; ri < repeat; ri++)
	{
		printf("-------------------------------------\n");
		printf("Input the length of the original array: ");
		scanf("%d", &nScores);
		printf("\n");
		
		printf("Input the array: ");
		for(i = 0; i < nScores; i++)
			scanf("%d", &Scores[i]);
		printf("\n");
			
		nScores = RemoveZeroElements(Scores, nScores);
		
		printf("Output the length of the new array: ");
		printf("%d", nScores);
		printf("\n\n");
		printf("Output the array: ");
		for(i = 0; i < nScores; i++)
			printf("%d ", Scores[i]);
		printf("\n\n");
		
	} 
}

int RemoveZeroElements(int array[], int n)
{
	int count = 0;
	int i, j;
	
	
	for(i = 0; i < n; i++)
	{
		if(array[i] == 0)
		{
			for(j = i; j < n-1; j++)
				array[j] = array[j+1];
			n--;
			i--;	 		
		}
	}
	
	return n;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).