bshy.net
当前位置:首页>>关于编写程序.输入任意整数n,计算1到n的奇数和的资料>>

编写程序.输入任意整数n,计算1到n的奇数和

因为你没说用什么语言实现,所以我就用个C语言实现了 #include int main(){ int n,sum=0; scanf("%d", &n); for (int i=1; i

解题思路:循环判断1到N的每一个数; 若除以2是结果为整数,也就是能被2整除,那么是偶数; 若除以2结果不是整数,则不能被2整除,那么是奇数; 是奇数的话,把它加到和里;注意事项:这样做应该,long double 以内的数据应该不会有错,数的范围更...

main() { int i,n,sum=0; scanf("%d",&n); n*=2; for(i=1;i

望采纳! #include void main() { int i,n; int result1=0,result2=0; printf("请输入n:"); scanf("%d",&n); for(i=0; i

#include int main(){ int sum = 0; int n,i; scanf("%d",&n); for(i=0;i

//#include "stdafx.h"//If the vc++6.0, with this line.#include using namespace std;int main(int argc,char *argv[]){ int n,i,s; cout > n) || n

//java写的import java.util.Scanner;public class OodSum {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("输入n的值:");int n = sc.nextInt();int sum = 0;for(int i = 1;i

#!/bin/bashsum=0for((i=1;i

Private Sub Command1_Click() Dim n As Integer Dim s As Double s = 0 n = Val(Text1.Text) For i = 1 To n If i Mod 2 = 1 Then s = s + i Next i Text3.Text = sEnd SubPrivate Sub Command2_Click() Dim n As Integer Dim s As Double s = ...

C可以这么写: #include "stdio.h"int main(void){ int n; while(1){ printf("Input n(int n>0)...\nn="); if(scanf("%d",&n) && n>0){ n-=!(n&1); printf("The result is %d\n",(1+n)/2*(n/2+1)); break; } printf("Error, must be n>0: "); ff...

网站首页 | 网站地图
All rights reserved Powered by www.bshy.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com