编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值

编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值

1 #import <Foundation/Foundation.h>


 3 int main(int argc, const char * argv[]) {
 4     @autoreleasepool {
 5         int shu=0,he=0;
 6         for (int i=1; i<=100; i++) {
 7             shu+=i;
 8             he+=shu;
 9             //printf("he is:%d\n",he);
10         }
11         printf("he is:%d\n",he);
12         return 0;
13     }
14 }

执行结果: 

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

时间: 2024-08-27 06:23:49

编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值的相关文章

编写一个程序,用户输入两个数,求出其加减乘除,并用消息框显示计算结果

编写一个程序,用户输入两个数,求出其加减乘除,并用消息框显示计算结果 import javax.swing.JOptionPane; public class Test{ public static void main(String[] args) { int n1=Integer.parseInt(JOptionPane.showInputDialog("Input number 1: ")); int n2=Integer.parseInt(JOptionPane.showInpu

【python】编写一个程序,求100~999之间的所有水仙花数

编写一个程序,求100~999之间的所有水仙花数. 如果一个三位数等于其各位数字的立方和,则称这个数为水仙花数. 例如:153=1^3+5^3+3^3 因此153就是一个水仙花数 代码如下 #水仙花数 for i in range(100, 1000): sum = 0 temp = i while temp: sum = sum + (temp%10)**3 temp //=10 if sum == i: print(i) 原文地址:https://www.cnblogs.com/SiminL

编写一个程序找出100~999之间所有的水仙花数

如果一个3位数等于其各位的立方和,称该数为水仙花数. 如,所以407是一个水仙花数,编写一个程序找出100~999之间所有的水仙花数. 1 #include<stdio.h> 2 #include<stdlib.h> 3 //判断水仙花数,是则返回1 4 int isNarcissus(int n); 5 6 int main() 7 { 8 int i; 9 for(i = 100; i < 1000; i++) 10 if(isNarcissus(i)) 11 print

编写一个程序实现strcpy函数的功能

1 #include <stdio.h> 2 #include <string.h> 3 #define N 5 4 5 6 char *mycpy(char *s1, char *s2) 7 { 8 //数组型 9 /* int i; 10 while(s2[i] != '\0') { 11 s1[i] = s2[i]; 12 i++; 13 } 14 s1[i] = '\0'; 15 return s1; */ 16 //指针型 17 char *p = s1; 18 whil

编写一个程序实现strcmp函数的功能

写自己的strcat函数------→mycmp 1 #include <stdio.h> 2 #include <string.h> 3 #define N 5 4 5 int mycmp(char *s1, char *s2) 6 { 7 //数组型 8 /* int i = 0; 9 while(s1[i] == s2[i] && s1[i] != '\0') { 10 i++; 11 } 12 13 return s1[i] - s2[i]; */ 14 /

c语言:编写一个程序,可以直接接收键盘字符

编写一个程序,可以直接接收键盘字符,如果是小写字符就输出对应的大写字符,如果接收的是大写字符,就输出对应的小写字符,如果是数字不输出. 程序1: #include <stdio.h> int main() { int t = 0; printf("请输入一个字符:"); t = getchar(); if (t >= 'a'&&t <= 'z') { putchar(t-32); } else if(t >= 'A'&&t 

编写一个程序,从标准输入读取几行输入。每行输入都要打印到标准输出上,前面加上行号。

编写一个程序,从标准输入读取几行输入.每行输入都要打印到标准输出上,前面加上行号. 在编写这个程序的时候要使这个程序能够处理的输入行的长度没有限制. #include <stdio.h> #include <stdlib.h> int main() { char ch = '0'; int n = 1; int flag = 1; while (1) { printf("please input the line: "); do { scanf("%c

c语言:编写一个程序,输入a,b,c三个值,输出其中最大者

程序: //编写一个程序,输入a,b,c三个值,输出其中最大者 #include<stdio.h> int main() { int a,b,c,max; printf("请输入三个数:"); scanf("%d,%d,%d",&a,&b,&c); max=a; if (max<b) { max=b; } if (max<c) { max=c; } printf("%d\n",max); retur

编写一个程序实现strcat函数的功能

写自己的strcat函数------→mycat 1 #include <stdio.h> 2 #include <string.h> 3 #define N 5 4 5 char *mycat(char *s1, char *s2) 6 { 7 //数组型 8 /* int i = 0; 9 while(s1[i] != '\0') { 10 i++; 11 } 12 int j = 0; 13 while(s2[j] != '\0') { 14 s1[i] = s2[j]; 1