计算正整数1~n中的奇数之和及偶数之和
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/11 14:45:13
1.由于a1+a3+a5+…+a(2n+1)=(n+1)a(n+1)=310a2+a4+a6+…+a2n=na(n+1)=300所以a(n+1)=10,n=302.a2+a6+a16=3a1+21d=
#includevoidmain(){intn;ints=0;printf("请输入一个正整数:");scanf("%d",&n);printf("该整数除1和其本身的因子为:\n");for(int
--奇数求和createorreplacefunctionsum_odd(i_numnumber)returnnumberasv_indexnumber(8):=1;v_totalnumber(10)
sum1=0;>>sum2=0;>>fori=1:100if(mod(i,2)==1)sum1=sum1+i;elsesum2=sum2+i;endend>>[sum1sum2]ans=2500255
#include"stdio.h"voidmain(){intsum1=0,sum2=0,i;for(i=1;i
intsum1,sum2,i;//sum1奇数和,sum2偶数和sum1=0;for(i=1;i
{----------根据题目补充已修改----------}programEugene;varm,n,ans:int64;beginreadln(m,n);ans:=0;iftrunc(m)mod2
c语言main(){intn,sum=0;printf("/n请输入一个正整数:");scanf("%d",&n);printf("数列的前n项和是:/n")if(n%2!=0){for(inti=2
额,学的不是VB,首先用N除以2,除的尽就从2开始循环,除不尽就1开始sum一直累加到n,步长为2就可以了.自己对照着换成VB的写法吧.if(条件)i=1;elsei=2;for(i;i
vari,n,x,y,z:longint;beginreadln(n);fori:=1tondobegininc(x,i);ifiand1=1theninc(y,i)elseinc(z,i);end;
#includevoidmain(){intn=10;inti;intjishu=0,oushu=0;for(i=1;i
longsum_ji(intx)//奇数之和{if(x%2==0){x--;}return(long)x*(long)x/4;}longsum_ou(intx)//偶数之和{if(x%2!=0){x-
奇数项之和S1=A1+A3+...+A(2n+1)=96偶数项之和S2=A2+A4+...+A(2n)=80S2-S1=A1+nd=A(n+1)=16S(2n+1)=A1+A2+...+A(2n+1)
#includeintmain(){inti,sum1=0,sum2=0;for(i=12;i
楼上的把循环条件中的n换成n/2,效率更好#includeusingnamespacestd;intmain(intargc,char*argv[]){intn,i,t,sum;cin>>n;i=2;
#includeintmain(){intn,i,x,a=0,b=0;scanf("%d",&n);for(i=1;i
#include"stdio.h"intmain(){inta,sum;while(scanf("%d",&a)&&a){sum=0;while(a){sum+=a%10;a/=10;}printf(
#includeintmain(){intsum=0;intn,i;scanf("%d",&n);for(i=0;i再问:提交时检测显示编译错误再答:#include<stdio.h>&n