//1. 设计函数原型,不需要返回值,参数N表示乘法口诀表总共有多少行//2. 设定两个循环,外层循环控制总共有多少行//内层循环控制每行有多少个表达式voidmul_table(int n){int i =0;int j =0;for( i =1; i <= n; i++){for( j=1; j<= i; j++){printf("%2d*%2d=%3d ", i, j,i*j);}printf("\n");}return0;}intmain(){int n =0;scanf("%d",&n);mul_table(n);return0;}
函数实现交换两个整数
voidchange(int*a,int*b){int t =0;
t =*a;*a =*b;*b = t;}intmain(){int* a =0;int* b =0;scanf("%d %d",&a,&b);printf("交换前%d %d\n", a, b);change(&a,&b);printf("交换后%d %d\n", a, b);return0;}
实现函数判断year是不是润年
#include<stdio.h>#include<stdbool.h>
bool is_leap_year(int year)//用布尔类型来返回,是闰年返回为真,否则为假{return(((year %4==0)&&(year %100!=0)|| year %400==0));}intmain(){int year =0;scanf("%d",&year);is_leap_year(year);if(is_leap_year(year)){printf("是闰年\n");}elseprintf("补是闰年\n");return0;}
intis_prime(int n){int i =0;for(i =2; i <=sqrt(n); i++){if(0== n % i){return0;}}return1;}intmain(){int i =0;for(i =100; i <=200; i++){if(is_prime(i)==1){printf("%d ", i);}}return0;}