Mega Code Archive

 
Categories / C# / Language Basics
 

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

/* C#: The Complete Reference  by Herbert Schildt  Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // Compute the sum and product of the numbers from 1 to 10.     using System;       public class ProdSum {      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);      }    }