#include <stdio.h>
#define SUM 3+4//macro definition is intact using used for test4
#include <time.h>//used for Test8~9
#include <stdlib.h>//used for Test8~9
void Test () {//array output
int a[5]={1,2,3,4,5};
printf ("Array output,look,please...\n");
int a[10];
int i;//for (int i=0;i<10;i++)
printf ("a[10]={");
for (i=0; i<10; i++) {
A[i]=i;
printf ("%d,", a[i]);
}
printf ("}");
}
void Test1 () {//input array
int a[5];
printf ("\narray input (just the number in the brackets), look please...\n");
scanf ("%d%d%d%d", &a[0],&a[1],&a[2],&a[3],&a[4]);//can input infinitely but only the first five, the back as a whole. Ignored.
for (int j=0; j<5; J + +) {
printf ("%d,", a[j]);
}
}
void Test2 () {//Bubble Sort method
printf ("\ n Bubble Sort method: \ n");
int a[4]={34,45,12,53};
for (int k=0;k<4; k++) {
for (int l=k+1;l<4; l++) {
if (A[k]<a[l]) {
int temp=a[l];
A[L]=A[K];
A[k]=temp;
}
}printf ("%d,", a[k]);
}
}
void Test3 () {//Sink sort method
printf ("\ n Sink Sort method: \ n");
int a[4]={34,45,12,53};
for (int k=0;k<4; k++) {
for (int l=k+1;l<4; l++) {
if (A[k]>a[l]) {
int temp=a[l];
A[L]=A[K];
A[k]=temp;
}
}printf ("%d,", a[k]);
}
}
void Test4 () {
printf ("\ n macro definition using: \ n");
int b=3;
printf ("%d\n", b*sum);
}
void Test5 () {//two-D array output
printf ("Two-dimensional array output, look here,please...\n");
int a[2][5]={0,1,2,3,4,5,6,7,8,9};
int c[2][5]={{0,1,2,3,4},{5,6,7,8,9}};
for (int i=0; i<2; i++) {
for (int j=0;j<5;j++) {
printf ("a[%d][%d]=%d", I,j,a[i][j]);
}printf ("\ n");
}
}
void Test6 () {
printf ("Two-dimensional array one-dimensional output \ n");
int a[4][4]={{32,3,454,56},{65,67,565,45},{423,343,34,27},{4,5,6,56}};
int i,j = 0;//is not available externally if defined for internal.
for (i=0; i<4; i++) {
for (j=0;j<4;j++) {
printf ("a[%d]=%d", I*4+j,a[i][j]);
}
}
printf ("\na[%d]={", i*j);
for (int i=0; i<4; i++) {
for (int j=0;j<4;j++) {
if (i==3 && j==3) {//Judge to remove the last comma
printf ("%d", a[i][j]);
}
Else
printf ("%d,", a[i][j]);//output comes with an adjacent comma;
}
}
printf ("\b");
printf ("}\n");
}
void Test7 () {//Output alphabetic column length;
Char a[]= "Hello";
printf ("%s\n", a);
printf ("%d\n", (int) sizeof (a));
Char b= ' A ';
printf ("%d\n", (int) sizeof (b));
}
void Test8 () {//known an array int a[100], storing the number is the number of 1~99, there is a duplicate number, find this number.
int a[10]={1,2,3,4,5,6,5,7,8,9};
for (int i; i<10; i++) {
for (int j=i+1; j<10; J + +) {
if (A[i]==a[j]) {
printf ("Number of repetitions:%d\n", A[i]);
}
}
}
}
void Test9 () {//Enter a number to determine if it has been repeated.
int a[10]={1,2,3,4,2,4,5,3,3,9};
int b;
while (1) {
printf ("Insert the number you want to check,please...\n");
scanf ("%d", &b);
int j=0;
for (int i=0; i<10; i++) {
if (a[i]==b) {
j=j+1;
}
}
if (j>=2) {
printf ("%d repeats, repeats to%d\n", b,j);
}
else if (j==1) printf ("%d appears only once \ n", b);
else printf ("%d never appeared, pro", b);
}
}
void Test10 () {//randomly produces 100 number outputs of any pair of the same number.
Srand ((unsigned int) time (0));
int a[100],i,j;
for (int i = 0; i <; i++) {
A[i] = rand ()%100 + 1;
printf ("a[%d]=%d\n", I, a[i]);
}
printf ("Out over.\n");
for (i=0; i<100; i++) {
for (j=i+1; j<100; J + +) {
if (A[i]==a[j]) {
printf ("a[%d]=a[%d]=%d", I,j,a[i]);
}
}printf ("\ n");
}
}
int main (int argc, const char * argv[]) {
printf ("Hello, world!\n");
Test ();
Test1 ();
Test2 ();
Test3 ();
Test4 ();
Test5 ();
Test6 ();
Test7 ();
Test8 ();
Test9 ();
Test10 ();
return 0;
}
C language Array output, bubble sort method, sink sorting method, two-dimensional array output, output alphabetic column length, find duplicates from random array