字符串逆序
#include <stdio.h>
#include <string.h>
#define N 20
int main()
{
char a[N] = {0};
char ch;
int i,j,n;
printf("Please input a string:");
gets(a);
n = strlen(a);
i = 0;
j = n-1;
while(i < j){
ch = a[i];
a[i] = a[j];
a[j] = ch;
j--;
i++;
}
puts(a);
return 0;
}
矩阵最大值
#include <stdio.h>
int main()
{
int a[3][4] = {{34,45,21,33},{746,213,22,45},{231,442,452}};
int row,column;
int i,j;
row = column = 0;
for(i = 0;i < 3;i++){
for(j = 0;j < 4;j++){
if(a[row][column] < a[i][j])
{
row = i;
column = j;
}
}
}
for(i = 0;i < 3;i++){
for(j = 0;j < 4;j++){
printf("%-4d",a[i][j]);
}
putchar('\n');
}
printf("max = %d %d %d\n",a[row][column],row,column);
return 0;
}
杨辉三角
#include <stdio.h>
int main()
{
int a[10][10] = {{0}};
int i,j;
for(i = 0;i < 10;i++){
a[i][0] = 1;
for(j = 1; j <= i;j++){
a[i][j] = a[i-1][j] + a[i-1][j-1];
}
}
for(i = 0;i < 10;i++){
for(j = 0; j <= i;j++){
printf("%-5d",a[i][j]);
}
putchar('\n');
}
return 0;
}
99乘法表
#include <stdio.h>
int main()
{
int i,j;
for(i = 1;i <= 9;i++){
for(j = 1; j <= i; j++){
printf("%d * %d = %d\t",j,i,j * i);
}
printf("\n");
}
return 0;
}