#include<stdio.h>intmain()int a,n;scanf("%d%d",&a,&n);int s =0,sum =0;for(int i =1;i<=n;i++)
s = s*10+a;
sum += s;printf("s = %d",sum);
1-7-5 成绩统计分析表
#include<stdio.h>voidPrint_s(double i)//把打印*封装成一个函数,方便int n =(int)floor(i+0.5);//四舍五入for(int j =0;j<n;j++)printf("*");intmain()int n;scanf("%d",&n);double arr[1000]=0.0;double sum =0.0,max =0.0,min =1000.0,avg;int a=0,b=0,c=0,d=0,e=0;for(int i =0; i < n; i++)scanf("%lf",&arr[i]);
sum += arr[i];if(arr[i]>max)
max = arr[i];if(arr[i]<min)
min = arr[i];if(arr[i]>=90&&arr[i]<=100)
a++;elseif(arr[i]>=80&&arr[i]<90)
b++;elseif(arr[i]>=70&&arr[i]<80)
c++;elseif(arr[i]>=60&&arr[i]<70)
d++;elseif(arr[i]>=0&&arr[i]<60)
e++;for(int i =0; i < n; i++)printf("%03d:%6.1lf ", i+1, arr[i]);Print_s(arr[i]);printf("\\n");
avg = sum / n;printf("\\nMax: %5.1lf ",max);Print_s(max);printf("\\nMin: %5.1lf ",min);Print_s(min);printf("\\nAvg: %5.1lf ",avg);Print_s(avg);printf("\\n");double A =100.0*a/n,B=100.0*b/n,C =100.0*c/n,D =100.0*d/n,E =100.0*e/n;//printf里打印一个百分号“%”要写两个:%%printf("\\nA:%6.1lf%%",A);printf(" ");Print_s(A);printf("\\nB:%6.1lf%%",B);printf(" ");Print_s(B);printf("\\nC:%6.1lf%%",C);printf(" ");Print_s(C);printf("\\nD:%6.1lf%%",D);printf(" ");Print_s(D);printf("\\nE:%6.1lf%%",E);printf(" ");Print_s(E);return0;
1-7-6 换硬币
#include<stdio.h>intmain()int x =0;scanf("%d",&x);int f5 =0, f2 =0, f1 =0;int count =0;for(int i = x/5;; i--)
f5 = i;for(int j =(x-5*f5)/2;; j--)
f2 = j;
f1 = x -5* f5 -2* f2;if(f2 ==0)break;if(f1 <=0)continue;printf("fen5:%d, fen2:%d, fen1:%d, total:%d\\n", f5, f2, f1, f1 + f2 + f5);
count++;if((f5 ==1))printf("count = %d\\n", count);break;return0;
1-7-7 验证“哥德巴赫猜想”
#include<stdio.h>#include<math.h>intPrime(longlong i)int c =0;for(longlongint j =2;j<=sqrt(i);j++)if(i%j==0)return0;return1;intmain()longlongint n;scanf("%lld",&n);for(longlongint i =2;i<n;i++)if(Prime(i)&&Prime(n-i))printf("%lld = %lld + %lld",n,i,n-i);break;elsecontinue;return0;
C博客作业--指针
一、PTA实验作业
题目1:字符串串动变化
1. 本题PTA提交列表
2. 设计思路
3.代码截图
4.本题调试过程碰到问题及PTA提交列表情况说明
一开始写成了这样
小细节导致错误,认真读了一遍代码后解决
题目2:求子串在母串中最后一次出现的地址
1.本题PTA提交列表
2. 设计思路
int i,k=0,flag=0,count=0,count判断是否有子串,flag记录子串出现的下标
for i=0 to s[i]!=\'\\0\'
k=0
for j=o to t[k]!=\'\\0\'
如果s[j]!=t[k] 不为子串的话
break
k++
如果t[k]==\'\\0\'即为子串的话
flag=i 记下下标
count=1 存在子串
如果count!=0 存在子串
t=&s[flag] t为子串在母串中最后一次出现的地址
return t
否则 return 0