C Sharp

1. An Overview of C# 2. OOP 3. C# Environment 4. IDE 5. Basic Requirement 6. Comments 7. My first program 8. Line Break 9. Escape Sequence 10. Identifiers 11. Variables 12. Datatypes 13. Range of datatypes in C# 14. Declare Variables 15. Reserved Key Words 16. Console.Write() 17. Chained & Embedded state 18. Prog.to print sum of 2 nos 19. Console.ReadLine() 20. Prg.to print sum & average 21. Area & Perimeter of Rectangle 22. Area Circumference of Circle 23. Prg.for Simple Calculator 24. Operatos in C# 25. Ex. Of Operators 26. Prg. to Swap two numbers 27. Hierarchy of Operators 28. if( ) statement 29. Prg.to check +ve,-ve or zero 30. if..else statement 31. Prg.to check Odd or Even 32. Prg.to print larger of 2 nos 33. Prg.to print largest of 3 nos 34. Prg.to check divisibility 35. Prg.to check print range 36. for. . . loop statement 37. prg.to print series of nos 38. Prg.to check divisibility 39. prg.to print sum of series 40. Prg.to print Pyramid 41. prg.for Factorial 42. prg.to fill screen 43. prg.for largest/smallest no 44. prg.to print reverse no 45. prg.to add each digit 46. prg.for sum of Factorial 47. prg.for fibonacci series 48. prg.to check Prime nos 49. prg. Prime no from 1 to 100 50. prg.Specified Prime nos 51. while( ) statement 52. do. . While statement 53. goto statement 54. break & continue statement 55. switch case statement 56. Array in C# 57. print reverse order using array 58. Ascending/Descending order 59. prg.to search no in Array 60. Multidimensional arrays 61. String in C# 62. String with spaces 63. prg.to print string in reverse 64. prg.to count A,E,I,O,U vowel 65. User Define Methods 66. Methods program example 67. General Purpose Programs 68. Loan & EMI calculation prg. 69. Table print prg. 70. Leap year program 71. lower to UPPER case prg. 72. Age Distribution prg. 73. Bank note calculation prg. 74. Simple Interest prg. 75. Compound Interest prg. 76. Simple Depreciation prg. 77. Reducing bal.Depreciation prg. 78. Marksheet prg. 79. Income Tax prg. 80. Time calculator prg. 81. Distance converter prg. 82. Volume Air Calculation prg. 83. Time to fill Water Tank prg. 84. Salary Calculation prg. 85. Total Sale Calculation prg. 86. Male/Female pecentage prg. 87. Library Rent prg. 88. Office Expance prg. 89. Total Salary Calculation prg. 90. Profit or Loss prg. 91. Total Profit/Loss prg. 92. Virtual Function . 93. C# Interview Part1 94. C# Interview Part2 95. C# Interview Part3 96. C# Interview Part4 97. C# Interview Part5 98. C# Interview Part6 99. C# Interview Part7 100. C# Interview Part8 101. C# Interview Part9 102. C# Interview Part10 103. C# Interview Part11 104. C# Interview Part12 105. C# Interview Part13 106. C# Interview Part14 107. C# Interview Part15
Pr.Pg Next Pg

Program to Print Sum of Series numbers tutorials

 

Example: C# program to print sum of number from 1+2+3+....10

 Sam Sir

//program name test035.cs

// C# program to print sum of number from 1+2+3+....10

using System;

class Program

{

static void Main(string[] args)

{

int no, s = 0;

for (no = 1; no <= 10; no++)

s = s + no;

Console.Write("Sum of nos from 1 to 10 = {0} \n", s);

}

}

Output

Sum of nos from 1 to 10 = 55

  • Now make few changes and keep two statements s=s+no; and make following changes in Console.Write statements withing { } brace brackets.

 

Example:C# program to print sum of numbers from 1+2+3+....10

 Sam Sir

// program name test035.cs

// C# program to print sum of number from 1+2+3+....10

using System;

class Program

{

static void Main(string[] args)

{

int no, s = 0;

for (no = 1; no <= 10; no++)

{

s = s + no;

Console.Write("Sum + {0} = {1} \n", no, s);

}

 

}

}

Output

Sum + 1 = 1

Sum + 2 = 3

Sum + 3 = 6

Sum + 4 = 10

Sum + 5 = 15

Sum + 6 = 21

Sum + 7 = 28

Sum + 8 = 36

Sum + 9 = 45

Sum + 10 = 55

  • Now you will see that as Console.Write statement is given within { } brace bracket, it will be executed for 10 times and it shows, each incremental sum of series.

 

Example:C# program to print product of numbers from 1*2*3*....10

 Sam Sir

//program name test036.cs

//C# program to print product of numbers from 1*2*3*....10

using System;

class Program

{

static void Main(string[] args)

{

int no, p = 1;

for (no = 1; no <= 10; no++)

p = p * no;

Console.Write("Product of nos from 1 to 10 = {0}\n", p);

}

}

Output

Product of nos from 1 to 10 = 3628800

 

 

 

Example:C# program to print sum of 2 digit odd numbers from 11+13+15....99

 Sam Sir

//program name test037.cs

//C# program to print sum of 2 digit odd numbers from 11+13+15....99

using System;

class Program

{

static void Main(string[] args)

{

int no, s = 0;

for (no = 11; no <= 99; no = no + 2)

s = s + no;

Console.Write("Sum of 2 digit odd nos from 11 to 99 = {0}\n", s);

}

}

Output

Sum of 2 digit odd nos from 11 to 99 = 2475

 

 

 

Example:C# program to print sum of 2 digit numbers divisible by 3 and 5

 Sam Sir

//program name test038.cs

// C# program to print sum of 2 digit numbers divisible by 3 and 5

using System;

class Program

{

static void Main(string[] args)

{

int no, s = 0;

for (no = 10; no <= 99; no++)

{

if (no % 3 == 0 && no % 5 == 0)

s = s + no;

}

Console.Write("Sum of 2 digit nos divisible by 3 and 5 = {0}\n", s);

}

}

Output

Sum of 2 digit nos divisible by 3 and 5 =315

 

 

Example:C# program to print sum of series as 1+ 1/2+ 1/3+ 1/4 ....1/10

 Sam Sir

//program name test039.cs

//C# program to print sum of series as 1+ 1/2+ 1/3+ 1/4 ....1/10

using System;

class Program

{

static void Main(string[] args)

{

float no, s = 0.0F;

for (no = 1; no <= 10; no++)

s = s + (1.0F / no);

Console.Write("\n Sum of series as 1+ 1/2+ 1/3+ 1/4 ....1/10 = {0}", s);

}

}

Output

Sum of series as 1+ 1/2+ 1/3+ 1/4 ....1/10 = 2.928968

 

 

Example:C# program to print sum of series as 1/2+ 2/3+ 3/4 ....9/10

 Sam Sir

//program name test040.cs

//C# program to print sum of series as 1/2+ 2/3+ 3/4 ....9/10

using System;

class Program

{

static void Main(string[] args)

{

float no, s = 0.0F;

for (no = 1; no <= 9; no++)

s = s + (no / (no + 1));

Console.Write("\n Sum of series as 1/2+ 2/3+ 3/4 ....9/10 = {0}", s);

}

}

Output

Sum of series as 1/2+ 2/3+ 3/4 ....9/10 = 7.071032

Pr.Pg border                                              Next Pg