高级乘法口诀表
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void mul(int row,int col) {
int x=0;
printf(“请输入一个正整数:”);
scanf("%d", &x);
for (row = 1; row <= x; ++row) {
for (col = 1; col <= row; ++col) {
printf("%d*%d=%d “, row, col, row*col);
}
printf(”\n");
}
}
int main() {
int x = 0,y=0;
mul(x,y);
return 0;
}
是否是润年
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void jud(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
printf(“是润年”);
}
else {
printf(“不是润年”);
}
}
int main() {
int year = 0;
printf(“请输入一个年份:”);
scanf("%d", &year);
jud(year);
return 0;
}
交换两个值
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void exchange(int *a, int *b) {
int tmp = 0;
tmp = *a, *a = *b, *b = tmp;
}
int main() {
int a = 0, b = 0;
printf(“请输入两个数”);
scanf("%d %d", &a, &b);
exchange(&a, &b);
printf("%d %d", a, b);
return 0;
}
#include<stdio.h>
#include<string.h>
//初始化数组
void init(int data[], int in[], int n) {
int i;
for (i = 0; i < n; ++i) {
data[i] = in[i];
printf("%d", data[i]);
}
printf("\n");
}
//清空数组
void empty(int data[],int n) {
int i;
for (i = 0; i< n; ++i) {
data[i] = 0;
printf( “%d”, data[i]);
}
printf("\n");
}
//逆置
void reverse(int data[],int n) {
int tmp;
int i, j;
for (i = 0, j = n - 1; i < j; ++i, --j) {
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
for (int i = 0; i < 5; ++i) {
printf("%d", data[i]);
}
printf("\n");
}
int main() {
int arr[5], arr1[5] = { 5, 4, 3, 2, 1 };
init(arr, arr1, 5);
reverse(arr1, 5);
empty(arr1, 5);
return 0;
}
是否素数
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void IsPrime(int x) {
int i = 2;
if (x > 2) {
for (; i < x; ++i) {
if (x%i == 0) {
printf(“不是素数\n”);
break;
}
else {
printf(“是素数”);
break;
}
}
}
else {
printf(“您的输入有误”);
}
}
int main() {
int x = 0;
printf(“请输入一个整数”);
scanf("%d", &x);
IsPrime(x);
return 0;
}