0% found this document useful (0 votes)
45 views6 pages

Ejercicio 3: Namespace Class Static Void String Int

This document contains code snippets for several programming exercises in C# and C++. The snippets demonstrate concepts like: 1. Calculating the number of customers that can be fully served and the leftovers for the last customer given the number of breads the seller has and each customer takes. 2. Finding all divisors of a given number. 3. Checking if a number is prime using two different approaches. 4. Calculating the greatest common divisor of three numbers. 5. Finding all palindromes between two given limits. 6. Implementing a basic ATM program with options to withdraw, check balance, deposit and exit. 7. Calculating pay for hours

Uploaded by

Cesar Lopez
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)
45 views6 pages

Ejercicio 3: Namespace Class Static Void String Int

This document contains code snippets for several programming exercises in C# and C++. The snippets demonstrate concepts like: 1. Calculating the number of customers that can be fully served and the leftovers for the last customer given the number of breads the seller has and each customer takes. 2. Finding all divisors of a given number. 3. Checking if a number is prime using two different approaches. 4. Calculating the greatest common divisor of three numbers. 5. Finding all palindromes between two given limits. 6. Implementing a basic ATM program with options to withdraw, check balance, deposit and exit. 7. Calculating pay for hours

Uploaded by

Cesar Lopez
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/ 6

Ejercicio 3

namespace ConsoleApplication22
{
class Program
{
static void Main(string[] args)
{
int n, m, r, t = 0, i = 0;
Console.WriteLine("Ingrese la cantidad de panes que tiene la
vendedora:");
n = int.Parse(Console.ReadLine());
Console.WriteLine("ingrese la cantidad de panes que lleva cada
cliente:");
m = int.Parse(Console.ReadLine());

do{ t=t+m; i++;


}
while (t <= n);
i--; t = t - m; r = n - t;

Console.WriteLine("Seran atendidos completamante:" +i+"clientes");

if (r <= 0)
{ Console.WriteLine("No se llevará nada el ultimo cliente..."); }
else
{ Console.WriteLine("y el ultimo se ira con:" + r + "panes"); }
Console.Read();

}
}
}

Ejercicio 4
namespace ejercicio6_calcule_y_muestre_los_divisores
{
class Program
{
static void Main(string[] args)
{
int n;

Console.WriteLine("Introducir numero:");
n = Convert.ToInt32(Console.ReadLine());

for (int i = 1; i <= n; i++)


{
if (n % i == 0)
{ Console.WriteLine("Divisores: " + i);
}

}
Console.ReadLine();

}
}
}
Ejercicio 5
Solución a)
class Program
{
static void Main(string[] args)
{
int j, i, n;
j = 0;
i = 0;
Console.WriteLine("Introduce num: ");
n = Convert.ToInt32(Console.ReadLine());

while (i <= n)
{
i++;

if (n % i == 0)

j = j + 1;
}
if (j == 2)
Console.WriteLine("Es primo!");
else
Console.WriteLine("No es primo!");

Console.ReadLine();

Solución b)
class Program
{
static void Main(string[] args)
{
int a = 0, n;
Console.WriteLine("Ingrese numero");
n = Convert.ToInt32(Console.ReadLine());

for (int i = 1; i < (n + 1); i++)


{
if (n % i == 0)
{
a++;
}
}
if (a != 2)
{
Console.WriteLine("No es Primo");
}
else
{
Console.WriteLine("Si es Primo");
}
Console.ReadLine();
}
Ejercicio 6
class Program
{
static void Main(string[] args)
{
int num1, num2, num3, c=2, mcd=1;
Console.WriteLine("Ingrese primer numero");
num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Ingrese segundo numero");
num2 = int.Parse(Console.ReadLine());
Console.WriteLine("Ingrese tercer numero");
num3 = int.Parse(Console.ReadLine());

while (c <= num1 && c <= num2 && c <= num3)


{
while (num1 % c == 0 && num2 % c == 0 && num3 % c == 0)
{
mcd = mcd * c;
num1 = num1 / c;
num2 = num2 / c;
num3 = num3 / c;
}
c = c + 1;
}
Console.WriteLine(" El maximo comun divisor de los numeros es:" +
mcd.ToString());
Console.Read();
}

Ejercicio 7
class Program
{
static void Main(string[] args)
{
int n, s=0, inv, i, linf, lsup;
Console.WriteLine("Ingrese limite inferior");
linf = int.Parse(Console.ReadLine());
Console.WriteLine("Ingrese limite superior");
lsup = int.Parse(Console.ReadLine());

for(i=linf;i<lsup;i++)
{
n=i;
inv=0;
while(n>0)
{
inv=(10*inv)+(n%10);
n=n/10;
}
if (inv == i)
{
Console.WriteLine("inv:" +i);
s = s + 1;
}
}
Console.WriteLine("total de capicuas es:"+s);
Console.Read();

}
Ejercicio 10
#include<iostream.h>
void main(void)
{int r,s,d,opc ;
s=1000;
do
{cout<<endl<<" ***MENU***"<<endl<<endl
<<" 1 = Retiro"<<endl<<" 2 = Saldo"<<endl
<<" 3 = Deposito"<<endl<<" 4 = Salir"<<endl;

cout<<"Ingresar opcion: ";cin>>opc;


switch(opc)
{case 1:
if(s==0)
cout<<endl<<"Su saldo ya no tiene fondos para hacer retiros"<<endl;
else
{ do 
{cout<<endl<<"Ingrese la cantidad de su retiro: ";cin>>r;
if (r>s)
{do {cout<<endl<<"!!! Su retiro es mayor que su saldo"<<endl;
cout<<endl<<"Ingrese la cantidad de su retiro: ";cin>>r;}
while(r>s);
}
}
while (r<0);
s=s-r;
cout<<"Su saldo es: "<<s<<endl<<endl;
break;}

case 2:
cout<<endl<<"Su saldo es: "<<s<<endl;
break;

case 3:
do
{cout<<endl<<"Ingrese su deposito: ";cin>>d;}
while(d<=0);
s=s+d;
cout<<"Su deposito fue de: "<<d<<endl;
cout<<"Su saldo es de: "<<s<<endl;
break;

}
}
while (opc!=4 );
cout<<endl<<"Gracias por utilizar nuestro servicio "<<endl<<endl;

}
Ejercicio 09
Ejercicio 01
int HT,TP, B, R, i=0, t=0;
Console.WriteLine(" Horas trabajadas:");
HT = int.Parse(Console.ReadLine());

while (i <= 8)
{
if (t <= HT)
{
TP = HT * 30;
}
else
{
if (t > HT)
{
B = HT * 30;
R = (t - HT) * 50;
TP = B + R;
}
}
t = t + 1;
Console.WriteLine("Total a pagar:"+TP);
}
i = i + 1;
Console.Read();

You might also like