大學程式實驗.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;
}