Baixe o app para aproveitar ainda mais
Prévia do material em texto
REPO RTE D T A I Alan OlivaresE-182 P R O UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.2.1 Your First Program UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.2.6 Whats ur name? Scenario: Write your f irst program in the "C" language. Just print your name 3 t imes. Remember to include a return statement and make proper use of the main function. Code: 1 #include <stdio.h> 2 3 int main(void) 4 { 5 puts ("Alan"); 6 puts ("Alan"); 7 puts ("Alan"); 8 return 0; 9 } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.2.6 Just numbers: Part 1 Scenario: Check the program in the editor. Find al l possible compilation errors and logic errors. Fix them. Your version of the program must print the same result as the expected output. Before you use the compiler, try to f ind the errors only by manual code analysis. Code: 1 #include <stdio.h> 2 3 int main(void) 4 { 5 printf("The value of f ive is: %d \n", 5); 6 return 0; 7 } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.1 Numbers and how the computers see them Scenario: Check the program in the editor. Find al l possible compilation errors and logic errors. Fix them. Your version of the program must print the same result as the expected output. Before you use the compiler, try to f ind the errors only by manual code analysis. Code: 1 #include <stdio.h> 2 3 int main(void) 4 { 5 printf("The value of f ive is: %d \n", 5); 6 return 0; 7 } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.8 Just Numbers 2 #include <stdio.h> /******************************************************************************* ******* writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion ******************************************************************************** *****/ int main() { printf("The value of six is: %d \n",16-10); return 0; } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.9 Just Numbers 3 #include <stdio.h> /********************************************************************************* ***** writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion ********************************************************************************* ****/ int main() { printf("The value of seven is: %d \n",7); printf("The value of eight is: %d \n",8); } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.10 Just Numbers 4 #include <stdio.h> /******************************************************************************* ******* writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion ******************************************************************************** *****/ int main() { printf("The value of nine is: %d \n", 0x9); printf("The value of ten is: %d \n", 0xA); return 0; } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.11 Just Numbers 5 #include <stdio.h> /******************************************************************************* ******* writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion ******************************************************************************** *****/ int main(void) { printf("The value of twenty-one is: %d \n", 0x15); printf("The value of twenty-two is: %d \n", 0x16); printf("The value of sixty-two is: %d \n", 0x3E); printf("The value of seventy-four is: %d \n", 0x4A); return 0; } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.12 Variable 1 #include <stdio.h> /******************************************************************************* ******* writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion ******************************************************************************** *****/ int main() { int Variable=10; printf("The value of ten is: %d \n",Variable); return 0; } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.13 Variable 2 #include <stdio.h> /******************************************************************************* ******* writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion ******************************************************************************** *****/ int main(void) { int seconds=60; int minutes=60; printf("One hour is %d seconds\n",seconds*minutes); return 0; } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.14 Variable 3 #include <stdio.h> /******************************************************************************* ******* writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion ******************************************************************************** *****/ int main(void) { int ipPart1 = 127; int ipPart2 = 0; int ipPart3 = 0; int ipPart4 = 1; printf("Localhost IP is %d.%d.%d.%d\n", ipPart1, ipPart2, ipPart3, ipPart4); } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.14 Variable 3 #include <stdio.h> /******************************************************************************* ******* writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion ******************************************************************************** *****/ int main(void) { int ipPart1 = 127; int ipPart2 = 0; int ipPart3 = 0; int ipPart4 = 1; printf("Localhost IP is %d.%d.%d.%d\n", ipPart1, ipPart2, ipPart3, ipPart4); } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.15 Variable 4 #include <stdio.h> /************************************************************************************** writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion *************************************************************************************/ int main(void) { int daysInJanuary=31; int daysInFebruary=29; int daysInMarch=31; int daysInApril=30; int daysInMay=31; int daysInJune=30; int daysInJuly=31; int daysInAugust=30; int daysInSeptember=31; int daysInOctober=30; int daysInNovember=31; int daysInDecember=30; int daysInSecondHalf=daysInJanuary+daysInDecember+daysInMarch+daysInApril+daysInMay+daysInJuly; int daysInFirstHalf=daysInJune+daysInAugust+daysInSeptember+daysInOctober+daysInNovember+daysInFebruary; printf("Days in the f irst half of the current year: %d\n",daysInFirstHalf); printf("Days in the second half of the current year: %d\n",daysInSecondHalf); printf("Days in the current year: %d\n",daysInFirstHalf+daysInSecondHalf); return 0; } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.15 Variable 4 #include <stdio.h> /************************************************************************************** writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion *************************************************************************************/ int main(void) { int daysInJanuary=31; int daysInFebruary=29; int daysInMarch=31; int daysInApril=30; int daysInMay=31; int daysInJune=30; int daysInJuly=31; int daysInAugust=30; int daysInSeptember=31; int daysInOctober=30; int daysInNovember=31; int daysInDecember=30; int daysInSecondHalf=daysInJanuary+daysInDecember+daysInMarch+daysInApril+daysInMay+daysInJuly; int daysInFirstHalf=daysInJune+daysInAugust+daysInSeptember+daysInOctober+daysInNovember+daysInFebruary; printf("Days in the f irst half of the current year: %d\n",daysInFirstHalf); printf("Days in the second half of the current year: %d\n",daysInSecondHalf); printf("Days in the current year: %d\n",daysInFirstHalf+daysInSecondHalf); return 0; } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.16 Variable 5 #include <stdio.h> /************************************************************************************** writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion *************************************************************************************/ int main(void) { int daysInJanuary=31; int daysInFebruary=28; int daysInMarch=31;int daysInApril=30; int daysInMay=31; int daysInJune=30; int daysInJuly=31; int daysInAugust=30; int daysInSeptember=31; int daysInOctober=30; int daysInNovember=31; int daysInDecember=31; int DaysinQ1ofthecurrentyear=daysInJanuary+daysInFebruary+daysInMarch; int DaysinQ2ofthecurrentyear=daysInApril+daysInMay+daysInJune; int DaysinQ3ofthecurrentyear=daysInJuly+daysInAugust+daysInSeptember; int DaysinQ4ofthecurrentyear=daysInOctober+daysInNovember+daysInDecember; printf("Days in Q1 of the current year: %d\n",DaysinQ1ofthecurrentyear); printf("Days in Q2 of the current year: %d\n",DaysinQ2ofthecurrentyear); printf("Days in Q3 of the current year: %d\n",DaysinQ3ofthecurrentyear); printf("Days in Q4 of the current year: %d\n",DaysinQ4ofthecurrentyear); return 0; } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I 1.1.3.17 Comments #include <stdio.h> /* we included stdio.h */ #include <stdlib.h> /* we included stdlib.h */ /************************************************************************************** writer: Alan Olivares Muñoz E182 Date: 8/12 Lenguaje de Programacion *************************************************************************************/ int main(void) { int v=10800; /* 3*60*60 */ int Second3=3*60; /* This is a variable to hold the value of 3 minutes in seconds */ int Seconds6=5*60; /* This is a variable to hold the value of 6 minutes in seconds */ f loat pi=3.141526; /* This is the value of pi */ printf (" value of v: %d \n", v); printf (" value of 3 minutes in seconds: %d \n", Second3); printf (" value of 6 minutes in seconds: %d \n", Seconds6); /*here we should print the v value, but a programmer didn't have time to write the code. However, he/she l ikes writ ing long, well formatted comments*/ } UTEQ- Querétaro México Alan Yael Olivares Muñoz D T A I Test Core1
Compartilhar