Estructuras Repetitivas C#

Descargar como pdf o txt
Descargar como pdf o txt
Está en la página 1de 4

Práctica de Laboratorio

Estructuras repetitivas

Analizar cada uno de los siguientes ejercicios

WHILE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EstructuraRepetitivaWhile3
{
class Program
{
static void Main(string[] args)
{
int x,suma,valor,promedio;
string linea;
x=1;
suma=0;
while (x<=10)
{
Console.Write("Ingrese un valor:");
linea = Console.ReadLine();
valor=int.Parse(linea);
suma=suma+valor;
x=x+1;
}
promedio=suma/10;
Console.Write("La suma de los 10 valores es:");
Console.WriteLine(suma);
Console.Write("El promedio es:");
Console.Write(promedio);
Console.ReadKey();
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EstructuraRepetitivaWhile9
{
class Program
{
static void Main(string[] args)
{
int mult8;
mult8=8;
while (mult8<=500)
{
Console.Write(mult8);
Console.Write(" - ");
mult8=mult8 + 8;
}
Console.ReadKey();
}
}
}

FOR
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EstructuraRepetitivaFor2
{
class Program
{
static void Main(string[] args)
{
int suma,f,valor,promedio;
string linea;
suma=0;
for(f=1;f<=10;f++)
{
Console.Write("Ingrese valor:");
linea=Console.ReadLine();
valor=int.Parse(linea);
suma=suma+valor;
}
Console.Write("La suma es:");
Console.WriteLine(suma);
promedio=suma/10;
Console.Write("El promedio es:");
Console.Write(promedio);
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EstructuraRepetitivaFor3
{
class Program
{
static void Main(string[] args)
{
int aprobados,reprobados,f,nota;
string linea;
aprobados=0;
reprobados=0;
for(f=1;f<=10;f++)
{
Console.Write("Ingrese la nota:");
linea = Console.ReadLine();
nota=int.Parse(linea);
if (nota>=7)
{
aprobados=aprobados+1;
}
else
{
reprobados=reprobados+1;
}
}
Console.Write("Cantidad de aprobados:");
Console.WriteLine(aprobados);
Console.Write("Cantidad de reprobados:");
Console.Write(reprobados);
Console.ReadKey();
}
}
}

Do.. While
Realizar un programa que permita ingresar el peso (en kilogramos) de piezas. El proceso termina
cuando ingresamos el valor 0. Se debe informar:
a) Cuántas piezas tienen un peso entre 9.8 Kg. y 10.2 Kg.?, cuántas con más de 10.2 Kg.? y cuántas
con menos de 9.8 Kg.?
b) La cantidad total de piezas procesadas.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EstructuraRepetitivaDoWhile3
{
class Program
{
static void Main(string[] args)
{
int cant1,cant2,cant3,suma;
float peso;
string linea;
cant1=0;
cant2=0;
cant3=0;
do {
Console.Write("Ingrese el peso de la pieza (0 pera finalizar):");
linea = Console.ReadLine();
peso=float.Parse(linea);
if (peso>10.2)
{
cant1++;
}
else
{
if (peso>=9.8)
{
cant2++;
}
else
{
if (peso>0)
{
cant3++;
}
}
}
} while(peso!=0);
suma=cant1+cant2+cant3;
Console.Write("Piezas aptas:");
Console.WriteLine(cant2);
Console.Write("Piezas con un peso superior a 10.2:");
Console.WriteLine(cant1);
Console.Write("Piezas con un peso inferior a 9.8:");
Console.WriteLine(cant3);
Console.ReadLine();
}
}
}

También podría gustarte

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy