大学程序实验.C语言.函数进阶汇总.函数求和.人民币面额置换问题.筛选水仙花数
- 0 目录
- 3 函数进阶汇总
- 3.1 函数求和
- 3.1.1 题目
- 3.1.2 源码
- 3.1.3 下载
- 3.2 人民币面额置换问题
- 3.2.1 题目
- 3.2.2 源码
- 3.2.3 下载
- 3.3 筛选水仙花数(基本)
- 3.3.1 题目
- 3.3.2 源码
- 3.3.3 下载
- 2 下一章
0 目录
3 函数进阶汇总
3.1 函数求和
3.1.1 题目
函数求和:输入控制参数a,i,a为基数,i为迭代次数,经过i次迭代,求出所有迭代数之和
3.1.2 源码
// c82.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
int main()
{
int a;
int i;
int n;
float sum;
sum=0;
//
scanf("%d",&a);
scanf("%d",&i);
//
for(n=1;n<=i;n++)
{
sum=sum+a;
a=a*10+a;
}
//
printf ("%.1f\n",sum);
return 0;
}
3.1.3 下载
链接地址: .CPP
3.2 人民币面额置换问题
3.2.1 题目
编写程序:输入金额,将金额用10元,5元,1元表示,并打印,输出分别需要的面额张数
3.2.2 源码
// c8.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
void main()
{
int a;
int b;
int c;
int n;
//
printf("输入一个面额:");
scanf("%d",&n);
//
for (a=0;a<=10;a++)
{
for (b=0;b<=20;b++)
{
for(c=0;c<=100;c++)
{
if(c>0)
{
if (10*a+5*b+1*c==n)
{
printf("10元:%d\n5元:%d\n1元:%d\n",a,b,c);
}
}
}
}
}
}
3.2.3 下载
链接地址: .CPP
3.3 筛选水仙花数(基本)
3.3.1 题目
筛选出1000以内的水仙花数(科普:水仙花数即这个数字各个位上的数的立方之和等于该数本身,例如:153=13+53+3^3,算一算是不是:)~)
3.3.2 源码
// c83.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
int main()
{
int a;
int g;
int s;
int b;
int sum;
//
for(a=100;a<1000;a++)
{
g=a%10;
s=(a/10)%10;
b=a/100;
sum=g*g*g+s*s*s+b*b*b;
if(sum==a)
{
printf("%d\n",sum);
}
}
return 0;
}
3.3.3 下载
链接地址: .CPP
2 下一章
博客地址: