你到底是如何格式化这个来排列的,我尝试了一切,没有任何改变?!
printf("N Count\n");
printf("---- ------ \n");
for(i = 0 ; i < MAX_ELEMENTS ; i++)
{
count = getOccur(arr, MAX_ELEMENTS, arr[i]);
printf("%1d %1d\n", arr[i], count);
}
我试过制表符,间距,那些带有最后一个数字的 % 符号,它不会从这个改变
N Count
----- ---
1 1
2 1
3 1
快把我逼疯了!我不明白!哈哈
编辑整个程序新问题!
#include <stdio.h>
#define MAX_ELEMENTS 10
int getOccur(int a[], int num_elements, int value);
void printArr(int a[], int num_elements);
int main()
{
int arr[MAX_ELEMENTS];
int trim[MAX_ELEMENTS];
int count, target, i;
int j, k, temp;
for(i = 0 ; i < MAX_ELEMENTS ; i++)
{
printf("Enter a variable for the array: ");
scanf("%d", &arr[i]);
}
for (j = 1 ; j <= MAX_ELEMENTS-1 ; j++)
{
for(k = 0 ; k <= MAX_ELEMENTS-2 ; k++)
{
if(arr[k] > arr[k+1])
{
temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
}
}
}
printf("%4s %6s\n", " N ", "Count");
printf("%4s %6s\n", "----", "------");
for(i = 0 ; i < MAX_ELEMENTS ; i++)
{
count = getOccur(arr, MAX_ELEMENTS, arr[i]);
printf("%3d %4d\n", arr[i], count);
}
}
int getOccur(int a[], int tally, int value)
{
int i;
tally = 0;
for( i = 0 ; i < MAX_ELEMENTS ; i++)
{
if (a[i] == value)
{
++tally;
}
}
return(tally);
}
void printArr(int a[], int amount)
{
int i;
for(i = 0 ; i < amount ; i++)
{
printf("%d ", a[i]);
}
printf("\n");
}