Modulo 2
Modulo 2
Lenguaje de programación
Alumno:
Alan Eduardo Ortega Herrera
Grupo:
E187
Profesor:
Código:
#include <stdio.h>
int main()
{
printf("The value of seven is: %f\n", 7.000000);
printf("The value of eight and a half is: %f\n", 8.500000);
return 0;
}
Código:
#include <stdio.h>
int main()
{
float tenValue = 10.000000;
printf("The value of nine is: %f\n", 9.000000);
printf("The value of ten is: %f\n", tenValue);
return 0;
}
2.1.1.8 LAB: Variables: Continued
Código:
#include <stdio.h>
int main()
{
float halfValue = 0.500000;
float piValue = 3.141593;
printf("The value of half is: %f\n", halfValue);
printf("The value of Pi is: %f\n", piValue);
return 0;
}
2.1.2.12 LAB: Operators: Part 1
Código:
#include <stdio.h>
int main()
{
float halfValue = 0.500000;
float piValue = 3.141593;
printf("The value of half is: %f\n", halfValue);
printf("The value of Pi is: %f\n", piValue);
return 0;
}
Código:
#include <stdio.h>
int main()
{
int fourValue, fiveValue;
fourValue = 2 + 2;
fiveValue = 2 + 3;
printf("The value of four is: %d\n", fourValue);
printf("The value of five is: %d\n", fiveValue);
return 0;
}
Código:
#include <stdio.h>
int main()
{
float tenValue, twelveValue;
Código:
#include <stdio.h>
int main()
{
float tenValue, twelveValue;
Código:
#include <stdio.h>
int main()
{
int tenValue = 3 * 8 % 14;
int twentyValue = 2 * tenValue + 10 % 5;
Código:
#include <stdio.h>
int main()
{
int xValue = 4 * 6 % 5;
int eightValue = 2 * xValue + 10 % 5;
printf("The value of eight is: %d\n", eightValue);
return 0;
}
2.1.2.17 LAB: Operators: Part 6
Código:
#include <stdio.h>
int main(void)
{
int xValue = 5;
int yValue = 9;
int result;
int bigResult;
xValue = xValue + 3;
yValue = yValue - xValue;
Código:
#include <stdio.h>
int main(void)
{
int xValue = 5;
int yValue = 9;
int result = (xValue + yValue) * 2;
int bigResult = xValue + yValue * 6;
Código:
#include <stdio.h>
int main(void)
{
int xValue = 3;
int yValue = 2;
int result = (xValue + yValue) * (2 + yValue);
int smallResult = xValue + yValue * (4 - xValue);
Código:
#include <stdio.h>
int main(void)
{
int xValue = 5;
int yValue = 3;
int result = (xValue % yValue) * (14 % yValue);
int smallResult = xValue + (10 % 4 % xValue);
Código:
#include <stdio.h>
int main(void)
{
float startValue = 100;
float interestRate = 0.015;
float firstYearValue = startValue + startValue * interestRate;
float secondYearValue = firstYearValue + firstYearValue * interestRate;
float thirdYearValue = secondYearValue + firstYearValue * interestRate;
Código:
#include <stdio.h>
int main(void)
{
int xValue = 5;
int yValue = 9;
int result;
int bigResult;
xValue += 3;
yValue -= xValue;
Código:
#include <stdio.h>
int main(void)
{
printf("Diff beetween '%c' and '%c' is : %d\n", 'c', 'a', 'c' - 'a');
printf("Diff beetween '%c' and '%c' is : %d\n", 'a', 'c', 'a' - 'c');
return 0;
}
2.1.3.9 LAB: Character types and values: Part 2
Código:
#include <stdio.h>
int main(void)
{
char firstLetter = 'A';
char firstSmallLetter = 'a';
char lastLetter = 'Z';
char lastSmallLetter = 'z';
printf("Upper case letters beetween (and with) '%c' and '%c' is : %d\n",
lastLetter, firstLetter, lastLetter - firstLetter + 1);
printf("Lower case letters beetween (and with) '%c' and '%c' is : %d\n",
lastSmallLetter, firstSmallLetter, lastSmallLetter - firstSmallLetter + 1);
return 0;
}
2.1.3.10 LAB: Character types and values: Part 3
Código:
#include <stdio.h>
int main(void)
{
char zero = '0';
Código:
#include <stdio.h>
int main(void)
{
int a = 10;
if (a > 9)
puts("First condition is true");
if (a < 9)
puts("Second condition is true");
if (a == 9 + 1)
puts("Third condition is true");
return 0;
}
2.1.4.9 LAB: Conditions and conditional executions: Part 2
Código:
#include <stdio.h>
int main(void)
{
int n = -3;
if (n < 0)
{
printf("The absolute value of %d is %d\n", n, -n);
}
printf("The value of n is %d\n", n);
return 0;
}
2.1.4.10 LAB: Conditions and conditional executions: Part 3
Código:
#include <stdio.h>
int main(void)
{
int dayOfWeek = 1;
if (dayOfWeek == 1)
puts("The day of the week is: Monday");
if (dayOfWeek == 2)
puts("The day of the week is: Tuesday" );
if (dayOfWeek == 3)
puts("The day of the week is: Wednesday");
if (dayOfWeek == 4)
puts("The day of the week is: Thursday");
if (dayOfWeek == 5)
puts("The day of the week is: Friday");
if (dayOfWeek == 6)
puts("The day of the week is: Saturday");
if (dayOfWeek == 0)
puts("The day of the week is: Sunday");
return 0;
}
Código:
#include <stdio.h>
int main(void) {
int VarInt;
char VarChar;
float VarFloat;
VarInt = 2012;
VarChar = 'r';
VarFloat = 3.1415;
Código:
#include <stdio.h>
int main(void) {
int i;
i = 31;
printf("%d %x %o", i, i, i);
return 0;
}
2.1.5.9 Formatted input/output
Código:
#include <stdio.h>
int main(void)
{
int value, square;
Código:
#include <stdio.h>
#include <math.h>
int main(void) {
float value, squareroot;
Código:
#include <stdio.h>
int main(void)
{
int day = 20;
int month = 2;
int year = 2016;
Código:
#include <stdio.h>
int main(void)
{
float studentAYear1 = 4.2;
float studentAYear2 = 4.5;
float studentAYear3 = 4.2;
Código:
#include <stdio.h>
int main(void)
{
printf(" ^\n");
printf(" / \\\n");
printf(" / \\\n");
printf("< >\n");
printf(" \\ /\n");
printf(" \\ /\n");
printf(" v\n");
return 0;
}
Código:
#include <stdio.h>
int main(void)
{
int daysCount;
float valuePi;
Código:
#include <stdio.h>
int main(void)
{
float valueA;
float valueB;
printf("Value A: ");
scanf("%f", &valueA);
printf("Value B: ");
scanf("%f", &valueB);
printf("%f + %f = %f.\n", valueA, valueB, valueA + valueB);
printf("%f - %f = %f.\n", valueA, valueB, valueA - valueB);
printf("%f * %f = %f.\n", valueA, valueB, valueA * valueB);
return 0;
}
2.1.5.16 LAB: Getting data from the user: Part 3
Código:
#include <stdio.h>
int main(void)
{
int day, month;
puts("day:");
scanf("%d", &day);
puts("month:");
scanf("%d", &month);
int dayOfYear = 0;
if (month > 1)
dayOfYear += 31;
if (month > 2)
dayOfYear += 29;
if (month > 3)
dayOfYear += 31;
if (month > 4)
dayOfYear += 30;
if (month > 5)
dayOfYear += 31;
if (month > 6)
dayOfYear += 30;
if (month > 7)
dayOfYear += 31;
if (month > 8)
dayOfYear += 31;
if (month > 9)
dayOfYear += 30;
dayOfYear += day;
printf("The day of the year : %d.\n", dayOfYear);
return 0;
}
2.1.5.17 LAB: Getting data from the user: Part 4
Código:
#include <stdio.h>
int main(void)
{
int day;
puts("day:");
scanf("%d", &day);
if (day == 1)
printf("The day of the weak is: Monday");
if (day == 2)
printf("The day of the weak is: Tuesday");
if (day == 3)
printf("The day of the weak is: Wednesday");
if (day == 4)
printf("The day of the weak is: Thursday");
if (day == 5)
printf("The day of the weak is: Friday");
if (day == 6)
printf("The day of the weak is: Saturday");
if (day == 7)
printf("The day of the weak is: Sunday");
if (day >= 8)
printf("There is no such day: %d.\n", day);
if (day >= 8)
printf("Input value must be from 0 to 6.");
return 0;
}
2.1.5.18 LAB: Getting data from the user: Part 5
Código:
#include <stdio.h>
int main(void)
{
int day, month, year;
puts("day:");
scanf("%d", &day);
puts("month:");
scanf("%d", &month);
puts("year:");
scanf("%d", &year);
int dayOfYear = 0;
if (month > 1)
dayOfYear += 31;
if (month > 2)
{
if (year / 10 == 4)
dayOfYear += 29;
else
dayOfYear += 28;
}
if (month > 3)
dayOfYear += 31;
if (month > 4)
dayOfYear += 30;
if (month > 5)
dayOfYear += 31;
if (month > 6)
dayOfYear += 30;
if (month > 7)
dayOfYear += 31;
if (month > 8)
dayOfYear += 31;
if (month > 9)
dayOfYear += 30;
return 0;
}