打印九九乘法表
#include "stdio.h"
int main()
{
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= i; j++)
{
printf("%d*%d=%d\t", i, j, i * j);
}
printf("\n");
}
}
统计学生信息
#include "stdio.h"
#define MAXSIZE 5
struct student
{
char name[20];
char sex;
unsigned age;
} stu[MAXSIZE];
main()
{
int sta[2][3] = {0};
for (int i = 0; i < MAXSIZE; i++)
{
scanf("%s %c %d", stu[i].name, &stu[i].sex, &stu[i].age);
if (stu[i].sex == 'F')
{
if (stu[i].age <= 29)
sta[0][0]++;
else if (stu[i].age <= 59)
sta[0][1]++;
else
sta[0][2]++;
}
else if (stu[i].sex == 'M')
{
if (stu[i].age <= 29)
sta[1][0]++;
else if (stu[i].age <= 59)
sta[1][1]++;
else
sta[1][2]++;
}
}
printf("男性 0-29岁:%d\t30-59岁:%d\t60岁以上:%d\n", sta[0][0], sta[0][1], sta[0][2]);
printf("女性 0-29岁:%d\t30-59岁:%d\t60岁以上:%d\n", sta[1][0], sta[1][1], sta[1][2]);
}
字符串剔除数字
#include "stdio.h"
#include "string.h"
#define MAXSIZE 100
int main()
{
char str1[MAXSIZE], str2[MAXSIZE] = "\0";
scanf("%s", str1);
for (int i = 0; str1[i] != '\0'; i++)
{
if ('0' >= str1[i] || str1[i] >= '9')
str2[strlen(str2)] = str1[i];
}
printf("%s", str2);
}