博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
函数编程的练习
阅读量:4116 次
发布时间:2019-05-25

本文共 1416 字,大约阅读时间需要 4 分钟。



1.实现一个函数,打印乘法口诀表,口诀表的行数和列数自己指定,输入9,输出9*9口诀表,输出12,输出12*12的乘法口诀表。

#include
#include
#pragma warning(disable:4996)int showMaltable(int n){ int i, j; for (i = 1; i <= n; i++) { printf(" "); for (j = 1; j <= i; j++) { printf("%d*%d=%d", i, j, i*j); printf(" "); } printf("\n"); } return i*j;}int main(){ int n; scanf("%d", &n); showMaltable(n); system("pause"); return 0;}
运行结果如下:

2.使用函数实现两个数的交换。

#include
#include
#pragma warning(disable:4996)int get_value(int *x, int *y){ *x = *x^*y; *y = *x^*y; *x = *x^*y; return *x, *y;}int main(){ int x; int y; scanf("%d%d", &x, &y); get_value(&x,&y); printf("%d %d\n", x, y); system("pause"); return 0;}

3.实现一个函数判断year是不是润年。

#include
#include
#pragma warning(disable:4996) #include
int isleapYear(int year){ if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { return 1; } return 0;}int main(){ int year=1000; for (year = 1000; year <= 2000; year++) { if (isleapYear(year)) { printf("%d ", year); } } system("pause"); return 0;}

4.写一个函数判断是不是素数。

#include
#include
#pragma warning(disable:4996) #include
int primenumber(int i){ int j = 2; for (j = 2; j <= sqrt(i); j++) { if (i%j == 0) { return 0; break; } else{ return 1 ; } }}int main(){ int i; scanf("%d", &i); i=primenumber(i); printf("%d", i); system("pause"); return 0;}

你可能感兴趣的文章
python实现100以内自然数之和,偶数之和
查看>>
python数字逆序输出及多个print输出在同一行
查看>>
ESP8266 WIFI数传 Pixhaw折腾笔记
查看>>
苏宁产品经理面经
查看>>
百度产品经理群面
查看>>
去哪儿一面+平安科技二面+hr面+贝贝一面+二面产品面经
查看>>
element ui 弹窗在IE11中关闭时闪现问题修复
查看>>
vue 遍历对象并动态绑定在下拉列表中
查看>>
Vue动态生成el-checkbox点击无法选中的解决方法
查看>>
python __future__
查看>>
MySQL Tricks1
查看>>
python 变量作用域问题(经典坑)
查看>>
pytorch
查看>>
pytorch(二)
查看>>
pytorch(三)
查看>>
pytorch(四)
查看>>
pytorch(5)
查看>>
pytorch(6)
查看>>
ubuntu相关
查看>>
C++ 调用json
查看>>