Está en la página 1de 30

UNIVERSIDAD TÉCNICA DE AMBATO

FACULTAD DE INGENIERIA EN SISTEMAS, ELECTRONICA E INDUSTRIAL


Telefax: 03-2851894 – 2411537, Correo Electronico: carrera.sistemas@uta.edu.ec
AMBATO-ECUADOR

Fundamentos de programación

Título: Realizar los siguntes ejercicios

Carrera: Telecomunicaciones

Paralelo: 2 “A”

Ciclo Académico: Marzo2019-Agosto2019

Docente: Ing. Víctor Manzano

Nombre: John Núñez

1.- Encontrar el factorial de un número

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package javaapplication4;

import java.util.Scanner;

//@author John
public class JavaApplication4 {

public static void main(String[] args) {

Scanner t = new Scanner(System.in);

int iCantidad = 1;

int Numero;

Numero=t.nextInt();

while (Numero!=0){

iCantidad = iCantidad*Numero;

Numero=Numero-1;

System.out.println("el factorial es"+iCantidad);

}
2.- Dado un rango de números enteros, obtener la cantidad de números pares e impares del
rango, sin considerar los múltiplos de 5

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package javaapplication4;

import java.util.Scanner;

import static javafx.application.Platform.exit;

/**

* @author John

*/
public class NewClass {

public static void main(String[] args) {

Scanner t = new Scanner(System.in);

int A,B=0,C=0;

System.out.println("ingrese un numero ");

System.out.println("ingrese el 0 para salir");

A=t.nextInt();

while ((A!=0)){

if(A%5==0){

exit();

}else

if(A%2==0){

B=B+1;

System.out.println("ingresar numero");

A=t.nextInt();

}else

C=C+1;

System.out.println("ingresar numero");

A=t.nextInt();

System.out.println("EL TOTAL DE NUMEROS PARES"+B);

System.out.println("EL TOTAL DE NUMEROS IMPARES"+C);

}
3.- Calcular la suma y el producto de los N primeros números naturales múltiplos de 3

public class Ejercicio_3 {

public static void main(String[] args) {

Scanner leer = new Scanner (System.in);

int N,i=1,SUMA=0,PRODUCTO=1;

System.out.println("ingrese el enesimo de los multiplos de 3 "

+ "para realizar la suma y multiplicacion");

N=leer.nextInt();

while(N>=1){

SUMA=SUMA+N*3;

PRODUCTO=PRODUCTO*N*3;

N--;

}System.out.println("la suma es: "+SUMA);

System.out.println("el producto: "+PRODUCTO);

}
4.- Dado un numero determinar cuantos dígitos 0 contiene

package javaapplication4;

import java.util.Scanner;

/**

* @author John

*/

public class NewClass2 {

public static void main(String[] args) {

Scanner t = new Scanner(System.in);

int num,res,contcero=0;
num=t.nextInt();

while (num!=0){

res=num%10;

num=num/10;

if(res!=0){

}else

contcero++;

System.out.println(contcero);

}
5.- Se quiere saber si existe un determinado digito en un numero dado

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package javaapplication4;

import java.util.Scanner;

/**

* @author John

*/

public class NewClass3 {


/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author John

*/

public static void main(String[] args) {

Scanner t = new Scanner(System.in);

int num,res,contcero=0,numeroaindentificar;

num=t.nextInt();

numeroaindentificar=t.nextInt();

while (num!=0){

res=num%10;

num=num/10;

if(res!=numeroaindentificar){

}else

contcero++;

System.out.println(contcero);
}

6.- Dado un numero, determinar el porcentaje de números pares, impares y neutros(0)

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author John
*/

public class porcentaje {

public static void main(String[] args) {

/**

* @author John

*/

Scanner t = new Scanner(System.in);

int num,res,contcero=0,numeropar=2,numeroimpar=3,neutro=0,contpar=0,contimpar=0;

num=t.nextInt();

while (num!=0){

res=num%10;

num=num/10;

if(res==0){

contcero++;

}else{

if(res%numeropar==0&&(res!=0)){

contpar++;

}else{

contimpar++;

double porspar,porsimpar,porsneutro,Totarl;
Totarl=contpar+contimpar+contcero;

porspar=(contpar/Totarl)*100;

porsimpar=(contimpar/Totarl)*100;

porsneutro=(contcero/Totarl)*100;

System.out.println("numero de dijitos pares"+contpar);

System.out.println("numero de dijitos inpares"+contimpar);

System.out.println("numero de dijitos neutros"+contcero);

System.out.println("porcentaje pares"+porspar);

System.out.println("porcentaje pares"+porsimpar);

System.out.println("porcentaje pares"+porsneutro);

}
7 Dado un rango determinecuantos números primos contiene

import java.util.Scanner;

/**

* @author John

*/

public class prueba {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("ingrese el rango inicial diferente de 1");

int rani = scanner.nextInt();

System.out.println("ingrese El rango final ");

int ranf = scanner.nextInt();

int num=rani;

if(num>1){

while(num<=ranf){

int num2 = num-1;

while((num%num2) != 0){

num2--;

if(num2 == 1){

System.out.println(num+"\nEs primo");

} else {

num++;
}

}else

System.out.println("INGRESE UN NUMERO POSITIVO DIFERENTE DE UNO ");

8 Dado un rango de números determine cuantos capicúa hay

//numero capicua

package javaapplication4;

import java.util.Scanner;
/**

* @author John

*/

public class NewClass7 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int numero;

int faltante;

int numeroInvertido;

int restante,rango,rangoF;

rango=sc.nextInt();

rangoF=sc.nextInt();

Scanner num=new Scanner(System.in);

while(rango<rangoF) {

faltante=rango;

numeroInvertido=0;

restante=0;

while(faltante!=0) {

restante=faltante%10;
numeroInvertido=numeroInvertido*10+restante;

faltante=faltante/10;

if(numeroInvertido==rango){

System.out.println(+rango+"\n El numero es capicua\n");

}else{

System.out.println(rango+"\n El numero no es capicua\n");

rango++;

}
import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author John

*/

public class metodo_euclides {


public static void main(String[] args) {

Scanner t = new Scanner(System.in);

int rest=0,num1,num2,A;

num1=t.nextInt();

num2=t.nextInt();

A=num1%num2;

while(A!=0){

A=num1%num2;

num1=num2;

num2=A ;

System.out.println("el M.C.D es "+num1);

}
10 calcular el máximo común divisor por el metodo de factorisacion simultanea

mport java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author John

*/

public class prueba2 {

public static void main(String[] args) {

Scanner t = new Scanner(System.in);

int x,b,c,R;

x=t.nextInt();

b=t.nextInt();

int factor=2;

int factor1=2;

while(factor<=x){

R=0;

if(x%factor==0){

x=x/factor;

System.out.println("primer numero"+factor);
}else{

factor++;

while(factor1<=b){

if(b%factor1==0){

b=b/factor1;

System.out.println("segundo numero"+factor1);

}else{

factor1++;

if(factor1==factor){

R=R+factor;

System.out.println(R);

}
11 calcular la siguiente serie

S2=2,4,-6,-8,10,12,14,-16

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author John

*/
public class serie1 {

public static void main(String[] args) {

Scanner t = new Scanner(System.in);

int n,i=0,j=0,x=0,s=0,suma=0,sum2=0,sum3;

n=t.nextInt();

while(i<n){

if(j<2){

s=s+2;

System.out.print(s+" , ");

j++;

suma=suma+s;

else{

if(x<2){

s=s+2;

System.out.print(s*(-1)+" , ");

x=x+1;

sum2=(s*(-1))+sum2;

else{

j=0;

x=0;

i++;

sum3=sum2+suma;

System.out.println("\nla suma es "+sum3);

}
}

12 calcular la siguiente serie

S1=1,-3,5,-7,-9,11,-13,-15,-17,19

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

*
* @author John

*/

public class pruebaserie {

public static void main(String[] args) {

Scanner t = new Scanner(System.in);

int RANGOI=1,rangoF,contador1=0,contador2=1,suma=1,sum2=0,sum3=0;

rangoF=t.nextInt();

System.out.print("1");

while(RANGOI<rangoF){

if(contador1<contador2){

suma=suma+2;

System.out.print(suma*(-1)+",");

contador1++;

sum2=(suma*(-1))+sum2;

else {

suma=suma+2;

System.out.print(suma);

contador2++;

contador1=0;

sum3=suma+sum3;

RANGOI++;

}
System.out.println("\nla suma es "+(sum2+sum3+1));

13 calcular la siguiente serie

e^x=1 + x + (x ^ 2) / 2! + ... + (x ^ n) / n!

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.


*/

/**

* @author John

*/

public class prueba___ {

public static void main(String[] args) {

Scanner t = new Scanner(System.in);

double iCantidad = 1,cont2=1;

double Numero,rangof,rangoi,A,R,P=1,amelia;

System.out.println("ingrese la variable x");

rangoi=t.nextInt();

System.out.println("ingrese un rango n");

rangof=t.nextInt();

Numero=2;

System.out.print("e^x="+"1"+"+"+rangoi);

while(Numero<=rangof){

A=Numero;

while (A!=0){

iCantidad = iCantidad*A;

A=A-1;

//System.out.println("el factorial es"+iCantidad);

Numero++;
cont2++;

//System.out.println(cont2);

R=(Math.pow(rangoi, cont2))/iCantidad;

System.out.print("+"+R);

P=(P+R);

iCantidad=1;

amelia=P+rangoi;

System.out.println("\nLa suma total es\n"+amelia);

}
14 realizar un programa que me diga que números son perfectos

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

* @author John

*/

public class taller {

public static void main(String[] args) {

Scanner leer = new Scanner(System.in);

int A,C,D;

int rani,ranf;

System.out.println("ingrese el rango inicial ");

rani=leer.nextInt();

System.out.println("ingrese el rango final ");

ranf=leer.nextInt();

A=rani;

D=0;

while(A<=ranf){

int suma=0;
C=1;

while(C<(A)){

if(A%C==0)

suma += C;

C++;

if (suma == A) {

D++;

System.out.println("El numero "+A+" es un numero perfecto;");

} else {

A++;

System.out.println("el total de numeros perfectos es"+D);

También podría gustarte