Write a C# Sharp program to find the sum of first 10 natural numbers

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to find the sum of first 10 natural numbers

Sample Output:

Find the sum of first 10 natural numbers:                                                                     
----------------------------------------------                                                                
                  
The first 10 natural number are :                                                                             
1 2 3 4 5 6 7 8 9 10                                                                                          
The Sum is : 55

الأجوبة

using System;  
public class Exercise2  
{  
    public static void Main() 
{
    int  j, sum = 0;

	Console.Write("\n\n");
    Console.Write("Find the sum of first 10 natural numbers:\n");
    Console.Write("----------------------------------------------");
    Console.Write("\n\n");
	
    Console.Write("The first 10 natural number are :\n");
     for (j = 1; j <= 10; j++)
    {
        sum = sum + j;
        Console.Write("{0} ",j);    
    }
    Console.Write("\nThe Sum is : {0}\n", sum);
  }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...