> 🚀write in front🚀
📝个人主页:[认真写博客的夏目浅石.](https://blog.csdn.net/congfen214?spm=1000.2115.3001.5343)
🎁欢迎各位→点赞👍 + 收藏⭐️ + 留言📝
📣系列专栏:[初学者必刷题---鹏哥推荐](https://blog.csdn.net/congfen214/category_12039293.html?spm=1001.2014.3001.5482)
💬总结:希望你看完之后,能对你有所帮助,不足请指正!共同学习交流 🖊
✉️不如沉默去做,看结局怎么去说 ♐
@[TOC](文章目录)
---
## 💡函数篇
**这里先提示一下:
博主不厉害然后只把会的写了,不会的还没写所以就是后面如果我会了,就会补充上去提供给大家学习。**
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/7e19d2d6b2694f61a72667624b22ec84.png)
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/cdafad1038064b41b40abff5642ad848.png)
**2022.12.8号真实的鹏哥推荐题目,下面开刷。**
---
函数篇:
# 6-1 简单输出整数
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/22f7596e81aa40d1939e31e3fdaa5895.png)
```c
void PrintN (int N)
{
for(int i = 1;i <= N;i++)
{
printf("%d\n",i);
}
}
```
# 6-2 多项式求值
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/0b1ed5ddbf9046ba92f8c8fad2056a81.png)
```c
double f( int n, double a[], double x )
{
double s=0.0,x0=1.0;
for(int i=0;i<=n;i++)
{
if(a[i])
s = s + a[i] * x0;
x0 = x0 * x;
}
return s;
}
```
# 6-3 简单求和
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/ebf6fb9410764d79954979b30f785979.png)
```c
int Sum ( int List[], int N )
{
float sum=0;
for(int i=0;i<N;i++)
{
sum=sum+List[i];
}
return sum;
}
```
# 6-4 求自定类型元素的平均
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/17a4d11e690d4e77af16d1b7c715993d.png)
```c
ElementType Average( ElementType S[], int N )
{
double average=0.0,sum=0.0;
for(int i=0;i<=N;i++)
{
sum=sum+S[i];
}
average=sum/N;
return average;
}
```
# 6-5 求自定类型元素的最大值
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/14f2a1ecd8174c4cabe3b09f33958960.png)
```c
ElementType Max( ElementType S[], int N )
{
int max;
for(int i=0;i<N;i++)
{
if(S[i]>S[max])
{
max=i;
}
}
return S[max];
}
```
# 6-7 统计某类完全平方数
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/c5e74d0637754fd78c5a15dfea848456.png)
```c
int IsTheNumber ( const int N )
{
int x,m;
x=(int)sqrt(N);
m=x*x;
if(m==N)
{
int num[10]={0};
while(m>0)
{
for(int i=0;i<=9;i++)
{
if(m%10==i)
{
num[i]+=1;
if(num[i]==2)
{
return 1;
}
}
}
m=m/10;
}
}
return 0;
}
```
```c
在这里插入代码片
```
# 6-8 简单阶乘计算
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/b5079fd986ec421abe63a2a17bea0c37.png)
```c
int Factorial( const int N )
{
int s=1;
if(N>=0)
{
for(int i=1;i<=N;i++)
{
s=s*i;
}
return s;
}
else
return 0;
}
```
# 6-12 判断奇偶性
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/bca0144b9965450d8f1d5fa2887a3296.png)
```c
int even( int n )
{
if(n==0)
{
return 1;
}
if(n<0)
n=-n;
if(n%2==0)
{
return 1;
}
if(n%2!=0)
{
return 0;
}
}
```
## 🎈编程题篇
# 7-1 厘米换算英尺英寸
![`在这里插入图片描述`](https://ucc.alicdn.com/images/user-upload-01/e6190f5100f044f6b193e2cb247a5724.png)
```c
#include<stdio.h>
int main()
{
int n;
int foot;
int inch;
scanf("%d",&n);
foot = n/30.48;
inch =12*(n/30.48-foot);
printf("%d %d",foot,inch);
return 0;
}
```
# 7-2 然后是几点
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/f9d0a34e04164bd695dadcc66c091e22.png)
```c
#include <stdio.h>
int main(){
int t,m;
scanf ("%d %d",&t,&m);
int m2=t%100+t/100*60;
int m3=m+m2;
int t2=m3/60;
int t3=m3%60;
printf ("%d%02d",t2,t3);
return 0;
}
```
# 7-3 逆序的三位数
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/fbee9abae11643409e7f54136334431f.png)
```c
#include<stdio.h>
int main()
{
//输入
int n,i=0,j=0;
scanf("%d",&n);
int arr[3];
//把每一位存放到数组里
while(n)
{
arr[i++]=n%10;
n/=10;
}
//考虑特殊情况
for(i=0;i<3;i++)
{
if(i==0&&arr[i]==0)
{
continue;
}
if(i==1&&arr[i-1]==0&&arr[i]==0)
{
continue;
}
else printf("%d",arr[i]);
}
return 0;
}
```
# 7-4 BCD解密
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/b6de3c9defa24110be30335430a8a820.png)
```c
#include<stdio.h>
int main()
{
int n,a,b;
scanf("%d",&n);
a=n/16;
b=n%16;
printf("%d",a*10+b);
return 0;
}
```
# 7-5 表格输出
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/6816d8042a2546bc988e403658c7c2eb.png)
# 7-6 混合类型数据格式化输入
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/bc1dd79dba534f3b9511218847d4239d.png)
```c
#include<stdio.h>
int main()
{
double a,b;
int c;
char d;
scanf("%lf %d %c %lf",&a,&c,&d,&b);
printf("%c %d %.2lf %.2lf",d,c,a,b);
return 0;
}
```
# 7-7 12-24小时制
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/46604b1d37e24e5d8a97ff809e487481.png)
```c
#include<stdio.h>
int main()
{
int n,m;
char ch;
scanf("%d%c%d",&n,&ch,&m);
if(n<12)
{
printf("%d%c%d AM",n,ch,m);
}
else if(n==12)
{
printf("%d%c%d PM",n,ch,m);
}
else if(n>12)
{
printf("%d%c%d PM",n-12,ch,m);
}
return 0;
}
```
# 7-8 超速判断
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/c53e8ac0a73b4d698628bd17aaf31674.png)
```c
#include "stdio.h"
void check()
{
int n;
scanf("%d",&n);
if(n<=60)
printf("Speed: %d - OK\n",n);
else
printf("Speed: %d - Speeding\n",n);
}
int main()
{
check();
return 0;
}
```
# 7-9 用天平找小球
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/8d2686ecc8704f3bb54f0df103fb154f.png)
```c
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a==b&&a!=c)
{
printf("C");
}
else if(a==c&&b!=a)
{
printf("B");
}
else if(b==c&&a!=c)
{
printf("A");
}
return 0;
}
```
# 7-10 计算工资
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/7dabd4ed21d64554931369c17293f5c4.png)
```c
#include <stdio.h>
int main()
{
float year,time,pay;
scanf("%f %f",&year,&time);
if(5<=year)
{
if(40<time) pay=50*40+(time-40)*50*1.5;
else pay=50*time;
}
else
{
if(40<time) pay=30*40+(time-40)*30*1.5;
else pay=30*time;
}
printf("%.2f",pay);
}
```
# 7-11 分段计算居民水费
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/6c46b17368354d2a9d583359df20827a.png)
```c
#include<stdio.h>
int main()
{
float x,y;
scanf("%f",&x);
if(x<=15)
{
y=4*x/3;
}
else
{
y=2.5*x-17.5;
}
printf("%.2f",y);
return 0;
}
```
# 7-12 两个数的简单计算器
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/9e7d1bbba20946ed9cbe96b57780b8ce.png)
```c
#include <stdio.h>
int main(){
int x1,x2;
char s;
scanf("%d %c %d",&x1,&s,&x2);
switch (s){
case '+':
printf("%d",x1+x2);
break;
case '-':
printf("%d",x1-x2);
break;
case '*':
printf("%d",x1*x2);
break;
case '%':
printf("%d",x1%x2);
break;
case '/':
printf("%d",x1/x2);
break;
default:
printf("ERROR");
}
return 0;
}
```
**这里为啥不写了,因为现在已经快12点了,咱明天继续冲哈,明天更完PTA基础编程题目集**
## 💬我给你挑俩难题,做完就让你嘿嘿嘿~
# 7-32 说反话-加强版
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/88fe1480733a422d9ff687ba944fa7f4.png)
```c
#include<stdio.h>
#include<string.h>
int main()
{
//输入
char arr[500001];
gets(arr);
//思考方法:进行一个计数法来打印空格
int i=0,cnt=0;
for(i=strlen(arr)-1;i>=0;i--)
{
////遇到空格,也就是空出来的,但是没有连续的空格
if(arr[i]==' ' && cnt>0)
{
printf("%s",&arr[i+1]);
if(arr[0] != ' ')
{
printf(" ");
}
arr[i]='\0';
cnt=0;
}
//只有空格的状态(连续空格)
else if(arr[i]==' ')
{
arr[i]='\0';
}
//没有空格且没有结束
else if(arr[i]!=' '&&arr[i]!='\0')
{
cnt++;
}
}
printf("%s\n",&arr[0]);
return 0;
}
```
# 7-24 约分最简分式
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/0b04ac4b28e546c5bc089df0d0e8d2ba.png)
```c
#include<stdio.h>
int gcd(int a,int b) //计算最大公约数---辗转相除法
{
int t;
while(b > 0)
{
t = a % b;
a = b;
b = t;
}
return a;
}
int main()
{
int a,b;
char c;
scanf("%d%c%d",&a,&c,&b);
int d=gcd(a,b);
a=a/d;
b=b/d;
printf("%d%c%d\n",a,c,b);
return 0;
}
```
```c
//递归实现
int gcd(int a,int b)//递归法--->辗转相除法
{
if (b==0)
return a;
int r = a%b;
return gcd(b,r);
}
//普通实现
int gcd(int a,int b) //计算最大公约数---辗转相除法
{
int t;
while(b > 0)
{
t = a % b;
a = b;
b = t;
}
return a;
}
//逗号表达式法emmmm博主见过但是emmm我忘了~
```
**如果大家这俩题不会那~**
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/86256a9a825449a5ac6f7e731b21cf56.png)
**but 如果会的话**
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/c1f2eb7060ce4b68ace899bfb7b6d002.gif)
**那咱进入下一个刷题学习吧hhh~**
今日看到我的博客那我分享一句鹏哥得语录吧,最近也是非常喜欢下课记录语录来学习:**任何人为什么到后期会学的快呢?是因为掌握了方法,触类旁通了,学会一个东西之后,那再学习其他的类似的就会变得快了,不妨碍每一个同学都可以听懂,一定坚持,一定要自信起来,不要着急,日复一日,日复一日得去练。消化理解慢慢来!**
**我是夏目浅石,欢迎和我一起学习进步,刷题无数!**