关于C语言不会题目的整理集合

June05

#include
#include
void fun(int*p1,int*p2,int*s){
	s = (int*)malloc(sizeof(int));
	*s = *p1 + *(p2++);
}
int main(){
	int a[2] = {1,2},
        b[2] = {10,20},
	      *s = a;
	fun(a,b,s);
	printf("%d\n",*s);

}

//1
#include
#include
static int a = 1;
void fun1(void)
{
	a = 2;
}
void fun2(void)
{
	int a = 3;
}
void fun3(void)
{
	static int a = 2;
}

int main(int argc,char** argv)
{
	printf("%d",a);
	
	fun1(); 
	printf("%d",a);
	
	fun2(); 
	printf("%d",a);
	
	fun3(); 
	printf("%d",a);
}

//1222

June06

#include 

#define ADD( x, y )  x+y
#define TO_STR(x) #x
#define MACRO_2_STR( x ) TO_STR( x )

int main(int argc, char** args){
    printf(MACRO_2_STR( ADD( ADD( 1,000 ), 000 ) ));
    return 0;
}
//1+000+000

June13th

#include 
#include 
#define ARR_LEN 10

void fill_array(int array[], const int len)
{
    int i;
    for (i = 0; i < len; ++i)
        array[i] = rand() % 100;
}

int compare(const void *p_1, const void *p_2)
{
    const int *a_1 = (const int *)p_1;
    const int *a_2 = (const int *)p_2;
                                                       
    return *a_1 < *a_2 ? 1 : (*a_1 == *a_2 ? 0: -1);
}

void print_array(const int array[], const int len)
{
    int i;
    for (i = 0; i < len; ++i)
        printf("%d ", array[i]);
    printf("\n");
}

int main(int argc, char** argv)
{
    int array[ARR_LEN];
    fill_array(array, ARR_LEN);
    printf("排序前:\n");
    print_array(array, ARR_LEN);
    qsort(array, ARR_LEN, sizeof(int), compare);
    printf("排序前:\n");
    print_array(array, ARR_LEN);

    return 0;
}

你可能感兴趣的:(#,C,c语言,c++,算法)