输入整数a,n,计算a+aa+aaa+.......+aa...a(n个a)相加的和并输出。用c语
#include
void main()
{int i,j,a,n,k=0,out=0;
printf("请输入a与n:");
scanf("%d %d",&a,&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
k=k*10+a;
}
out+=k;
k=0;
}
printf("the result is:%d
",out);
}
或者用楼上的公式
#include
void main()
{int i,a,n,k=1,out;
printf("请输入a与n:");
scanf("%d %d",&a,&n);
for(i=0;i<n+1;i++)
{
k=k*10;
}
out=a*k/81-10*a/81-a*n/9;
printf("the result is:%d
",out );
}
INPUT n,a
s=0
i=1
DO
s=s+a
a=10a+a
i=i+1
LOOP UNTIL i>n
PRINT s
END
其中i是计数变量,这是一个叠加型,直到型循环结构,希望你能看懂!
int main()
{
long a,n,i,j,s;
scanf("%ld",&a);scanf("%ld",&n);
for(i=1,j=1,s=0;i<=n;i++,j=j*10+1)s+=j;
s*=a;printf("%ld\n",s);
return 0;
}
C语言问题。输入2个正整数a和n,求a+aa+aaa+aa……(n个a)之和。例如...
printf()语句最后那个l改成sum。
输入两个整数a和n,计算Sn=a+aa+aaa+aa...a(n个a),用c语言写个程序将这...
格式错误:scanf("%d,%d",a,n);应该是scanf("%d,%d",&a,&n);逻辑错误:a=a+a*10,a的值变了,不再是原先输入的a。修改方法:格式错误按C语言要求的格式修改。逻辑错误引入新的变量k解决。include <stdio.h>int main(){int a,n,k=0,sum=0,i;\/\/定义变量k,并赋初始值0scanf("%d,...
输入2个整数a和n,求a+aa+aaa+……+a(n个a)之和。
long fn(long a,int n);printf("Enter a:");scanf("%d",&a);printf("Enter n:");scanf("%d",&n);sn=0;for(i=1;i<=n;i++)\/***found***\/ sn += fn(a,i);printf("sum=%ld\\n",sn);} long fn(long a,int n){ int i;long tn=0;for(i=1;i<=n;i++){ \/**...
输入2个正整数 a 和 n,求 a+aa+aaa+aa…a(n个a)之和。
include<stdio.h>#include<Windows.h>int main(void){ int a, b, i, n; long sum; int ri, looptimes;printf("请输入循环次数:");scanf("%d",&looptimes);for(i=1;i<=looptimes;i++){sum=0;printf("请输入a,n: ");scanf("%d%d",&a,&n);b=a;printf("sum = %...
...与n(a和n的值都在1之9之间)的值,计算sum=a+aa+aaa+……
include<stdio.h> void main( ){ int i, a, n;float t, sum;printf("a的值n的值:");scanf("%d%d", &a,&n);t=(float)a;sum=(float)a;for( i=2; i<=n; i++) { t=t*10+a;sum=sum+t;} printf("sum=%.0f\\n",sum);} ...
C语言输入两个正数a和n求a+aa+aaa+aaaa+…+aa…a(n个a)之和调用fn(a...
include <stdio.h>int fn(int a, int n){ int sum = a, tem = a; printf("%d", tem); for (int i = 2; i <= n; i++) { tem = tem * 10 + a; printf(" + %d", tem); sum += tem; } return sum;}int main(){ int a, n; ...
编程题:输入两个正整数a,n,求a+aa+aaa+aaaa+aa……a(n个a),要求调用函...
就是编写一个函数fn吧,VB的代码:Function fn(a As Integer, n As Integer) As LongDim i As Integer, tmp As Longtmp = 0For i = 1 To ntmp = tmp + a * (10 ^ i - 1) \/ 9Nextfn = tmpEnd Function
C语言 a+aa+aaa+...
题目:输入两个整数a和n。(1≤n≤14,1≤a≤9),计算 a+aa+aaa+...分析:这里n值达到了14,远超了整数的范围,但未超出double类型数据有效范围,因此,可用double来存储n个a的结果。整形会溢出。实现过程:定义一个double变量da,累加结果变量sum,初始化为0 定义两个整形变量a n用来存储输入...
C语言输入一个数字a和一个整数n,s=a+aa+aaa+aa...a最后一项为n个a计 ...
include <stdio.h>int main (){ int a, n; int t = 0, s = 0; scanf("%d %d", &a, &n); while(n--){ t = t*10+a; s += t; } printf("%d\\n", s); return 0;}
编程计算a+aa+aaa+…+aa…a(n位a)的值,n和a的值由键盘输入
include <stdio.h> include <stdlib.h> int main(){ int n,a,i;int sum,na;printf("Please input n and a:");scanf("%d %d",&n,&a);sum=0;na=a;for(i=1;i<=n;i++){ sum+=na;na=na*10+a;} printf("sum=%d\\n",sum);system("pause");return 0;} ...