34
UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE INGENIERÍA MATERIA: Computación para ingenieros EQUIPO: Castillo Méndez Elizabeth Cuatepotzo Martinez Sebastian Alberto Lozada Rodriguez Sergio Humberto Rosales Ramirez Marian Guadalupe TAREA: Secuencia, Selección y Repetición

UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO

FACULTAD DE INGENIERÍA

MATERIA:

Computación para ingenieros

EQUIPO:

Castillo Méndez Elizabeth

Cuatepotzo Martinez Sebastian Alberto

Lozada Rodriguez Sergio Humberto

Rosales Ramirez Marian Guadalupe

TAREA:

Secuencia, Selección y Repetición

Page 2: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

FOR

Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA MATRICIAL”

Programa2: “ILUSTRA EL USO DE BLUCLE FOR”

Page 3: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 3: “TABLAS DE MULTIPLICAR”

Page 4: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 4: ”SUMA UN MISMO NUMERO N VECES”

Page 5: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 5: “SERIE DE FIBONACCI”

Programa 6: “SUMA DE NUMEROS CONSECUTIVOS”

Page 6: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 7: “IMPRIME SUS NUMEROS AL CUADRADO”

Programa 8:”SUMA NÚMEROS DEL 1 AL 100”

Page 7: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA
Page 8: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 9:” CALCULA EL FACTORIAL DE UN NÚMERO”

Programa 10: “PROGRAMA QUE DETERMINA SI ES UN NUMERO PRIMO”

Page 9: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

IF DOBLE

Programa 1:”MAYOR, MENOR O IGUAL QUE”

Page 10: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 2:”SUMA MAYOR QUE CERO”

Page 11: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

PROGRAMAS DE SWITCH

Programa 1#include <stdio.h>#include <conio.h>#include <ctype.h>main() { char opcion; do { system("cls"); printf("Escoge una opcion: A, B, C, D, S.\n "); scanf("%c", &opcion); opcion = toupper(opcion); switch(opcion) { case 'A': printf("Buon Giorno."); break; case 'B': printf("Guten Morgen."); break; case 'C': printf("Buenos Dias."); break; case 'D': printf("Bonjour."); break; } getch(); } while(opcion != 'S');}

Page 12: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 2#include<stdio.h>#include<conio.h>int main(){

int a,x,y; float r;printf("Dame 2 numeros cuales quieras\n");scanf("%d %d",&x,&y);printf("los valores dados son %d %d",x,y);printf("\nque quieres hacer con ellos");printf("\n1.-Sumarlos\n2.-Restarlos\n3.-Multiplicarlos\n4.-Dividirlos\n");scanf("\n%d",&a);

switch(a) { float z; case 1: if(x!=y){r=(x+y); printf("su suma es %f",r);} break; case 2: if(x!=y){r=(x-y); printf("su resta es %f",r);} else printf("su resta es 0"); break; case 3: if(y!=0){r=(x*y); printf("su multiplicacion es %f",r);} else printf("su multiplicacion es 0"); break; case 4: if(y!=0){r=(x/y); printf("su division es %f(no doy fracciones)",r);} else printf("no decide"); break; default: printf("Elige una Opcion Valida"); break; } getch();}

Page 13: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 3

#include <stdio.h>#include <stdlib.h>#include<conio.h>int x;int main(){ printf("dame un valor y te dire tu suerte\n"); scanf("%d",&x);switch (x){ case 1: printf("\nSu opcion es uno"); printf("\nno te pasara nada malo, pero tampoco nada bueno"); break; case 2: printf("\nSu opcion es dos"); printf("\nTe Caeras a un Hoyo"); break; case 3: printf("\nSu opcion es tres"); printf("\nTe Encontraras Dinero"); break; default: printf("\nSu opcion es invalida"); printf("\nla bola mistica se ah molestado"); break;}getch();}

Page 14: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 4

