求[1,n]之间所有不能被3整除的整数之和,n的值由键盘输入。C++程序设计

2024-11-06 07:49:43
推荐回答(3个)
回答(1):

#includeusingnamespacestd;intmul(intn){intm=1;while(n!=0){m=m*n;n--;}returnm;}intmain(){inti=1,n;intsum=0;cout>n;do{sum=sum+mul(i);i++;}while(i<=n);cout<<"sum="<

回答(2):

#include

/* count characters in input; 2nd version */
main()
{
double nc;

for (nc = 0; gechar() != EOF; ++nc)
;
printf("%.0f\n", nc);
}

回答(3):

#include
void main()
{ int i,n,s;
s=0; scanf("%d",&n);
for ( i=1;i<=n;i++ ) if ( i%3 ) s+=i;
printf("%d\n",s);

}