1.实现一个函数,打印乘法口诀表,口诀表的行数和列数自己指定,
输入9,输出9*9口诀表,输入12,输出12*12的乘法口诀表。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Fun1(int m)
{
int i,j;
for (i=1;i<=m;i++)
{
for (j=1;j<=i;j++)
{
printf("%d*%d=%d ",i,j,i*j);
if (i == j)
printf("\n");
}
}
return m;
}
int main()
{
int m;
printf("Please putin the num:");
scanf("%d", &m);
Fun1(m);
system("pause");
return 0;
}
2.使用函数实现两个数的交换。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Fun1(int a,int b)
{
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("Output:a=%d,b=%d\n",a,b);
return a,b;
}
int main()
{
int a,b;
printf("Please putin a=");
scanf("%d", &a);
printf("Please putin b=");
scanf("%d", &b);
Fun1(a, b);
system("pause");
return 0;
}
3.实现一个函数判断year是不是润年。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Isleapyear(int year)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
printf("%d is a leap year.\n", year);
}
else
{
printf("%d isn't a leap year.\n", year);
}
}
else
{
if (year % 4 == 0)
{
printf("%d is a leap year\n",year);
}
else
{
printf("%d isn't a leap year\n",year);
}
}
return year;
}
int main()
{
int year;
printf("Please putin the year:");
scanf("%d", &year);
Isleapyear(year);
system("pause");
return 0;
}
4.实现一个函数,判断一个数是不是素数。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Fun1(int m)
{
int i;
for (i=2;i<=m;i++)
{
if (m % i == 0)
{
printf("%d是非素数\n", m);
break;
}
}
if (m == i)
printf("%d是素数\n",m);
return m;
}
int main()
{
int m;
printf("Please putin the num:");
scanf("%d",&m);
Fun1(m);
system("pause");
return 0;
}