#include <stdio.h>
double ari_sum(double start, double delta, int n) {
// 请在此处编写代码
double sum = 0;
int i = 0;
double item = start;
for(;i<n;i++){
sum+=item; // 求和,再求下一项
item += delta; //直接赋值第一项,然后求出第二项,再次进入循环时直接使用的二项
// 求出接着求第三,4567项
}
return sum;
}
int main () {
double res = ari_sum(0.1, 0.2, 3);
printf("%f",res);
return 0;
}
#include <stdio.h>
int common_multiple (int number1, int number2) {
// 请在此处编写子函数代码
int multiple;
for(multiple=1;;multiple++){
if(multiple%number1==0 && multiple%number2 == 0){
break; //❗这里可以直接break
}
}
return multiple;
}
int main () {
int multiple, number1 = 24, number2 = 16;
multiple = common_multiple(number1, number2);
printf("%d", multiple);
return 0;
}
#include <stdio.h>
void convert(int n)
{
int i;
if ((i=n/10) ! = 0)
convert(i);
putchar(n % 10 +'0');
}
int main(){
int number;
scanf("%d", &number);
if (number < 0)
{
putchar('-');
number = -number;
}
convert(number);
return 0;
}
#include<stdio.h>
int salary(int n) {
int s;
if(n==1)
s=3100;
else
s=salary(n-1)+500;
return s;
}
int main() {
printf("sarary:%d\n", salary(5));
return 0;
}
#include <stdio.h>
int fact (int n) {
//请在此处编写子函数代码
if(n == 1)
return 1;
else
return n*fact(n-1);
}
int factsum (int n) {
//请在此处编写子函数代码
if(n == 1)
return fact(n);
else
return fact(n) + factsum(n-1);
}
int main () {
int n = 10;
int sum;
sum = factsum(n);
printf("%d", sum);
return 0;
}