tag:blogger.com,1999:blog-9971236286610959542024-02-06T21:23:40.271-06:00Ejercicios de programación en CEjercicios de programación resueltos en C.DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-997123628661095954.post-74087784561382773622017-07-15T18:49:00.000-06:002017-07-15T18:49:02.135-06:00Code<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> <span class="GramE">System.Collections.Generic</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> System.Text;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">using</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> <span class="GramE">System.Threading.Tasks</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">namespace</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> ConsoleApplication2<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">class</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> </span><span lang="EN-US" style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">Program</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">static</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> </span><span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">void</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;">
Main(</span><span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">string</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;">[]
args)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">for</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> (</span><span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">int</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;">
i = 0; i <= 10; i++) {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span lang="EN-US" style="color: blue; font-family: "consolas"; font-size: 9.5pt;">if</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"> (i % 2 == 0)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span lang="EN-US" style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">Console</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;">.WriteLine(i);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span lang="EN-US" style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">Console</span><span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;">.Read();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span lang="EN-US" style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt; margin-bottom: 0cm;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;">
</span>}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">}</span></div>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-69418781839104286592015-01-28T22:24:00.004-06:002021-03-16T19:53:28.982-06:00Ejercicio de Programación: 17<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto17() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 17. Leer un numero entero de tres digitos y determinar en que posicion esta el mayor digito.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, dig1, dig2, dig3;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("\\nIngrese un numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' } while (num < 100 || num > 999);');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig3 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig2 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig1 = num % 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' if (dig1 > dig2 && dig1 > dig3){');
texto.push('\r\n');
texto.push(' printf("\\nEl primer digito es el mayor\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else if (dig2 > dig1 && dig2 > dig3){');
texto.push('\r\n');
texto.push(' printf("\\nEl segundo digito es el mayor\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else if (dig3 > dig1 && dig3 > dig2){');
texto.push('\r\n');
texto.push(' printf("\\nEl tercer digito es el mayor\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else if( dig1 == dig2 && dig2 == dig3){');
texto.push('\r\n');
texto.push(' printf("\\nLos tres digitos son iguales\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else if ( dig1 == dig2 ){');
texto.push('\r\n');
texto.push(' printf("\\nDigito uno y dos son los mayores\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else if (dig1 == dig3){');
texto.push('\r\n');
texto.push(' printf("\\nDigito uno y tres son los mayores\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else if (dig2 == dig3){');
texto.push('\r\n');
texto.push(' printf("\\nDigito dos y tres son los mayores\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' system("pause");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar17(){
descargarArchivo(generarTexto17(), 'Ejercicio17.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de tres dígitos y determinar en qué posición está el mayor dígito.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar17();' value='Descargar' />
<br />
<pre><code class="C#">
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, dig1, dig2, dig3;
do{
printf("\nIngrese un numero: ");
scanf("%d", &num);
} while (num < 100 || num > 999);
dig3 = num % 10;
num = num / 10;
dig2 = num % 10;
num = num / 10;
dig1 = num % 10;
if (dig1 > dig2 && dig1 > dig3){
printf("\nEl primer digito es el mayor\n");
}
else if (dig2 > dig1 && dig2 > dig3){
printf("\nEl segundo digito es el mayor\n");
}
else if (dig3 > dig1 && dig3 > dig2){
printf("\nEl tercer digito es el mayor\n");
}
else if( dig1 == dig2 && dig2 == dig3){
printf("\nLos tres digitos son iguales\n");
}
else if ( dig1 == dig2 ){
printf("\nDigito uno y dos son los mayores\n");
}
else if (dig1 == dig3){
printf("\nDigito uno y tres son los mayores\n");
}
else if (dig2 == dig3){
printf("\nDigito dos y tres son los mayores\n");
}
system("pause");
return 0;
}
</code></pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-26884088015122630992015-01-28T22:04:00.002-06:002015-01-28T22:04:05.978-06:00Ejercicio de Programación: 16<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto16() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 16. Leer un numero entero de tres digitos y determinar si al menos dos de sus tres digitos son iguales.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, dig1, dig2, dig3;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("\\nIngrese un numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' } while (num < 100 || num > 999);');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig3 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig2 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig1 = num % 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' if (dig1 == dig2 && dig2 == dig3){');
texto.push('\r\n');
texto.push(' printf("\\nLos tres digitos son iguales\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else if ( (dig1 == dig2) || (dig1 == dig3) || (dig2 == dig3) ){');
texto.push('\r\n');
texto.push(' printf("\\nDos digitos son iguales\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("\\nNingun digito es igual\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' system("pause");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar16(){
descargarArchivo(generarTexto16(), 'Ejercicio16.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de tres dígitos y determinar si al menos dos de sus tres dígitos son iguales.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar16();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, dig1, dig2, dig3;
do{
printf("\nIngrese un numero: ");
scanf("%d", &num);
} while (num < 100 || num > 999);
dig3 = num % 10;
num = num / 10;
dig2 = num % 10;
num = num / 10;
dig1 = num % 10;
if (dig1 == dig2 && dig2 == dig3){
printf("\nLos tres digitos son iguales\n");
}
else if ( (dig1 == dig2) || (dig1 == dig3) || (dig2 == dig3) ){
printf("\nDos digitos son iguales\n");
}
else{
printf("\nNingun digito es igual\n");
}
system("pause");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-41228566725278168262015-01-28T21:54:00.000-06:002015-01-28T21:54:02.040-06:00Ejercicio de Programación: 15<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto15() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 15. Leer un numero entero de tres digitos y determinar a cuanto es igual la suma de sus digitos.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, dig1, dig2, dig3;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("\\nIngrese un numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' } while (num < 100 || num > 999);');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig3 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig2 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig1 = num % 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' printf("\\n%d + %d + %d = %d\\n", dig1, dig2, dig3, (dig1+dig2+dig3));');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' system("pause");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar15(){
descargarArchivo(generarTexto15(), 'Ejercicio15.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de tres dígitos y determinar a cuánto es igual la suma de sus dígitos.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar15();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, dig1, dig2, dig3;
do{
printf("\nIngrese un numero: ");
scanf("%d", &num);
} while (num < 100 || num > 999);
dig3 = num % 10;
num = num / 10;
dig2 = num % 10;
num = num / 10;
dig1 = num % 10;
printf("\n%d + %d + %d = %d\n", dig1, dig2, dig3, (dig1+dig2+dig3));
system("pause");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-82565290276245398922015-01-28T21:47:00.000-06:002015-01-28T21:47:01.007-06:00Ejercicio de Programación: 14<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto14() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 14. Leer dos numeros enteros de dos digitos y determinar a cuanto es igual la suma de todos los digitos.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int n1, n2;');
texto.push('\r\n');
texto.push(' int n1dig1, n1dig2;');
texto.push('\r\n');
texto.push(' int n2dig1, n2dig2;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("\\nIngrese N1: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &n1);');
texto.push('\r\n');
texto.push(' } while (n1 < 10 || n1 > 99);');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("\\nIngrese N2: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &n2);');
texto.push('\r\n');
texto.push(' } while (n2 < 10 || n2 > 99);');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' n1dig2 = n1 % 10;');
texto.push('\r\n');
texto.push(' n1 = n1 / 10;');
texto.push('\r\n');
texto.push(' n1dig1 = n1 % 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' n2dig2 = n2 % 10;');
texto.push('\r\n');
texto.push(' n2 = n2 / 10;');
texto.push('\r\n');
texto.push(' n2dig1 = n2 % 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' printf("\\n%d + %d + %d + %d = %d\\n", n1dig1, n1dig2, n2dig1, n2dig2, (n1dig1 + n1dig2 + n2dig1 + n2dig2));');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' system("pause");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar14(){
descargarArchivo(generarTexto14(), 'Ejercicio14.c');
}
</script>
<b>Enunciado:</b> Leer dos números enteros de dos dígitos y determinar a cuánto es igual la suma de todos los dígitos.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar14();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int n1, n2;
int n1dig1, n1dig2;
int n2dig1, n2dig2;
do{
printf("\nIngrese N1: ");
scanf("%d", &n1);
} while (n1 < 10 || n1 > 99);
do{
printf("\nIngrese N2: ");
scanf("%d", &n2);
} while (n2 < 10 || n2 > 99);
n1dig2 = n1 % 10;
n1 = n1 / 10;
n1dig1 = n1 % 10;
n2dig2 = n2 % 10;
n2 = n2 / 10;
n2dig1 = n2 % 10;
printf("\n%d + %d + %d + %d = %d\n", n1dig1, n1dig2, n2dig1, n2dig2, (n1dig1 + n1dig2 + n2dig1 + n2dig2));
system("pause");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-14005078701594621722015-01-28T21:36:00.003-06:002015-01-28T21:36:26.004-06:00Ejercicio de Programación: 13<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto13() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 13. Leer dos numeros enteros de dos digitos y determinar si la suma de los dos numeros origina un numero par.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int n1, n2;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("\\nIngrese N1: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &n1);');
texto.push('\r\n');
texto.push(' } while (n1 < 10 || n1 > 99);');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("\\nIngrese N2: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &n2);');
texto.push('\r\n');
texto.push(' } while (n2 < 10 || n2 > 99);');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' if (((n1 + n2) % 2) == 0){');
texto.push('\r\n');
texto.push(' printf("\\n%d + %d = %d origina un numero par\\n", n1, n2, n1+n2);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("\\n%d + %d = %d NO origina un numero par\\n", n1, n2, n1+n2);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' system("pause");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar13(){
descargarArchivo(generarTexto13(), 'Ejercicio13.c');
}
</script>
<b>Enunciado:</b> Leer dos números enteros de dos dígitos y determinar si la suma de los dos números origina un número par.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar13();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int n1, n2;
do{
printf("\nIngrese N1: ");
scanf("%d", &n1);
} while (n1 < 10 || n1 > 99);
do{
printf("\nIngrese N2: ");
scanf("%d", &n2);
} while (n2 < 10 || n2 > 99);
if (((n1 + n2) % 2) == 0){
printf("\n%d + %d = %d origina un numero par\n", n1, n2, n1+n2);
}
else{
printf("\n%d + %d = %d NO origina un numero par\n", n1, n2, n1+n2);
}
system("pause");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com1tag:blogger.com,1999:blog-997123628661095954.post-23898489718120575032014-02-17T10:58:00.000-06:002015-01-01T03:03:59.057-06:00Ejercicio de programación: 12<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto12() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 12. Leer dos numeros enteros de dos digitos y determinar si tienen digitos comunes.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num1, num2, i, j;');
texto.push('\r\n');
texto.push(' int matriz[2][2];');
texto.push('\r\n');
texto.push(' int bandera = 0;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("Ingrese el primer numero de 2 digitos: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num1);');
texto.push('\r\n');
texto.push(' }while( num1 < 10 || num1 > 99 );');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("Ingrese el segundo numero de 2 digitos: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num2);');
texto.push('\r\n');
texto.push(' }while( num2 < 10 || num2 > 99 );');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' for( i = 1; i >= 0 ; i--){');
texto.push('\r\n');
texto.push(' matriz[0][i] = num1 % 10;');
texto.push('\r\n');
texto.push(' num1 = num1 / 10;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' matriz[1][i] = num2 % 10;');
texto.push('\r\n');
texto.push(' num2 = num2 / 10;');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' for(i = 0; i < 2; i++){');
texto.push('\r\n');
texto.push(' for(j = 0; j < 2; j++){');
texto.push('\r\n');
texto.push(' if( matriz[0][i] == matriz[1][j] ){');
texto.push('\r\n');
texto.push(' bandera = 1;');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if(bandera == 1){');
texto.push('\r\n');
texto.push(' printf("los dos numeros tienen digitos en comun\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("los dos numeros NO tienen digitos en comun\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("PAUSE");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar12(){
descargarArchivo(generarTexto12(), 'Ejercicio12.c');
}
</script>
<b>Enunciado:</b> Leer dos números enteros de dos dígitos y determinar si tienen dígitos comunes.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar12();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num1, num2, i, j;
int matriz[2][2];
int bandera = 0;
do{
printf("Ingrese el primer numero de 2 digitos: ");
scanf("%d", &num1);
}while( num1 < 10 || num1 > 99 );
do{
printf("Ingrese el segundo numero de 2 digitos: ");
scanf("%d", &num2);
}while( num2 < 10 || num2 > 99 );
for( i = 1; i >= 0 ; i--){
matriz[0][i] = num1 % 10;
num1 = num1 / 10;
matriz[1][i] = num2 % 10;
num2 = num2 / 10;
}
for(i = 0; i < 2; i++){
for(j = 0; j < 2; j++){
if( matriz[0][i] == matriz[1][j] ){
bandera = 1;
}
}
}
if(bandera == 1){
printf("los dos numeros tienen digitos en comun\n");
}
else{
printf("los dos numeros NO tienen digitos en comun\n");
}
system("PAUSE");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-43150064767058478682014-02-17T10:55:00.001-06:002015-01-01T03:13:04.011-06:00Ejercicio de programación: 11<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto11() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 11. Leer dos numeros enteros y determinar cual es el mayor.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num1, num2;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' printf("Ingrese el primer numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num1);');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' printf("Ingrese el segundo numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num2);');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if( num1 > num2 ){');
texto.push('\r\n');
texto.push(' printf("%d es el mayor\\n", num1);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("%d es el mayor\\n", num2);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("PAUSE");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar11(){
descargarArchivo(generarTexto11(), 'Ejercicio11.c');
}
</script>
<b>Enunciado:</b> Leer dos números enteros y determinar cuál es el mayor.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar11();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num1, num2;
printf("Ingrese el primer numero: ");
scanf("%d", &num1);
printf("Ingrese el segundo numero: ");
scanf("%d", &num2);
if( num1 > num2 ){
printf("%d es el mayor\n", num1);
}
else{
printf("%d es el mayor\n", num2);
}
system("PAUSE");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-90444305255903721172014-02-17T10:53:00.000-06:002015-01-01T02:59:57.042-06:00Ejercicio de programación: 10<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto10() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 10. Leer un numero entero de dos digitos y determinar si los dos digitos son iguales.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, dig1, dig2;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero de 2 digitos: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' }while( num < 10 || num > 99 );');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' dig2 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' dig1 = num %10;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if( dig1 == dig2 ){');
texto.push('\r\n');
texto.push(' printf("Los dos digitos son iguales\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("Los dos digitos son distintos\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("PAUSE");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar10(){
descargarArchivo(generarTexto10(), 'Ejercicio10.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de dos dígitos y determinar si los dos dígitos son iguales.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar10();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, dig1, dig2;
do{
printf("Ingrese un numero de 2 digitos: ");
scanf("%d", &num);
}while( num < 10 || num > 99 );
dig2 = num % 10;
num = num / 10;
dig1 = num %10;
if( dig1 == dig2 ){
printf("Los dos digitos son iguales\n");
}
else{
printf("Los dos digitos son distintos\n");
}
system("PAUSE");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-24066086293618358932014-02-17T10:44:00.000-06:002015-01-01T02:58:39.170-06:00Ejercicio de programación: 9<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto9() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 9. Leer un numero entero de dos digitos y determinar si un digito es multiplo del otro.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, dig1, dig2;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero de 2 digitos: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' }while( num < 10 || num > 99 );');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' dig2 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' dig1 = num %10;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if( dig1 != 0 && dig2 != 0 ){');
texto.push('\r\n');
texto.push(' if( dig1 % dig2 == 0 ){');
texto.push('\r\n');
texto.push(' printf("%d es multiplo de %d\\n", dig1, dig2);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' if( dig2 % dig1 == 0 ){');
texto.push('\r\n');
texto.push(' printf("%d es multiplo de %d\\n", dig2, dig1);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("No se encontro ninguno que sea multiplo\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' if(dig1 == 0){');
texto.push('\r\n');
texto.push(' printf("%d es multiplo de %d\\n", dig1, dig2);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("%d es multiplo de %d\\n", dig2, dig1);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("PAUSE");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar9(){
descargarArchivo(generarTexto9(), 'Ejercicio9.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de dos dígitos y determinar si un dígito es múltiplo del otro.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar9();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, dig1, dig2;
do{
printf("Ingrese un numero de 2 digitos: ");
scanf("%d", &num);
}while( num < 10 || num > 99 );
dig2 = num % 10;
num = num / 10;
dig1 = num %10;
if( dig1 != 0 && dig2 != 0 ){
if( dig1 % dig2 == 0 ){
printf("%d es multiplo de %d\n", dig1, dig2);
}
else{
if( dig2 % dig1 == 0 ){
printf("%d es multiplo de %d\n", dig2, dig1);
}
else{
printf("No se encontro ninguno que sea multiplo\n");
}
}
}
else{
if(dig1 == 0){
printf("%d es multiplo de %d\n", dig1, dig2);
}
else{
printf("%d es multiplo de %d\n", dig2, dig1);
}
}
system("PAUSE");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-51762839153975277792014-02-09T00:07:00.000-06:002015-01-01T02:57:02.479-06:00Ejercicio de programación: 8<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto8() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 8. Leer un numero entero de dos digitos y determinar si sus dos digitos son primos.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, dig1, dig2, i;');
texto.push('\r\n');
texto.push(' int d1 = 0, d2 = 0;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero de dos digitos:");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' }while( num < 10 || num > 99 );');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' dig2 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' dig1 = num % 10;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' for( i=1; i<= dig1; i++ ){');
texto.push('\r\n');
texto.push(' if( (dig1 % i) == 0 ){');
texto.push('\r\n');
texto.push(' d1++;');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' for( i=1; i<= dig2; i++ ){');
texto.push('\r\n');
texto.push(' if( (dig2 % i) == 0 ){');
texto.push('\r\n');
texto.push(' d2++;');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if( d1 == 2 && d2 == 2 ){');
texto.push('\r\n');
texto.push(' printf("Los dos digitos son primos\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' if( d1 == 2 ){');
texto.push('\r\n');
texto.push(' printf("%d es primo\\n%d NO es primo\\n", dig1, dig2);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' if( d2 == 2 ){');
texto.push('\r\n');
texto.push(' printf("%d NO es primo\\n%d es primo\\n", dig1, dig2);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' if( d1 != 2 && d2 != 2 ){');
texto.push('\r\n');
texto.push(' printf("Ninguno de los dos digitos son primos\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("PAUSE");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar8(){
descargarArchivo(generarTexto8(), 'Ejercicio8.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de dos dígitos y determinar si sus dos dígitos son primos.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar8();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, dig1, dig2, i;
int d1 = 0, d2 = 0;
do{
printf("Ingrese un numero de dos digitos:");
scanf("%d", &num);
}while( num < 10 || num > 99 );
dig2 = num % 10;
num = num / 10;
dig1 = num % 10;
for( i=1; i<= dig1; i++ ){
if( (dig1 % i) == 0 ){
d1++;
}
}
for( i=1; i<= dig2; i++ ){
if( (dig2 % i) == 0 ){
d2++;
}
}
if( d1 == 2 && d2 == 2 ){
printf("Los dos digitos son primos\n");
}
else{
if( d1 == 2 ){
printf("%d es primo\n%d NO es primo\n", dig1, dig2);
}
if( d2 == 2 ){
printf("%d NO es primo\n%d es primo\n", dig1, dig2);
}
if( d1 != 2 && d2 != 2 ){
printf("Ninguno de los dos digitos son primos\n");
}
}
system("PAUSE");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-88673419949057581792014-02-09T00:03:00.000-06:002015-01-01T13:12:41.407-06:00Ejercicio de programación: 7<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto7() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 7. Leer un numero entero de dos digitos y determinar si es primo y ademas si es negativo.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push('#include <math.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, i;');
texto.push('\r\n');
texto.push(' int divisoresCont = 0;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero entre -99 y 99: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' }while( (num < -99 || num > 99) || (num > -10 && num < 10));');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' for( i = 1; i <= abs(num); i++ ){');
texto.push('\r\n');
texto.push(' if( (abs(num) % i) == 0 ){');
texto.push('\r\n');
texto.push(' divisoresCont++;');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if( divisoresCont == 2 ){');
texto.push('\r\n');
texto.push(' printf("El numero ingresado es primo\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("El numero ingresado NO es primo\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if( num < 0 ){');
texto.push('\r\n');
texto.push(' printf("Es negativo\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("NO es negativo\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("PAUSE");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar7(){
descargarArchivo(generarTexto7(), 'Ejercicio7.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de dos dígitos y determinar si es primo y además si es negativo.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar7();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
int num, i;
int divisoresCont = 0;
do{
printf("Ingrese un numero entre -99 y 99: ");
scanf("%d", &num);
}while( (num < -99 || num > 99) || (num > -10 && num < 10));
for( i = 1; i <= abs(num); i++ ){
if( (abs(num) % i) == 0 ){
divisoresCont++;
}
}
if( divisoresCont == 2 ){
printf("El numero ingresado es primo\n");
}
else{
printf("El numero ingresado NO es primo\n");
}
if( num < 0 ){
printf("Es negativo\n");
}
else{
printf("NO es negativo\n");
}
system("PAUSE");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-38940958299468737492014-02-08T23:59:00.000-06:002015-01-01T13:13:04.475-06:00Ejercicio de programación: 6<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto6() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 6. Leer un numero entero de dos digitos menor que 20 y determinar si es primo.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, i;');
texto.push('\r\n');
texto.push(' int divisoresCont = 0 ;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' }while(num < 10 || num >= 20 );');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' for( i=1; i <= num; i++ ){');
texto.push('\r\n');
texto.push(' if( (num % i) == 0 ){');
texto.push('\r\n');
texto.push(' divisoresCont++;');
texto.push('\r\n');
texto.push(' } ');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if( divisoresCont == 2 ){');
texto.push('\r\n');
texto.push(' printf("El numero ingresado es primo\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("El numero ingresado NO es primo\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("PAUSE");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar6(){
descargarArchivo(generarTexto6(), 'Ejercicio6.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de dos dígitos menor que 20 y determinar si es primo.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar6();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, i;
int divisoresCont = 0 ;
do{
printf("Ingrese un numero: ");
scanf("%d", &num);
}while(num < 10 || num >= 20 );
for( i=1; i <= num; i++ ){
if( (num % i) == 0 ){
divisoresCont++;
}
}
if( divisoresCont == 2 ){
printf("El numero ingresado es primo\n");
}
else{
printf("El numero ingresado NO es primo\n");
}
system("PAUSE");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-62806559831262195142013-03-17T09:16:00.000-06:002015-01-01T13:13:26.148-06:00Ejercicio de programación: 5<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto5() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 5. Leer un numero entero de dos digitos y determinar si ambos digitos son pares.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, dig1, dig2;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' }while( num < 10 || num > 99 );// Validacion de 2 digitos');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig2 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' dig1 = num % 10;');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' if ( dig1 % 2 == 0 && dig2 % 2 == 0 ){');
texto.push('\r\n');
texto.push(' printf("Ambos digitos son pares!\\n %d y %d\\n", dig1, dig2);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' if ( dig1 % 2 == 0 ){');
texto.push('\r\n');
texto.push(' printf("Solo el primer digito es par %d\\n", dig1);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' if ( dig2 % 2 == 0 ){');
texto.push('\r\n');
texto.push(' printf("Solo el segundo digito es par %d\\n", dig2);');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push('');
texto.push('\r\n');
texto.push(' system("pause");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar5(){
descargarArchivo(generarTexto5(), 'Ejercicio5.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de dos dígitos y determinar si ambos dígitos son pares.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar5();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, dig1, dig2;
do{
printf("Ingrese un numero: ");
scanf("%d", &num);
}while( num < 10 || num > 99 );// Validacion de 2 digitos
dig2 = num % 10;
num = num / 10;
dig1 = num % 10;
if ( dig1 % 2 == 0 && dig2 % 2 == 0 ){
printf("Ambos digitos son pares!\n %d y %d\n", dig1, dig2);
}
else{
if ( dig1 % 2 == 0 ){
printf("Solo el primer digito es par %d\n", dig1);
}
if ( dig2 % 2 == 0 ){
printf("Solo el segundo digito es par %d\n", dig2);
}
}
system("pause");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-78061019161702670882013-03-17T09:01:00.001-06:002015-01-01T13:13:48.125-06:00Ejercicio de programación: 4<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto4() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 4. Leer un numero entero de dos digitos y determinar a cuanto es igual la suma de sus digitos.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num, dig1, dig2, suma;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' do{');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' }while( num < 10 || num > 99 );// Validacion de 2 digitos');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' dig1 = num % 10;');
texto.push('\r\n');
texto.push(' num = num / 10;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' dig2 = num % 10;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' suma = dig1 + dig2;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' printf("La suma de los dos digitos %d + %d es: %d\\n",dig2, dig1, suma);');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("pause");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar4(){
descargarArchivo(generarTexto4(), 'Ejercicio4.c');
}
</script>
<b>Enunciado:</b> Leer un número entero de dos dígitos y determinar a cuánto es igual la suma de sus dígitos.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar4();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, dig1, dig2, suma;
do{
printf("Ingrese un numero: ");
scanf("%d", &num);
}while( num < 10 || num > 99 );// Validacion de 2 digitos
dig1 = num % 10;
num = num / 10;
dig2 = num % 10;
suma = dig1 + dig2;
printf("La suma de los dos digitos %d + %d es: %d\n",dig2, dig1, suma);
system("pause");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-40263101761480851842013-03-16T18:18:00.000-06:002015-01-01T13:14:02.338-06:00Ejercicio de programación: 3<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto3() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 3. Leer un numero entero y determinar si es negativo.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int num;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &num);');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if( num < 0 ){');
texto.push('\r\n');
texto.push(' printf("El numero ingresado es negativo!\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("El numero ingresado NO es negativo!\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("pause");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar3(){
descargarArchivo(generarTexto3(), 'Ejercicio3.c');
}
</script>
<b>Enunciado:</b> Leer un número entero y determinar si es negativo.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar3();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
int main(){
int num;
printf("Ingrese un numero: ");
scanf("%d", &num);
if( num < 0 ){
printf("El numero ingresado es negativo!\n");
}
else{
printf("El numero ingresado NO es negativo!\n");
}
system("pause");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-59441289424784156272012-12-27T22:12:00.001-06:002015-01-01T13:14:15.589-06:00Ejercicio de programación: 2<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto2() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 2. Leer un numero entero y determinar si tiene 3 digitos.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push('#include <math.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main(){');
texto.push('\r\n');
texto.push(' int numero;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero entero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &numero);');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if ( numero < 0 ){');
texto.push('\r\n');
texto.push(' numero = numero * -1;');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if ( numero >= 100 && numero <= 999 ){');
texto.push('\r\n');
texto.push(' printf("El numero ingresado tiene 3 digitos\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("El numero ingresado NO tiene 3 digitos\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("PAUSE");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar2(){
descargarArchivo(generarTexto2(), 'Ejercicio2.c');
}
</script>
<b>Enunciado:</b> Leer un número entero y determinar si tiene 3 dígitos.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar2();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
int numero;
printf("Ingrese un numero entero: ");
scanf("%d", &numero);
if ( numero < 0 ){
numero = numero * -1;
}
if ( numero >= 100 && numero <= 999 ){
printf("El numero ingresado tiene 3 digitos\n");
}
else{
printf("El numero ingresado NO tiene 3 digitos\n");
}
system("PAUSE");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0tag:blogger.com,1999:blog-997123628661095954.post-61170040845234576842012-12-11T22:21:00.000-06:002015-01-01T13:14:25.669-06:00Ejercicio de programación: 1<script>
function descargarArchivo(contenidoEnBlob, nombreArchivo) {
var reader = new FileReader();
reader.onload = function (event) {
var save = document.createElement('a');
save.href = event.target.result;
save.target = '_blank';
save.download = nombreArchivo || 'archivo.txt';
var clicEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
save.dispatchEvent(clicEvent);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
};
reader.readAsDataURL(contenidoEnBlob);
};
function generarTexto1() {
var texto = [];
texto.push(' // Descargado desde: http://ejerciciodeprogramacion.blogspot.com/');
texto.push('\r\n');
texto.push(' // 1. Leer un numero entero y determinar si es un numero terminado en 4.');
texto.push('\r\n');
texto.push('\r\n');
texto.push('#include <stdio.h>');
texto.push('\r\n');
texto.push('#include <stdlib.h>');
texto.push('\r\n');
texto.push('#include <math.h>');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push('int main()');
texto.push('\r\n');
texto.push('{');
texto.push('\r\n');
texto.push(' int numero;');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' printf("Ingrese un numero: ");');
texto.push('\r\n');
texto.push(' scanf("%d", &numero);');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' if( ( abs(numero) % 10) == 4 ){');
texto.push('\r\n');
texto.push(' printf("El numero SI termina en 4\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' else{');
texto.push('\r\n');
texto.push(' printf("El numero NO termina en 4\\n");');
texto.push('\r\n');
texto.push(' }');
texto.push('\r\n');
texto.push(' ');
texto.push('\r\n');
texto.push(' system("PAUSE");');
texto.push('\r\n');
texto.push(' return 0;');
texto.push('\r\n');
texto.push('}');
texto.push('\r\n');
return new Blob(texto, {
type: 'text/plain'
});
};
function descargar1(){
descargarArchivo(generarTexto1(), 'Ejercicio1.c');
}
</script>
<b>Enunciado:</b> Leer un número entero y determinar si es un número terminado en 4.<br />
<br />
<b>Código fuente en C:</b>
<input type='button' onClick='descargar1();' value='Descargar' />
<br />
<pre class='brush: c'>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int numero;
printf("Ingrese un numero: ");
scanf("%d", &numero);
if( ( abs(numero) % 10) == 4 ){
printf("El numero SI termina en 4\n");
}
else{
printf("El numero NO termina en 4\n");
}
system("PAUSE");
return 0;
}
</pre>
DXerohttp://www.blogger.com/profile/01962407676156931301noreply@blogger.com0