#include<stdio.h> const int N=4; int main() { int a[N]={2,0,2,1}; char b[N]={'2','0','1','1'}; int i; printf("sizeof(int)=%d\n",sizeof(int)); printf("sizeof(char)=%d\n",sizeof(char)); printf("\n"); for(i=0;i<N;++i) printf("%x:%d\n",&a[i],&a[i]); printf("\n"); for(i=0;i<N;++i) printf("%x:%c\n",&b[i],&b[i]); return 0; }
#include<stdio.h> int main() { int a[2][3]={{1,2,3},{4,5,6}}; char b[2][3]={{'1','2','3'},{'4','5','6'}}; int i,j; for(i=0;i<2;++i) for(j=0;j<3;++j) printf("%x:%d\n",&a[i][j],&a[i][j]); printf("\n"); for(i=0;i<2;++i) for(j=0;j<3;j++) printf("%x:%c\n",&b[i][j],&b[i][j]); return 0; }
#include<stdio.h> #define N 1000 int fun(int n, int m, int bb[N]) { int i, j, k = 0, flag; for (j = n; j <= m; j++) { flag = 1; for (i = 2; i < j; i++) if (j % i == 0) { flag = 0; break; } if (flag) bb[k++] = j; } return k; } int main() { int n = 0, m = 0, i, k, bb[N]; scanf_s("%d", &n); scanf_s("%d", &m); for (i = 0; i < m - n; i++) bb[i] = 0; k = fun(n, m, bb); for (i = 0; i < k; i++) printf("%4d", bb[i]); return 0; }
#include <stdio.h> const int N = 5; int find_max(int x[], int n); void input(int x[], int n); void output(int x[], int n); int main() { int a[N]; int max; input(a, N); // 调用input完成数组输入 output(a, N); // 调用output输出数组元素值 max = find_max(a, N); // 调用find_max查找数组a的最大值 printf("max = %d\n", max); return 0; } // 函数定义 // 功能:为数组x的n个元素输入数值 void input(int x[], int n) { int i; for (i = 0; i < n; ++i) scanf("%d", &x[i]); }
#include <stdio.h> void dec2n(int x, int n); // 函数声明 int main() { int x; printf("输入一个十进制整数: "); scanf_s("%d", &x); dec2n(x, 2); dec2n(x, 8); dec2n(x, 16); return 0; } void dec2n(int x, int n) { int i, k = 0, j, m, a[1000]; while (x != 0) { m = x % n; a[k] = m; k++; x = x / n; } for (j = k - 1; j >= 0; j--) { if (a[j] <= 9) printf("%d", a[j]); else switch (a[j]) { case 10:printf("A"); break; case 11:printf("B"); break; case 12:printf("C"); break; case 13:printf("D"); break; case 14:printf("E"); break; case 15:printf("F"); break; } } printf("\n"); }
#include<stdio.h> int main() { int i, j, n; printf("Enter n:"); while (1) { scanf_s("%d", &n); for (j = 1; j <= n; j++) { for (i = 1; i <= n; i++) { if (i <= j) printf("%2d", i); else printf("%2d", j); } printf("\n"); } } return 0; }