论坛: 编程破解 标题: C++的问题 复制本贴地址    
作者: aa [haizhe]    论坛用户   登录
书上有这么题
大家帮帮忙
s=3+33+333+3333+33333+333333
此处A和N的值都在1->9之间aaa…aaa表示N个A
例如a=3,n=6表达式为
s=3+33+333+3333+33333+333333
谁能帮我把这题写出来呀


[此贴被 aa(haizhe) 在 05月06日12时09分 编辑过]

地主 发表时间: 05/02 13:15

回复: 286 [unique]   版主   登录
int a,n,sum=0,temp=0,i;
scanf("%d,%d",&a,$n);
for (i=0;i<n;i++)
{
temp=temp*10+a;
sum+=temp;
}


B1层 发表时间: 05/04 09:26

回复: michaelpig [michaelpig]   论坛用户   登录
#include<iostream.h>
main()
{int a,n,sum=0,temp;
cin>>a>>n;
for (int i=0;i<n;i++)
{temp=temp*10+a;
sum+=temp;
}
cout<<sum;
}
 


B2层 发表时间: 05/04 22:04

回复: aa [haizhe]   论坛用户   登录
谢谢

B3层 发表时间: 05/06 12:43

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号