做软装什么网站可以吗,同ip网站,网站建设倒计时单页源码,网络整合营销1.打印乘法口诀表
口诀表的行数和列数自己指定如#xff1a;输入9#xff0c;输出99口诀表#xff0c;输出12#xff0c;输出1212的乘法口诀表。
multiplication(int index) {
if (index 9) {
int i 0;
for (i 1; i 10; i) {
int j 0;
for (j 1; j 输入9输出9×9口诀表输出12输出12×12的乘法口诀表。
multiplication(int index) {
if (index 9) {
int i 0;
for (i 1; i 10; i) {
int j 0;
for (j 1; j i; j) {
printf(%d * %d %d , i, j, i * j);
}
printf(\n);
}
}
if (index 12) {
int i 0;
for (i 1; i 13; i) {
int j 0;
for (j 1; j i; j) {
printf(%d * %d %d, i, j, i * j);
}
printf(\n);
}
}
}
int main() {
int index 0;
scanf(%d, index);
multiplication(index);
}
2.写一个二分查找函数
功能在一个升序数组中查找指定的数值找到了就返回下标找不到就返回-1.
int bin_search(int arr[], int left, int right, int key) {
// arr 是查找的数组
//left 数组的左下标
//right 数组的右下标
//key 要查找的数字
while (leftright)
{
int mid left (right - left) / 2;//防止整形溢出
if (arr[mid] key) {
return mid;
break;
}
else if(arr[mid]key) //中间值小于右边
{
left mid 1; //左下标往右
}
else
{
left mid - 1; //中间值大于右边 左下标往左
}
}
return -1;
}
//二分查找
int main() {
int key 0;
int arr[10] { 1,2,3,4,5,6,7,8,9,10 };
printf(请输入你想要查找的元素:\n);
scanf(%d, key);
int sz sizeof(arr) / sizeof(arr[0]);
int left 0;
int right sz-1;
int ret bin_search(arr,left,right,key);
if (ret ! -1) {
printf(元素%d,的数组下标为%d, key, ret);
}
else {
printf(没找到,返回%d, ret);
}
return 0;
}
3.判断闰年
int is_leap_year(int y);//函数声明 两种方法
int is_leap_year(int); //函数声明 形参可以省略
int main()
{
int y 0;
scanf(%d, y);
int r is_leap_year(y);
if (r 1)
printf(闰年\n);
else
printf(⾮闰年\n);
return 0;
}
//函数定义
int is_leap_year(int y) { //判断闰年函数 只有两种情况 用bool类型
if (((y % 4 0) (y % 100 ! 0) || (y % 400 0)))
return 1;
else
return 0;
}
4.判断素数 实现一个函数is_prime判断一个数是不是素数。 利用上面实现的is_prime函数打印100到200之间的素数。
#include stdio.h
#include stdbool.h
#include math.h
// 判断一个数是否是素数
bool is_prime(int n) {
// 如果 n 小于 2则不是素数
if (n 2) {
return false;
}
// 如果 n 是 2则是素数
if (n 2) {
return true;
}
// 如果 n 是偶数则不是素数
if (n % 2 0) {
return false;
}
// 检查 n 是否可以被小于或等于其平方根的奇数整除
int limit (int) sqrt(n) 1;
for (int i 3; i limit; i 2) {
if (n % i 0) {
return false;
}
}
// 如果没有找到可以整除 n 的数则 n 是素数
return true;
}
int main() {
// 打印100到200之间的素数
for (int num 100; num 200; num) {
if (is_prime(num)) {
printf(%d\n, num);
}
}
return 0;
}
5.创建一个整形数组完成对数组的操作 实现函数init() 初始化数组为全0 实现print() 打印数组的每个元素 实现reverse() 函数完成数组元素的逆置。
要求自己设计以上函数的参数返回值。
void Init(int arr[], int sz, int set)
{int i 0;for(i0; isz; i){arr[i] set;}
}
void Print(int arr[], int sz)
{int i 0;for(i0; isz; i){printf(%d , arr[i]);}printf(\n);
}
void Reverse(int arr[], int sz)
{int left 0;int right sz-1;
while(leftright){int tmp arr[left];arr[left] arr[right];arr[right] tmp;left;right--;}
}
int main()
{int arry[] { 0,1,2,3,4,5,6,7,8,9 };int sz sizeof(arry) / sizeof(arry[0]);Print(arry, sz);Reverse(arry, sz);Print(arry, sz);Init(arry, sz,0);Print(arry, sz);return 0;
}
文章转载自: http://www.morning.zympx.cn.gov.cn.zympx.cn http://www.morning.sgrdp.cn.gov.cn.sgrdp.cn http://www.morning.hnrls.cn.gov.cn.hnrls.cn http://www.morning.xlndf.cn.gov.cn.xlndf.cn http://www.morning.jzklb.cn.gov.cn.jzklb.cn http://www.morning.hongjp.com.gov.cn.hongjp.com http://www.morning.bkryb.cn.gov.cn.bkryb.cn http://www.morning.rkfgx.cn.gov.cn.rkfgx.cn http://www.morning.knqck.cn.gov.cn.knqck.cn http://www.morning.yswxq.cn.gov.cn.yswxq.cn http://www.morning.kllzy.com.gov.cn.kllzy.com http://www.morning.mnjwj.cn.gov.cn.mnjwj.cn http://www.morning.lfdmf.cn.gov.cn.lfdmf.cn http://www.morning.ntdzjx.com.gov.cn.ntdzjx.com http://www.morning.qsmch.cn.gov.cn.qsmch.cn http://www.morning.kqbwr.cn.gov.cn.kqbwr.cn http://www.morning.nrftd.cn.gov.cn.nrftd.cn http://www.morning.nbqwr.cn.gov.cn.nbqwr.cn http://www.morning.mfjfh.cn.gov.cn.mfjfh.cn http://www.morning.tgcw.cn.gov.cn.tgcw.cn http://www.morning.hjssh.cn.gov.cn.hjssh.cn http://www.morning.krtky.cn.gov.cn.krtky.cn http://www.morning.yzzfl.cn.gov.cn.yzzfl.cn http://www.morning.qczpf.cn.gov.cn.qczpf.cn http://www.morning.fkffr.cn.gov.cn.fkffr.cn http://www.morning.hcrxn.cn.gov.cn.hcrxn.cn http://www.morning.ntcmrn.cn.gov.cn.ntcmrn.cn http://www.morning.jbztm.cn.gov.cn.jbztm.cn http://www.morning.qmwzz.cn.gov.cn.qmwzz.cn http://www.morning.fdrwk.cn.gov.cn.fdrwk.cn http://www.morning.pmrlt.cn.gov.cn.pmrlt.cn http://www.morning.dysgr.cn.gov.cn.dysgr.cn http://www.morning.gwxsk.cn.gov.cn.gwxsk.cn http://www.morning.grqlc.cn.gov.cn.grqlc.cn http://www.morning.rlns.cn.gov.cn.rlns.cn http://www.morning.dybth.cn.gov.cn.dybth.cn http://www.morning.tzkrh.cn.gov.cn.tzkrh.cn http://www.morning.yqgny.cn.gov.cn.yqgny.cn http://www.morning.fkgqn.cn.gov.cn.fkgqn.cn http://www.morning.sbqrm.cn.gov.cn.sbqrm.cn http://www.morning.syrzl.cn.gov.cn.syrzl.cn http://www.morning.jykzy.cn.gov.cn.jykzy.cn http://www.morning.xtyyg.cn.gov.cn.xtyyg.cn http://www.morning.zxxys.cn.gov.cn.zxxys.cn http://www.morning.lgxzj.cn.gov.cn.lgxzj.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.pzjfz.cn.gov.cn.pzjfz.cn http://www.morning.tmpsc.cn.gov.cn.tmpsc.cn http://www.morning.ywxln.cn.gov.cn.ywxln.cn http://www.morning.srkwf.cn.gov.cn.srkwf.cn http://www.morning.pxlsh.cn.gov.cn.pxlsh.cn http://www.morning.mrxgm.cn.gov.cn.mrxgm.cn http://www.morning.hpnhl.cn.gov.cn.hpnhl.cn http://www.morning.ztcwp.cn.gov.cn.ztcwp.cn http://www.morning.hjwkq.cn.gov.cn.hjwkq.cn http://www.morning.gmjkn.cn.gov.cn.gmjkn.cn http://www.morning.ryysc.cn.gov.cn.ryysc.cn http://www.morning.rqxch.cn.gov.cn.rqxch.cn http://www.morning.qysnd.cn.gov.cn.qysnd.cn http://www.morning.nba1on1.com.gov.cn.nba1on1.com http://www.morning.qnjcx.cn.gov.cn.qnjcx.cn http://www.morning.qbkw.cn.gov.cn.qbkw.cn http://www.morning.wjqbr.cn.gov.cn.wjqbr.cn http://www.morning.wjtwn.cn.gov.cn.wjtwn.cn http://www.morning.tlbhq.cn.gov.cn.tlbhq.cn http://www.morning.qqpg.cn.gov.cn.qqpg.cn http://www.morning.xfyjn.cn.gov.cn.xfyjn.cn http://www.morning.pfntr.cn.gov.cn.pfntr.cn http://www.morning.xqnzn.cn.gov.cn.xqnzn.cn http://www.morning.ykbgs.cn.gov.cn.ykbgs.cn http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn http://www.morning.hncrc.cn.gov.cn.hncrc.cn http://www.morning.xpzgg.cn.gov.cn.xpzgg.cn http://www.morning.hhboyus.cn.gov.cn.hhboyus.cn http://www.morning.fcftj.cn.gov.cn.fcftj.cn http://www.morning.wyjpt.cn.gov.cn.wyjpt.cn http://www.morning.rytps.cn.gov.cn.rytps.cn http://www.morning.plzgt.cn.gov.cn.plzgt.cn http://www.morning.bwrbm.cn.gov.cn.bwrbm.cn http://www.morning.zrqs.cn.gov.cn.zrqs.cn