[go: up one dir, main page]

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

Solution 4

The document contains multiple code snippets in C# that demonstrate different methods for summing integers input by the user. The first snippet calculates the sum until a zero is entered, while the second also calculates the average. The third snippet finds the lowest and highest values along with the sum, and the fourth snippet limits input to a maximum of 10 numbers or a sum of 100.

Uploaded by

Arab kg
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)
17 views2 pages

Solution 4

The document contains multiple code snippets in C# that demonstrate different methods for summing integers input by the user. The first snippet calculates the sum until a zero is entered, while the second also calculates the average. The third snippet finds the lowest and highest values along with the sum, and the fourth snippet limits input to a maximum of 10 numbers or a sum of 100.

Uploaded by

Arab kg
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

Saeed Ghanem

Assignment 4
I.

int sum = 0;
string input = Console.ReadLine();
int n = Convert.ToInt32(input);
while(n !=0)
{
sum=sum+n;
input = Console.ReadLine();
n = Convert.ToInt32(input);
}
Console.WriteLine(sum);

II.

int sum = 0;
string input = Console.ReadLine();
int n = Convert.ToInt32(input);
while(n !=0)
{
sum=sum+n;
input = Console.ReadLine();
n = Convert.ToInt32(input);
}
Console.WriteLine(sum);
double avg = sum / 2.0;
Console.WriteLine(avg);

III.

int lowest = int.MaxValue;


int highest = int.MinValue;
int sum = 0;
string input = Console.ReadLine();
int n = Convert.ToInt32(input);
while(n !=0)
{
sum=sum+n;
input = Console.ReadLine();
n = Convert.ToInt32(input);
if (n < lowest)
lowest = n;
if (n > highest)
highest = n;
}

Console.WriteLine($"sum={sum}");
double avg = sum / 2.0;
Console.WriteLine($"avg={avg}");
Saeed Ghanem
IV.

int sum = 0;
int count=0;

while (true)
{
if (count >= 10)
break;

if (sum >= 100)


break;
string input = Console.ReadLine();
int n = Convert.ToInt32(input);

if (n == 0)
break;

sum = sum + n;
count++;
}
Console.WriteLine(sum);

int sum = 0;
int count=0;

while (true)
{
if (count >= 10)
break;

if (sum >= 100)


break;
string input = Console.ReadLine();
int n = Convert.ToInt32(input);

if (n == 0)
break;

sum = sum + n;
count++;
}
Console.WriteLine(sum);

You might also like