0% found this document useful (0 votes)
40 views2 pages

Program: Comentarios Despues de La Linea de Codigo. Class Static Void String Int Int Int Int While

This document contains code for two C# programs. The first program calculates the sum of integers from 1 to a user-input number n. It prompts the user to enter n, initializes variables to track the number and running sum, and uses a while loop to iteratively add numbers to the sum from 1 to n. The second program determines if a user-input number is a prime number. It prompts the user for a positive number, uses a while loop to check for divisibility by integers from 2 to the square root of the number, and prints whether the number is prime or not.

Uploaded by

cesar1hc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

Program: Comentarios Despues de La Linea de Codigo. Class Static Void String Int Int Int Int While

This document contains code for two C# programs. The first program calculates the sum of integers from 1 to a user-input number n. It prompts the user to enter n, initializes variables to track the number and running sum, and uses a while loop to iteratively add numbers to the sum from 1 to n. The second program determines if a user-input number is a prime number. It prompts the user for a positive number, uses a while loop to check for divisibility by integers from 2 to the square root of the number, and prints whether the number is prime or not.

Uploaded by

cesar1hc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Comentarios despues de la linea de codigo.

class Program
{
static void Main(string[] args)
{
Console.Write(" n = ");//
int n = int.Parse(Console.ReadLine());
int num = 1;
int sum = 1;
Console.Write(" The sum 1");
while ( num < n )
{
num++;
sum += num;
Console.Write(" + " + num );

}
Console.WriteLine("="+ sum);
}
}

//*********************************************************************
static void Main(string[] args)
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a positive number: ");//
int num = int.Parse(Console.ReadLine());//
int divider = 2;//
int maxDivider = (int)Math.Sqrt(num);//
bool prime = true;//
while ( prime && (divider <= maxDivider))//
{
if (num % divider == 0)//
{
prime = false;//

}
divider++;//
}
Console.WriteLine("Prime?" + prime);//
}
}

}
}

You might also like