#include <stdio.h>#include <conio.h>int main(){char letra;printf("dame una letra : ");printf("\nte dire a que animal te pareces(no te ofendas)\n");letra = getchar();getchar();switch (letra){case 'a': case 'A':printf("Aguila");break;case 'b': case 'B': printf("Vaca");break;case 'c': case 'C':printf("Camello");break;default: printf("no hay");}getch();return 0;}

Page 15: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 5#include <stdio.h>#include <stdlib.h>#include <conio.h>int main(){ int a; float x,y; printf("Vamos a convertir tus unidades\n"); printf("\nDame un valor que quieras convertir\n"); scanf("%f",&x); printf("\na que lo quieres convertir"); printf("\n1.- de g a kg\n2.-de cm^3 a m^3\n3.-de ºC a K\n4.-De cal a J\n"); scanf("%d",&a); switch(a){case 1: y=(x/1000); printf("Su equivalente de %fg son %fkg ",x,y);break;case 2: y=(x/1000000); printf("Su equivalente de %fcm^3 son %fm^3",x,y); break;case 3: y=(x+273.15); printf("Su equivalente de %fºC son %fK",x,y); case 4: y=(x*4.1868); printf("Su equivalente de %fcal son %fJ",x,y); printf("\nno te preocupes\ncon un poco de ejercicio\nbajas esas calorias que comiste"); break;default: printf("No se hacer otra cosa mas");}getch();}

Page 16: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

PROGRAMAS DE WHILE

Programa 1

#include<stdio.h>int main(){int X;printf("Tabla de multiplicar del 3 con while\n");printf("Valor\tValor\tResultado\n");X=0;while(<=30){X = X+1;printf("%d\t3\t%d\n",X,X*3);}_getche();}

#include <stdio.h>#include <stdlib.h>#include <conio.h>int j,a,k,r;int main(){printf("programa para calcular el doble de un numero y la mitad de este");while(a<100){a=a+1;j=a*2;k=a/2;r=(a%2)*5;printf("\n%d %d %d.%d",a,j,k,r);}getch();}

Page 17: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 2

#include <stdio.h>#include <stdlib.h>#include <conio.h>int j,a,k;float r;int main(){printf("programa para calcular el cuadrado y el cubo del 1 al 100\n");printf("Numero\tCuadrado\tCubo");while(a<100){a=a+1;k=a*a;j=a*a*a;printf("\n%d\t%d\t\t%d",a,k,j);}getch();}

Programa 3#include <stdio.h>#include <stdlib.h>#include <conio.h>int j,a,k,z;int main(){printf("programa para dividir por el numero que quieras\n");printf("dame el numero que quieres que divida\n");scanf("%d",&j);printf("Numero\tEntre\tResultado");while(a<100){a=a+1;k=a/j;z=(a%j)*2;printf("\n%d\t%d\t\t%d.%d",a,j,k,z);}getch();}Programa 4

Page 18: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 4#include <stdio.h>#include <stdlib.h>#include <conio.h>int j,a,k;int main(){printf("te mostrare los multiplos del numero que quieras\n");printf("dame el numero que quieres \n");scanf("%d",&j);while(a<100){a=a+1;k=(j*a);printf("\n%d",k);}getch();}

Programa 5

#include <stdio.h>#include <stdlib.h>#include <conio.h>int a,k,x;char j;int main(){printf("calculare los valores de la funcion que quieras\n");printf("dame la funcion que quieras \n");printf("(recuerda que x^3=x*x*x y 2x^2=2*x*x)\n");scanf("%c",&j);while(a<25){a=a+1;x=2*a*a;printf("\n%d",x);}getch();}

Page 19: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

Programa 6

#include<stdio.h>#include<conio.h>main(void){float a,y;printf("programa para evaluar una funcion (y=4a^2-16a+15)en el intervalo [-4,4]\n");a=-4;while(a<4.1) { y=4*a*a-16*a+15; a=a+0.5; if(y>0) printf(" %lf POSITIVO\n",y); else printf(" %lf NEGATIVO\n",y);}getch();}

