Sum integers in for statement : For statement « Statement « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C / ANSI-C
C++
C++ Tutorial
Visual C++ .NET
C Tutorial » Statement » For statement 
6.6.6.Sum integers in for statement
#include <stdio.h>

int main(void)
{
  long sum = 0L;
  int count = 0;

  
  printf("\nEnter the number of integers you want to sum: ");
  scanf(" %d", &count);

  
  for (int i = ; i<= count ; sum += i++ );

  printf("\nTotal of the first %d numbers is %ld\n", count, sum);
  return 0;
}
Enter the number of integers you want to sum: 112
     
     Total of the first 112 numbers is 6328
6.6.For statement
6.6.1.for LOOP
6.6.2.Omit all three parts in for loop
6.6.3.The for loop with a comma operator
6.6.4.Initialize loop control variable outside the for statement
6.6.5.Use for loop to print a rectangle
6.6.6.Sum integers in for statement
6.6.7.for loop backward
6.6.8.indefinite loop: empty for
6.6.9.Nest if statement in for loop
6.6.10.Nest for loop: two different control variables
6.6.11.Use char variable to control for loop
6.6.12.Continue a for loop
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.