using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public static int suma(int a, int b)
{
return a + b;// y restorna la suma a + b
}
static void Main(string[] args)
{
int a, b,c;// declara tres variables
a = 12;
b = 14;
c = suma(a, b);//suma es uh metodo q recibe dos valores
Console.WriteLine(suma(a, b));
a=16;
b=78;
c=suma(a,b);//suma es uh metodo q recibe dos valores
Console.WriteLine(suma(a, b));
c = suma(100, 200);//suma es uh metodo q recibe dos valores
Console.WriteLine(suma(a, b));
}
}
}
--------------------------------------------------
HAYAR EL FACTORIAL DE UN NUMERO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x, f=1;
Console.Write("INGRESE UN NUMERO");
x = Convert.ToInt16(Console.ReadLine());
for (int i = x; i > 1; i--)
{
f = f * i;
}
Console.WriteLine("EL FACTORIAL ES "+ f);
}
}
}
--------------------------------------------------------------
INGRESAR 10 NUMEROS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
public static int fac(int x)
{
int f = 1;
for (int i = x; i > 1; i--)
{
f = f * i;
}
return f;
}
static void Main(string[] args)
{
int x;
Console.Write("INGRESE EL NUMERO");
x = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("EL FACTORIAL ES {0}", fac(x));
}
}
}
-------------------------------------------------------------------------------
HACER PROGRAMA Q INGRESE 10 NUMEROS POR FACTORIAL:
using System.Text;
namespace ConsoleApplication2
{
class Program
{
public static int fac(int x)
{
int f = 1;
for (int i = x; i > 1; i--)
{
f = f * i;
}
return f;
}
static void Main(string[] args)
{
Random objeto = new Random();
int[] a = new int[10];
int[] b = new int[10];
for (int i = 0; i < es ="{1}" f =" 1;" i =" x;"> 1; i--)
{
f = f * i;
}
return f;
}
public static void imprimir(int[] a, string l)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("{0}[{1}]={2}", l, i, a[i]);
}
}
static void Main(string[] args)
{
Random objeto = new Random();
int[] a = new int[10];
int[] b = new int[10];
for (int i = 0; i < 10; i++)
{
a[i] = objeto.Next(12);
b[i] = fac(a[i]);
Console.WriteLine("EL FACTORIAL DE {0} ES ={1} ", a[i], b[i]);
}
imprimir(a,"a");
imprimir(b,"b");
}
}
--------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
public static int suma(int a, int b)
{
return a + b;
}
public static int resta(int a, int b)
{
return a - b;
}
public static int multiplica(int a, int b)
{
return a * b;
}
public static int divide(int a, int b)
{
return a / b;
}
static void Main(string[] args)
{
Console.WriteLine(suma(8, 45));
Console.WriteLine(resta(8, 45));
Console.WriteLine(multiplica(8, 45));
Console.WriteLine(divide(8, 45));
}
}
}
-----------------------------------------------------------------------------------------
RELLERNAR:se crea rellenar q permite rellenmar un arreglo de valores aleatorios
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
public static int suma(int a, int b)
{
return a + b;
}
public static int resta(int a, int b)
{
return a - b;
}
public static int multiplica(int a, int b)
{
return a * b;
}
public static int divide(int a, int b)
{
return a / b;
}
public static void rellenar(int[] x, int r)// x toma el valor de a y r de b
{
Random objeto = new Random();// declara un objeto random
for (int i = 0; i < x.Length; i++)// length es tamaño
{
x[i] = objeto.Next(r);// cada uno de los elementos lo va a rellenar un ramdon
}
}
static void Main(string[] args)
{
int[] a = new int[10];// declarar 3 arreglos
int[] b = new int[10];
int[] c = new int[10];
rellenar(a, 20);// funcion rellear a con 20
rellenar(b, 40);
for(int i=0;i<10;i++)
{
c[i] = suma(a[i], b[i]);
Console.WriteLine("{0}+{1}={2}", a[i], b[i], c[i]);
}
}
}
}
-------------------------------------------------------------------------------------------------
RELLERNAR OCHO ARREGLOS:
a
b
c
d
e
f
g
h
x= mostrar la suma del arreglo a +b
y= la resta de c-d
z=la multiplicacion de e*f
w=la division de g/h
imrpimir donde se manda (a,b,c, simbolo "string")
imprimir (a,b,x,"+")
a+b=x
imprimir (c,d,y,"-")
c-d=y
console. whiteline("´(a) simbolo")
----------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
public static int suma(int a, int b)
{
return a + b;
}
public static int resta(int a, int b)
{
return a - b;
}
public static int multiplica(int a, int b)
{
return a * b;
}
public static int divide(int a, int b)
{
return a / b;
}
public static void rellenar(int[] x, int r)// x toma el valor de a y r de b
{
Random objeto = new Random();// declara un objeto random
for (int i = 0; i < x.Length; i++)// length es tamaño
{
x[i] = objeto.Next(r);// cada uno de los elementos lo va a rellenar un ramdon
Console.WriteLine(x[i]);
}
}
public static void imprimir(int[] m, int[] n, int[] o, string s)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("{0} {1} {2} ={3}", m[i],s, n[i], o[i]);
}
}
static void Main(string[] args)
{
int[] a = new int[10];// declarar 3 arreglos
int[] b = new int[10];
int[] c = new int[10];
int[] d = new int[10];
int[] e = new int[10];
int[] f = new int[10];
int[] g = new int[10];
int[] h = new int[10];
int[] w = new int[10];
int[] y= new int[10];
rellenar(a, 20);// funcion rellear a con 20
Console.WriteLine("****************");
rellenar(b, 20);
rellenar(d, 20);
rellenar(e, 20);
rellenar(f, 20);
rellenar(g, 20);
rellenar(h, 20);
rellenar(w, 20);
rellenar(y, 20);
for(int i=0;i<10;i++)
{
c[i] = suma(a[i], b[i]);
}
imprimir(a, b, c, "+");
Console.WriteLine("****************");
for (int i = 0; i < 10; i++)
{
d[i] = resta(a[i], b[i]);
}
imprimir(a, b, d, "-");
Console.WriteLine("****************");
for (int i = 0; i < 10; i++)
{
c[i] =resta(a[i], b[i]);
}
imprimir(e, f, w, "*");
Console.WriteLine("******************************");
for (int i = 0; i < 10; i++)
{
w[i] = multiplica(e[i], f[i]);
}
imprimir(c, d, y, "/");
Console.WriteLine("********************************");
for (int i = 0; i < 10; i++)
{
y[i] = divide(c[i], d[i]);
}
}
}
}
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario