Gracias x las rtas!!
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
void funcion1()
{
int i;
void *ptr = NULL;
for (i = 0; i < 5; i++){
if (ptr == NULL)
ptr = funcion2(i);
else
funcion2(i);
}
free(ptr);
}
void *funcion2(int par)
{
static char *str[] = {
"UNO",
"DOS",
"TRES",
"CUATRO",
"CINCO"
};
printf("%s\n", str[par]);
return &str;
}
#include <iostream>
#include <iomanip>
using namespace std;
const int floor_size = 20;
void mainMenu(void);
void turtleGraphics(int [][floor_size], int []);
int main(void)
{
const int max_command = 256;
int floor[floor_size][floor_size] = {{false},{false}};
int command[max_command] = {false};
mainMenu();
cout << "\nEnter commands(max " << max_command << "): ";
int i = 0;
while (command[i - 1] != 9){
cin >> command[i];
i++;
}
cout << "\n" << endl;
turtleGraphics(floor, command);
return 0;
}
void mainMenu(void)
{
cout << "*****" << setw(20) << "Turtle Graphics" << setw(10) << "*****" << endl;
cout << "\nCommand" << setw(20) << "Meaning" << endl;
cout << setw(7) << "1" << setw(20) << "Pen up" << endl;
cout << setw(7) << "2" << setw(20) << "Pen down" << endl;
cout << setw(7) << "3" << setw(20) << "Turn right" << endl;
cout << setw(7) << "4" << setw(20) << "Turn left" << endl;
cout << setw(7) << "5,10" << setw(20) << "Move forward 10"
<< "\n" << setw(27) << "spaces (or a number" << "\n"
<< setw(27) << "other than 10)" << endl;
cout << setw(7) << "6" << setw(20) << "Print the" << "\n"
<< setw(15) << floor_size << "-by-" << floor_size
<< " array" << endl;
cout << setw(7) << "9" << setw(20) << "End of data" << "\n"
<< setw(27) << "(sentinel)" << endl;
}
void turtleGraphics(int flr[][floor_size], int cmd[])
{
int coord_x = 0, coord_y = 0, move = 0,
row, column, i = 0;
bool pen = false;
while (cmd[i] != 9){
//Uncoment next line to show coord_x and coord_y
//cout << "X: " << coord_x << "\nY: " << coord_y << endl;
switch(cmd[i]){
case 1: //Don't write
pen = false;
break;
case 2: //Write
pen = true;
break;
case 3: //Turn rigth
if (move == 3)
move = 0;
else
move++;
break;
case 4: //Turn left
if (move == 0)
move = 3;
else
move--;
break;
case 5: // Move turtle
i++;
switch(move){ //Nested switch (control direction)
case 0: //Move down
if ((cmd[i] + coord_y) > floor_size) //Check if it is in floor limits
cmd[i] = floor_size - coord_y - 1; //If not, set move to the limit
for (row = coord_y; row < (cmd[i] + coord_y); row++)
for (column = coord_x; column < coord_x + 1; column++)
flr[row][column] = pen;
coord_y = row;
break;
case 1: //Move rigth
if ((cmd[i] + coord_x) > floor_size) //Check if it is in floor limits
cmd[i] = floor_size - coord_x - 1; //If not, set move to the limit
for (row = coord_y; row < coord_y + 1; row++)
for (column = coord_x; column < (cmd[i] + coord_x); column++)
flr[row][column] = pen;
coord_x = column;
break;
case 2: //Move up
if (cmd[i] > coord_y) //Check if it is in floor limits
cmd[i] = floor_size - 1; //If not, set move to the limit
for (row = coord_y; row > (coord_y - cmd[i]); row--)
for (column = coord_x; column < coord_x + 1; column++)
flr[row][column] = pen;
coord_y = row;
break;
case 3: //Move left
if (cmd[i] > coord_x) //Check if it is in floor limits
cmd[i] = floor_size - 1; //If not, set move to the limit
for (row = coord_y; row < coord_y + 1; row++)
for (column = coord_x; column > (coord_x - cmd[i]); column--)
flr[row][column] = pen;
coord_x = column;
break;
default:
;
} //End nested switch
break;
case 6: // Print floor
for (int i = 0; i < 20; i++){
for (int j = 0; j < 20; j++){
if (flr[i][j] == true)
cout << setw(2) << "*";
else
cout << setw(2) << " ";
}
cout << endl;
}
break;
default:
;
}
i++;
}
}
#include<stdio.h>
#include<stdlib.h>
struct nodo{
char data;
struct nodo *nextPtr;
};
typedef struct nodo NODO;
typedef NODO *NODOPTR;
void insertNodo(NODOPTR *, char);
char deleteNodo(NODOPTR *, char);
int listLength(NODOPTR);
void ordenarAscendente(NODOPTR *, NODOPTR *);
void printLista(NODOPTR);
main()
{
NODOPTR startPtr = NULL, startPtr2 = NULL;
char value;
int choice;
printf("Ingrese una opcion: ");
scanf("%d", &choice);
while (choice != 4){
switch (choice){
case 1:
printf("Ingrese una letra: ");
scanf("%s", &value);
insertNodo(&startPtr, value);
printLista(startPtr);
break;
case 2:
printf("Ingrese una letra para borrar: ");
scanf("%s", &value);
deleteNodo(&startPtr, value);
printLista(startPtr);
break;
case 3:
if(listLength(startPtr) == NULL)
printf("La lista no contiene elementos\n");
else
printf("La lista contiene %d elementos\n", listLength(startPtr));
break;
default:
printf("Opcion inexistente");
}
printf("Ingrese una opcion: ");
scanf("%d", &choice);
}
ordenarAscendente(&startPtr, &startPtr2);
printLista(startPtr2);
return 0;
}
void insertNodo(NODOPTR *sPtr, char val)
{
NODOPTR newPtr, previousPtr, currentPtr;
newPtr = (NODO*)malloc(sizeof(NODO));
if (newPtr != NULL){
newPtr -> data = val;
newPtr -> nextPtr = NULL;
previousPtr = NULL;
currentPtr = *sPtr;
while (currentPtr != NULL){
previousPtr = currentPtr;
currentPtr = currentPtr -> nextPtr;
}
if (previousPtr == NULL){
newPtr -> nextPtr = *sPtr;
*sPtr = newPtr;
}
else{
previousPtr -> nextPtr = newPtr;
newPtr -> nextPtr = currentPtr;
}
}
else
printf("%s not inserted. Insuficient space", val);
}
char deleteNodo(NODOPTR *sPtr, char val)
{
NODOPTR previousPtr, currentPtr, tempPtr;
if (val == (*sPtr) -> data){
tempPtr = *sPtr;
*sPtr = (*sPtr) -> nextPtr;
free(tempPtr);
return val;
}
else{
previousPtr = *sPtr;
currentPtr = (*sPtr) -> nextPtr;
while(currentPtr != NULL && currentPtr -> data != val){
previousPtr = currentPtr;
currentPtr = currentPtr -> nextPtr;
}
if(currentPtr != NULL){
tempPtr = currentPtr;
previousPtr -> nextPtr = currentPtr -> nextPtr;
free(tempPtr);
return val;
}
}
return '\0';
}
int listLength(NODOPTR currentPtr)
{
int cont = 0;
if (currentPtr == NULL)
return NULL;
else{
while (currentPtr != NULL){
cont++;
currentPtr = currentPtr -> nextPtr;
}
}
return cont;
}
void ordenarAscendente(NODOPTR *sPtr, NODOPTR *sPtr2)
{
NODOPTR auxPtr, previousPtr, currentPtr, tempPtr;
//auxPtr = *sPtr;
if (*sPtr == NULL)
printf("No hay elementos en la lista\n");
else{
while (*sPtr != NULL){
tempPtr = *sPtr;
previousPtr = NULL;
currentPtr = *sPtr2;
while (currentPtr != NULL && tempPtr -> data > currentPtr -> data){
previousPtr = currentPtr;
currentPtr = currentPtr -> nextPtr;
}
if (previousPtr == NULL){
tempPtr -> nextPtr = *sPtr2;
*sPtr2 = tempPtr;
}
else{
previousPtr -> nextPtr = tempPtr;
tempPtr -> nextPtr = currentPtr;
}
free(tempPtr);
*sPtr = (*sPtr) -> nextPtr;
}
}
}
void printLista(NODOPTR currentPtr)
{
if (currentPtr == NULL)
printf("La lista esta vacia");
else{
while (currentPtr != NULL){
printf("|%c|->", currentPtr -> data);
currentPtr = currentPtr -> nextPtr;
}
}
printf("NULL\n");
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SIZE 71
int printRace(int [][SIZE], int, int, int);
main()
{
srand(time(NULL));
int row, column, raceTrack[3][SIZE];
int tortoise = 1, hare = 1, finish;
printf("BANG!!%63s%ds\nAND THEY 'RE OFF!!\n\n", "Time: ", 0);
finish = printRace(raceTrack, tortoise, hare, SIZE);
if (finish == 1)
printf("\nTORTOISE WINS\n");
else if (finish == 2)
printf("\nHare wins\n");
else
printf("\nIt's a tie\n");
return 0;
}
int printRace(int rt[][SIZE], int t, int h, int size)
{
void wait(int);
int tortoiseArray[10] = {3, 3, 3, 3, 3, -6, -6, 1, 1, 1};
int hareArray[10] = {0, 0, 9, 9, -12, 1, 1, 1, -2, -2};
int timer = 1, row, column;
while (t < size - 1 && h < size - 1){
for (row = 1; row < 3; row++){
for (column = 1; column < size; column++){
if (t != h || t == 1){
if (row == 1 && column == t)
printf("%c", 'T');
else if (row == 2 && column == h)
printf("%c", 'H');
else
printf("_");
}
else{
if (row == 1 && column == t)
printf("%c", 'T');
else if (row == 2 && column == h)
printf("%s", "OUCH!!!");
else
printf("_");
}
}
printf("\n");
}
t += tortoiseArray[rand() % 10];
h += hareArray[rand() % 10];
if (t < 1)
t = 1;
if (h < 1)
h = 1;
if (t > size - 1)
t = size - 1;
if (h > size - 1)
h = size - 1;
wait(1);
printf("%69s%ds","Time: ", timer++);
system("clear");
printf("\n\n\n");
}
for (row = 1; row < 3; row++){
for (column = 1; column < size; column++){
if (row == 1 && column == t)
printf("%c", 'T');
else if (row == 2 && column == h)
printf("%c", 'H');
else
printf("_");
}
printf("\n");
}
if (t == size - 1 && h == size -1)
return 0;
else if (t == size -1)
return 1;
else
return 2;
}
void wait(int seconds)
{
clock_t endwait;
endwait = clock() + seconds * CLOCKS_PER_SEC;
while (clock() < endwait);
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void shuffle(int [][13]);
void deal(int [][13], const char *[], const char *[]);
void bubble(int n[], int size);
main()
{
srand(time(NULL));
int i, j, desk[4][13] = {0};
const char *suit[4] = {"Corazones", "Diamantes", "Trebol", "Espadas"};
const char *faces[13] = {"As", "Dos", "Tres", "Cuatro", "Cinco", "Seis", "Siete",
"Ocho", "Nueve", "Diez", "Jack", "Reina", "Rey"};
shuffle(desk);
deal(desk, suit, faces);
return 0;
}
void shuffle(int d[][13])
{
int row, column, card;
for (card = 1; card < 53; card++){
row = rand() % 4;
column = rand() % 13;
while (d[row][column] != 0){
row = rand() % 4;
column = rand() % 13;
}
d[row][column] = card;
}
}
void deal(int d[][13], const char *s[], const char *f[])
{
int deck2[4][13] = {0};
int row, column, card, pnt = 0, i;
int royalFlush(const int [][13]);
int straightFlush(const int [][13]);
int poker(const int [][13]);
int fullHouse(const int [][13]);
int flush(const int [][13]);
int straight(const int [][13]);
int threeOfAKind(const int [][13]);
int twoPair(const int [][13]);
int pair(const int [][13]);
int (*pokerArray[9])(const int) = {royalFlush, straightFlush, poker, fullHouse, flush,
straight, threeOfAKind, twoPair, pair};
void point(int);
for (card = 1; card < 6; card++){
for (row = 0; row < 4; row++){
for (column = 0; column < 13; column++){
if (d[row][column] == card){
printf("%-6s de %-8s\n", f[column], s[row]);
deck2[row][column] = 1;
}
}
}
}
for (i = 0; i < 9; i++){
pnt = (*pokerArray[i])(deck2);
if (pnt != 0)
break;
}
point(pnt);
}
int royalFlush(const int d2[][13])
{
int i, j, k = 0, cont = 0, card[5],
royal[5] = {0, 9, 10, 11, 12};
if (flush(d2) == 5)
for (i = 0; i < 4; i++){
for (j = 0; j < 13; j++){
if (d2[i][j] == 1){
card[k] = j;
k++;
}
}
}
bubble(card, 5);
for (i = 0; i < 5; i++)
if (card[i] == royal[i])
cont++;
if (cont == 5)
return 1;
return 0;
}
int straightFlush(const int d2[][13])
{
if (flush(d2) == 5)
if (straight(d2) == 6)
return 2;
return 0;
}
int poker(const int d2[][13])
{
int i, j, incr, cont;
for (incr = 0; incr < 13; incr++){
cont = 0;
for (i = 0; i < 4; i++){
for (j = incr; j <= incr; j++){
if (d2[i][j] == 1)
cont++;
}
}
if (cont == 4)
return 3;
}
return 0;
}
int fullHouse(const int d2[][13])
{
if (threeOfAKind(d2) == 7)
if (pair(d2) == 9)
return 4;
return 0;
}
int flush(const int d2[][13])
{
int i, j, cont;
for (i = 0; i < 4; i++){
cont = 0;
for (j = 0; j < 13; j++){
if (d2[i][j] == 1)
cont++;
}
if (cont == 5)
return 5;
}
return 0;
}
int straight(const int d2[][13])
{
int i, j, k = 0, temp, num[5];
for (i = 0; i < 4; i++){
for (j = 0; j < 13; j++){
if (d2[i][j] == 1){
num[k] = j;
k++;
}
}
}
bubble(num, 5);
temp = num[0];
for (i = 1; i < 5; i++){
if (num[i] != temp + 1)
return 0;
temp = num[i];
}
return 6;
}
int threeOfAKind(const int d2[][13])
{
int i, j, incr, cont;
for (incr = 0; incr < 13; incr++){
cont = 0;
for (i = 0; i < 4; i++){
for (j = incr; j <= incr; j++){
if (d2[i][j] == 1)
cont++;
}
}
if (cont == 3)
return 7;
}
return 0;
}
int twoPair(const int d2[][13])
{
int i, j, incr, cont, pairCont = 0;
for (incr = 0; incr < 13; incr++){
cont = 0;
for (i = 0; i < 4; i++){
for (j = incr; j <= incr; j++){
if (d2[i][j] == 1)
cont++;
}
}
if (cont == 2)
pairCont++;
}
if (pairCont == 2)
return 8;
return 0;
}
int pair(const int d2[][13])
{
int i, j, incr, cont;
for (incr = 0; incr < 13; incr++){
cont = 0;
for (i = 0; i < 4; i++){
for (j = incr; j <= incr; j++){
if (d2[i][j] == 1)
cont++;
}
}
if (cont == 2)
return 9;
}
return 0;
}
void point(int p)
{
switch (p){
case 1:
printf("\nROYAL FLUSH\n");
break;
case 2:
printf("\nSTRAIGHT FLUSH\n");
break;
case 3:
printf("\nPOKER\n");
break;
case 4:
printf("\nFULL HOUSE\n");
break;
case 5:
printf("\nFLUSH\n");
break;
case 6:
printf("\nSTRAIGHT\n");
break;
case 7:
printf("\nTHREE OF A KIND\n");
break;
case 8:
printf("\nTWO PAIR\n");
break;
case 9:
printf("\nPAIR\n");
break;
default:
printf("\nHIGH CARD\n");
}
}
void bubble(int n[], int size)
{
int i, j, temp;
for (i = 0; i < size - 1; i++){
for (j = i + 1; j < size; j++){
if (n[i] > n[j]){
temp = n[i];
n[i] = n[j];
n[j] = temp;
}
}
}
}
#include<stdio.h>
#define SIZE 1000
void cribaDeEratostenes(int [], int , int);
main()
{
int vectorPrimo[SIZE];
int i, num;
for (i = 1; i <= SIZE; i++)
vectorPrimo[i] = 1;
for (i = 2; i <= SIZE; i++)
if (vectorPrimo[i] == 1){
cribaDeEratostenes(vectorPrimo, i, SIZE);
printf("%-5d", i);
}
return 0;
}
void cribaDeEratostenes(int v[], int n, int size)
{
int i = n;
for (i += n; i <= size; i += n)
v[i] = 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SIZE 20
void generarRandom(int [], int);
void ordenarVector(int [], int);
void mostrarVector(int [], int);
main()
{
srand(time(NULL));
int vector[SIZE] = {0};
generarRandom(vector, SIZE);
ordenarVector(vector, SIZE);
mostrarVector(vector, SIZE);
return 0;
}
void generarRandom(int v[], int size)
{
int i, j, num, dupl;
printf("RANDOM\n");
for (i = 0; i < size; i++){
num = 1 + rand() % size;
dupl = 0;
printf("%-4d", num);
for (j = 0; j <= i; j++){
if (num == v[j]){
dupl = 1;
break;
}
}
if (dupl == 1)
i--;
else
v[i] = num;
}
}
void ordenarVector(int v[], int size)
{
int i, j, temp;
for (i = 0; i < size - 1; i++){
for (j = i+1; j < size; j++){
if (v[i] > v[j]){
temp = v[i];
v[i] = v[j];
v[j] = temp;
}
}
}
}
void mostrarVector(int v[], int size)
{
int i;
printf("\n\nVECTOR\n");
for (i = 0; i < size; i++)
printf("%d\n", v[i]);
}