|
Mostrar Mensajes
|
Páginas: [1]
|
1
|
Programación / Programación C/C++ / Re: ayuda con detallitos en mi programa (OJO paciencia, soy novato)
|
en: 28 Diciembre 2014, 18:10 pm
|
abro mi cabecera stdio.h (codelite) esto me dice q el compilador trabaja dentro de el estandar C99, sin embargo tendre que estudiar mas, gracias por el apoyo! ahorita estoy con el libro de como programar en c/ c++ (deitel && deitel) 2da edicion me parece bastante completo. inclusibe pienso adquirir un tomo! saludos. ! /* Define ISO C stdio on top of C++ iostreams. Copyright (C) 1991, 1994-2008, 2009, 2010 Free Software Foundation, Inc. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */
/* * ISO C99 Standard: 7.19 Input/output <stdio.h> */
|
|
|
2
|
Programación / Programación C/C++ / ayuda con detallitos en mi programa (OJO paciencia, soy novato)
|
en: 25 Diciembre 2014, 04:32 am
|
tengo un detalle con este programita al elegir la opcion b) en la impresion de las traspuesta del arreglo bidimensional me imprime valores basura (en lo que vienen siendo las 2 ultimas filas de la traspuesta del arreglo bid.) no logro saber a que se debe. inclusibe pueden notar que en la linea de la insersion de valores al arreglo antes del scanf("%d", &array[f][c]); Uso la funcino flush_input(); para limpiar el buffer /*fflush por alguna razon no hace su trabajo*/ esta funcion la estructure de la siguiente manera: flush_input { int variable_entera; while ( (variable_entera = getchar()) != '\n' && variable_entera != EOF) ; }
#include <stdio.h> #include <string.h>
char Menu(void); void flush_input(void); int EvaluacionDeEleccion(char m); void OperandoLaOpcion(int eleccion); void CreacionEimpresionDeArregloUnidimensional(int size); void CreacionEimpresionDeArregloBidimensional(int filas, int columnas); int ConteoDeCadenaDeCaracteres(char *palabra);
int main(int argc, char **argv) { int eleccion; char m; printf("Hola usuario Bievenido a tu programa OPCIONES "); m = Menu(); eleccion = EvaluacionDeEleccion(m); OperandoLaOpcion(eleccion); return 0; }
void flush_input(void) { int ch; while( (ch = getchar()) != '\n' && ch != EOF) ; }
char Menu(void) { char option; printf(" \n a) creacion e impresion de un ciclo unidimiencional \n b) creacion e impresion de un ciclo bidimensional \n c) conteo de caracteres de una frase \n\n "); scanf("%c", &option); return option;; } int EvaluacionDeEleccion( char m) { if( m == 'a' || m == 'A' ) return 1; else if( m == 'b' || m == 'B' ) return 2; else if ( m == 'c' || m == 'C' ) return 3; else printf("OPCION NO VALIDA ! "); return 0; } void OperandoLaOpcion(int eleccion) { int size; int filas, columnas; char palabra[256]; int CaracteresContados; switch(eleccion) { case 1: printf(" Ingrese el tamano de su arreglo unidimensional: \n"); scanf("%d", &size); CreacionEimpresionDeArregloUnidimensional(size); break; case 2: printf("Ingresa las filas : \n"); flush_input(); scanf("%d",&filas); printf("Ingresa las columnas: \n"); flush_input(); scanf("%d", &columnas); CreacionEimpresionDeArregloBidimensional(filas, columnas); break; case 3: puts("ingresa una cadena de caracteres cualquiera: "); flush_input(); scanf("%s", &palabra); CaracteresContados = ConteoDeCadenaDeCaracteres(palabra); printf("tu palabra contiene %d caracteres ", CaracteresContados); break; } } void CreacionEimpresionDeArregloUnidimensional(int size) { int array[size]; int f; /*solicitud de valores al usuario para la creacion del arreglo unidimensional*/ for( f = 0; f < size; f ++ ) { printf("ingrese el valor deseado para la posicion [%d]: ", f); flush_input(); scanf("%d", &array[f]); }
/*impresion del array de manera normal*/ for( f = 0; f < size; f ++ ) { printf("%d \n", array[f]); } printf("\n"); /*impresion del array al rrevez */ for( f = size-1; f != -1; f-- ) /*nota: sin el menos uno me imprimia un valor basura*/ { printf("%d \n", array[f]); } } void CreacionEimpresionDeArregloBidimensional(int filas, int columnas) { int array[filas][columnas]; int f, c; /*solicitud de valores al usuario para formar el arreglo*/ for( f = 0; f < filas; f++ ) { for( c = 0; c < columnas; c++ ) { printf("ingrese el valor par la posicion [%d][%d]: ", f, c); flush_input(); scanf("%d", &array[f][c]); } } /*impresion normal del arreglo bidimensional*/ for( f = 0; f < filas; f++ ) { for( c = 0; c < columnas; c++ ) { printf("%d \t", array[f][c] ); } printf("\n"); } /*impresion de transpuesta del arreglo */ printf("\n\n"); for( c = 0; c < columnas; c++ ) { for( f = 0; f < filas; f++ ) { printf("%d \t", array[c][f] ); } printf("\n"); } } int ConteoDeCadenaDeCaracteres(char *palabra) { return strlen(palabra); }
|
|
|
3
|
Programación / Programación C/C++ / Aprendiendo el uso basico de apuntadores ! no me da el resultado correcto
|
en: 25 Diciembre 2014, 04:21 am
|
Que tal, apenas estoy aprendiendo el uso basico de apuntadores, hice este programita para calcular el promedio, sin embergo, me da mal el promedio, la pregunta es: que estoy haciendo mal ? #include <stdio.h> void SolicitudEingresoDeValores(float valor1, float valor2, float valor3, float valor4, float valor5); float Promedio(float *val1, float *val2, float *val3, float *val4, float *val5); /*declaracion de apuntadores*/ float *val1, *val2, *val3, *val4, *val5;
int main(int argc, char **argv) { float average; float valor1 = 0, valor2 = 0, valor3 = 0, valor4 = 0, valor5 = 0; SolicitudEingresoDeValores(valor1, valor2, valor3, valor4, valor5); average = Promedio(val1, val2, val3, val4, val5); printf("%10.2f \n", average); return 0; }
void SolicitudEingresoDeValores(float valor1, float valor2, float valor3, float valor4, float valor5) { printf("ingrese el primer valor: \n"); scanf("%f", &valor1); /*inicializo puntero*/ val1 = &valor1; printf("ingrese el primer valor: \n"); scanf("%f", &valor2);/*inicializo puntero*/ val2 = &valor2; printf("ingrese el primer valor: \n"); scanf("%f", &valor3);/*inicializo puntero*/ val3 = &valor3; printf("ingrese el primer valor: \n"); scanf("%f", &valor4);/*inicializo puntero*/ val4 = &valor4; printf("ingrese el primer valor: \n"); scanf("%f", &valor5);/*inicializo puntero*/ val5 = &valor5; } float Promedio(float *val1, float *val2, float *val3, float *val4, float *val5) {
float promedio; promedio = ( *val1 + *val2 + *val3 + *val4 + *val5 ) / 5; return promedio; }
|
|
|
|
|
|
|