Programa 7 “Switch e if doble”

#include<stdio.h>#include<conio.h>main(void){float a,y; int c,num;printf("programa para calcular la sucecion de ULAM y la funcion 3x+1");printf("\ningrese un numero\n");scanf("%d",&num);c=1;while(num>1 && c<=10) { if(num%2==0)num=num/2; else num=num*3+1; printf(" \n numero= %d", num); c=c+1; }getch();}

Page 20: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

10 ejercicios de do-while

1.-

Page 21: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

2.-

Page 22: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

3.-

Page 23: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

4.-

Page 24: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA
Page 25: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

5.-

Page 26: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

6.-

Page 27: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

7.-

Page 28: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

8.-

Page 29: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

9.-

Page 30: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

IF simple

1)#include <stdio.h>#include <conio.h>

int g,h,j;main(){ g=9; h=7; j=5; if((g>h)&&(g>j)) printf("g tiene que ser mayor"); getch();}

2)#include <stdio.h>#include <conio.h>

int k,l;main(){ k=1; l=4; if(k<l) printf("k es menor"); getch();}

3)#include <stdio.h>#include <conio.h>

int z,x,c;main(){ z=1; x=4; c=3; if((z<x)||(c<x)) printf("x tiene que ser mayor"); getch();}

Page 31: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

4)#include <stdio.h>#include <conio.h>

int o,p;main(){ o=5; p=2; if(o>p) printf("o es mayor"); getch();}

5)#include <stdio.h>#include <conio.h>

int y,d,r;main(){ y=9; d=3; r=1; if((d<y)&&(r<y)) printf("y tiene que ser mayor"); getch();}

Page 32: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

SECUENCIA

1)#include <stdio.h>#include <stdlib.h>#include <conio.h>int e;main(){ printf("Sumando numeros"); e=5; printf("\n\n%d",e); e=e+10; printf(" %d",e); e=e+10; printf(" %d",e); e=e+10; printf(" %d",e); e=e+10; printf(" %d",e); e=e+10; printf(" %d",e); e=e+10; printf(" %d",e); getch();}

2)#include <stdio.h>#include <stdlib.h>#include <conio.h>int r;main(){ printf("Restando numeros"); r=70; printf("\n\n%d",r); r=r-5; printf(" %d",r); r=r-5; printf(" %d",r); r=r-5; printf(" %d",r); getch();

Page 33: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

}3)#include <stdio.h>#include <stdlib.h>#include <conio.h>int t;main(){ printf("Restando numeros"); t=5; printf("\n\n%d",t); t=t-1; printf(" %d",t); t=t-1; printf(" %d",t); t=t-1; printf(" %d",t); t=t-1; printf(" %d",t); t=t-1; printf(" %d",t); getch(); printf(" Tiempo"); getch();}

4)#include <stdio.h>#include <stdlib.h>#include <conio.h>int u;main(){ printf("Sumando numeros"); u=u+1; printf("\n\n%d",u); u=u+1; printf(" %d",u); u=u+1; printf(" %d",u); u=u+1; printf(" %d",u); u=u+1; printf(" %d",u);

Page 34: UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO FACULTAD DE … · 2011. 4. 19. · TAREA: Secuencia, Selección y Repetición. FOR Programa 1: “PROGRAMA QUE ORDENA NÚMEROS DE FORMA

u=u+1; printf(" %d",u); u=u+1; getch();}

5)#include <stdio.h>#include <stdlib.h>#include <conio.h>

int q;

main(){ printf("Retando numeros"); q=80; printf("\n\n%d",q); q=q-1; printf(" %d",q); q=q-1; printf(" %d",q); q=q-1; printf(" %d",q); q=q-1; printf(" %d",q); q=q-1; printf(" %d",q); getch; printf(" Huf, que cansado"); getch();}