--Originally published at Carlos David Mendoza
En este quiz teníamos que hacer 5 programas. Empecemos con el primero:
- En este caso teníamos que corregir el siguiente:
#include main() { /* PROGRAM TO PRINT OUT SPACE RESERVED FOR VARIABLES */ char c; short s; int i; unsigned int ui; unsigned long int ul; float f; double d; long double ld; cout << endl << "The storage space for each variable type is:" << endl; cout << endl << "char: \t\t\t%d bits",sizeof(c)*8; // \t means tab cout << endl << "short: \t\t\t%d bits",sizeof(s)*8; cout << endl << "int: \t\t\t%d bits",sizeof(i)*8; cout << endl << "unsigned int: \t\t%d bits",sizeof(ui)*8; cout << endl << "unsigned long int: \t%d bits",sizeof(ul)*8; cout << endl << "float: \t\t\t%d bits",sizeof(f)*8; cout << endl << "double: \t\t%d bits",sizeof(d)*8; cout << endl << "long double: \t\t%d bits",sizeof(ld)*8; }
Así que para corregir este teníamos que cambiar cout por printf ademas de agregar int antes de sizeof. Me quedo así:
- Write a program to read in a character, an integer, and a float, and print out the values, then cast to other types; so that the interaction with the user is something like the following:
Input a single character, followed by : h Input an integer, followed by : 4872 Input a float, followed by : 182.937 The character h when cast to an int gives value ????? The character h when cast to a float gives value ????? The integer 4872 when cast to a char gives value ? The integer 4872 when cast to a float gives value ????? The float 182.937 when cast to a char gives value ? The float 182.937 when cast to an int gives value ?????
Aquí era simplemente hacer el programa y convertir a char, float e int. Queda así:
3. Write a program to print the following pattern:
C Continue reading "Quiz Week 6"