1 Star 0 Fork 0

Jellylorry/C语言学习

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
函数 2_8.c 1.56 KB
Copy Edit Raw Blame History
Jellylorry authored 2022-02-08 20:10 +08:00 . 函数学习
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
//练习题
// 1.运用函数,判断一个数是否为素数
//#include <math.h>
//int su_shu_ma(int x)
//{
// for (int t = 2; t <= (sqrt(x) + 1); t++)
// {
// if (x % t == 0)
// return(0);//不是素数
// }
// else
// return(1);//是素数
//}
//
//int main()
//{
// int m = 0;
// printf("输入数字以判断是否为素数:>");
// scanf(" %d", &m);
// int P = su_shu_ma(m);
// if (1 == P)
// printf("%d是素数\n", m);
// else
// printf("%d不是素数\n", m);
// return 0;
//}
////运用函数,判断一个年份是否为闰年
//int run_nian(int x)
//{
// if (((x % 4 == 0) && (x % 100 != 0)) || (x % 400 == 0))
// return 1;//是闰年
// else
// return 0;//不是闰年
//}
//int main()
//{
// int year = 0;
// printf("输入年份以判断是否为闰年\n");
// scanf(" %d", &year);
// int p = run_nian(year);
// if (p == 1)
// printf("%d是闰年\n", year);
// else
// printf("%d不是闰年\n", year);
// return 0;
//}
//3.运用函数,实现有序数组的二分查找
//int cha_zhao(int x, int y[], int z)
//{
// int left = 0;
// int right = z - 1;
// while (left <= right)
// {
// int mid = (left + right) / 2;
// if (x < y[mid])
// right = mid - 1;
// else if (x > y[mid])
// left = mid + 1;
// else
// return mid;//找到了并返回下标
// }
// return -1;//未找到
//}
//int main()
//{
// int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
// int key = 0;
// int sz = sizeof(arr) / sizeof(arr[0]);
// printf("输入数字查找是否在数组内");
// scanf(" %d", &key);
// int p = cha_zhao(key,arr,sz);
// if (-1 == p)
// printf("没找到");
// else
// printf("找到了,下标是%d", p);
// return 0;
//
//}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jellylorry/c-language-learning.git
git@gitee.com:jellylorry/c-language-learning.git
jellylorry
c-language-learning
C语言学习
master

Search