(C syntax) Calculate the sum of 1 + 2 + 3 + 4... + n, 4...

Source: Internet
Author: User

(C syntax) Calculate the sum of 1 + 2 + 3 + 4... + n, 4...

Knowledge point:

For (;) loop usage

S + = I

 

Content: calculates the sum of 1 + 2 + 3 + 4... + n

Input description:

An integer n

Output description:

And

 

Input example:

100

Output example:

5050

 

#include <stdio.h>int main(){ int n,i,sum=0; scanf("%d",&n); for (i=0;i<=n;i++) {  sum+=i; } printf("%d\n",sum); return 0;}

 


C language programming: Calculate the sum of all numbers in a positive integer N. For example, if you enter 1234, the value of 1 + 2 + 3 + 4 is calculated.

# Include <iostream. h>
# Include <math. h>
Void main ()
{
Int a, t, m, sum = 0;
Cout <"enter a positive number :";
Cin>;
For (int I = 0; I <= 10; I ++)
{
M = pow (10, I );
T = a/m % 10;
Sum = sum + t;
}

Cout <sum <endl;
}

1st math question! A = 19, B =-4, C =-21, which is the value of-a-B-c? Calculate 1 + (-2) + 3 + (

-19-4-(-21) =-23 + 21 =-2
1 + 2-3 + 4-5 + 6-7 + 8-9.......-97 + 98-99 + 100 = 1 + (2-3) + (4-5) + (6-7) + (8-9 )..... (96-97) + (98-99) + 100 = 1-1-1-1-1.....-1-1 + 100 = 101-49 = 52 (49 is a division of 1,100, 98 are left, two in one group, 98/2 = 49 groups in total)
Ordinary paper cannot be folded for 10 times in a row. It can be up to eight or nine times. If it reaches 10 times, the thickness should be 204.8mm.
Split X times, X power of 2 = 16, X = 4, split 4 times, one and a half hours, total 2 hours
2 pieces of dough (1 time) 2x2 = 4 (2 times) 4x2 = 8 (3 times) 8x2 = 16 (4 times) 16*2 = 32 (5 times) 32*2 = 64 (6 times) 64*2 = 128 (7 times) 128*2 = 256 (8 times) 256*2 = 512 (9 times) 512*2 = 1024 (10 times)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.