Compute the sum and product of the numbers from 1 to 10 in CSharp

Description

The following code shows how to compute the sum and product of the numbers from 1 to 10.

Example


using System;  /*from w w w .  j  ava 2  s .com*/
   
public class MainClass {     
  static void Main() {   
    int prod; 
    int sum; 
    int i; 
 
    sum = 0; 
    prod = 1; 
 
    for(i=1; i <= 10; i++) { 
      sum = sum + i; 
      prod = prod * i;       
    } 
    Console.WriteLine("Sum is " + sum); 
    Console.WriteLine("Product is " + prod); 
 
  }   
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var