Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Ejercicios de Programacion C
Ejercicios de Programacion C
#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
#include<dos.h>
#include <string.h>
main ()
{
int c, x, r;
clscr ();
gotoxy (28,5); printf (“introduce el numero”)
scanf(“%d”, &x);
c= 2;
r= 1;
while ( (c<x) && (r!=0) )
{
r= x%c;
if (r!=0)
c= c+1;
}
if(r!=0)
{
gotoxy(20,15);
printf(“es un numero primo”);
}
else
{
gotoxy(20,15);
printf(“ no es un numero primo”);
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
main()
{
float p,c,t;
clrscr();
gotoxy(10,8);printf("indica el valor de p");
scanf("%f",&p);
gotoxy(10,9);printf("indica el valor de c");
scanf("%f",&c);
if(c<11)
t=(p*.95)*c;
else
if(c<21)
t=(p*.90)*c;
else
if(c<36)
t=(p*.85)*c;
else
t=(p*.75)*c;
printf("\n total a pagar %f",t);
gotoxy(18,36);printf("pulsa una tecla");
getch();
}
CARRERA
#include<stdio.h> Io=-1;
#include<conio.h> if(Co==1)
#include<stdlib.h> H=1;
#include<dos.h> break;
#include<string.h> case1:gotoxy(C1,10);printf(" ");
main() C1=C1+I1;
{ delay(15);
int x,Co,C1,C2,Io,I1,I2,H; gotoxy(C1,10);printf("C1");
clrscr(); if(C1==70)
srand(time(NULL)); I1=-1;
Co=1; if(C1==1)
C1=1; H=1;
C2=1; break;
Io=1; case2:gotoxy(C2,15);printf(" ");
I1=1; C2=C2+I2;
I2=1; delay(15);
H=0; gotoxy(C2,15);printf("Y2");
gotoxy(Co,5);printf("M"); if(C2==70)
gotoxy(C1,10);printf("C"); I2=-1;
gotoxy(C2,15);printf("y"); if(C2==1)
while(H==0) H=1;
{ break;
X=rand()%3; }
switch(X) }
{ gotoxy(30,24);printf("el ganador es
case0:gotoxy(Co,5);printf(" "); %d",X);
Co=Co+Io; getch();
delay(15); }
gotoxy(Co,5);printf("MO");
if(Co==70)
PROGRAMA QUE DARÁ LA FECHA DEL ÚLTIMO DOMINGO DE TODOS LOS MESES
1
Mes=1
PROGRAMA QUE DARÁ LA FECHA DEL ÚLTIMO DOMINGO DE TODOS LOS MESES
1
main();
{
Int mes,f,tm,r,td,rr;
char nmes[15];
clrscr();
mes=1;
While(mes<=12)
{
Swich(mes)
{
Case 1:{strcpy (nmes,"Enero"); tm=31; td=31; break;}
Case 2:{strcpy (nmes,"Febrero"); tm=28; td=59; break;}
Case 3:{strcpy (nmes,"Marzo"); tm=31; td=90; break;}
Case 4:{strcpy (nmes,"Abril"); tm=30; td=120; break;}
Case 5:{strcpy (nmes,"Mayo"); tm=31; td=151; break;}
Case 6:{strcpy (nmes,"Junio"); tm=30; td=181; break;}
Case 7:{strcpy (nmes,"Julio"); tm=31; td=212; break;}
Case 8:{strcpy (nmes,"Agosto"); tm=31; td=243; break;}
Case 9:{strcpy (nmes,"Septiembre"); tm=30; td=273; break;}
Case 10:{strcpy (nmes,"Octubre"); tm=31; td=304; break;}
Case 11:{strcpy (nmes,"Noviembre"); tm=31; td=334; break;}
Case 12:{strcpy (nmes,"Diciembre"); tm=31; td=365; break;}
}
f=tm-rr;
r= td%7;
Switch(r);
gotoxy(5,mes+1);
{
printf("mes=%s",names);
Case 0:{rr=2; break;}
gotoxy(30,mes+1);
Case 1:{rr=3; break;}
printf("ultimo domingo=%d",f);
Case 2:{rr=4; break;}
Case 3:{rr=5; break;}
mes=mes+1;
Case 4:{rr=6; break;}
}
Case 5:{rr=0; break;}
gotoxy(15,20);printf("pulsar cualquier tecla");
Case 6:{rr=1; break;}
getche();
}
}
#include<stdio.h>
#include<string.h>
#include<dos.h>
#include<conio.h>
char m[13][20]={"mes no
correcto","enero","febrero" ,"marzo","abril","mayo","junio","julio","agosto","septiembre","octu
bre","noviembre","diciembre"};
main()
{
intmes,longi,carac;
clrscr();
for(mes=1;mes<=!2;mes++)
{
gotoxy(10,mes);
printf("%s",m[mes]);
}
gotoxy("25+mes*4,carac+1")
Printf("%c",m[mes][carac]);
delay(30);
}
}
gotoxy(60,20);
printf("oprimir una tecla");
getche();
INICIO
H2,
H2, M1
M1
H2,
H2, M2
M2
H2, M2
Ca=Em=0
cH=0
ME<M5
CQ
CQ
ME=Me+1
CM
CM CH
CH
M1=M1+1
Ch
Ch
M1 FIN
15 30 45 60
td=días transcurridos
r=residuo
rr=días retrocedido
# include<stdio.h>
# include<conio.h>
# include<stdlib.h>
# include<dos.h>
# include<string.h>
Main()
{
Int mes,f,tm,r,td,rr;
Char nmes[15];
Clrscr();
Gotoxy(15,5); printf(“numero de mes”);
Scanf(“%d”,&mes);
Switch(mes)
{
Case1: {strcpy (nmes,”enero”); tm=31; td=31; break;}
Case1: {strcpy (nmes,”febrero”); tm=28; td=59; break;}
Case1: {strcpy (nmes,”marzo”); tm=31; td=90; break;}
Case1: {strcpy (nmes,”abril”); tm=30; td=120; break;}
Case1: {strcpy (nmes,”mayo”); tm=31; td=151; break;}
Case1: {strcpy (nmes,”junio”); tm=30; td=181; break;}
Case1: {strcpy (nmes,”julio”); tm=31; td=212; break;}
Case1: {strcpy (nmes,”agosto”); tm=31; td=243; break;}
Case1: {strcpy (nmes,”septiembre”); tm=30; td=273; break;}
Case1: {strcpy (nmes,”octubre”); tm=31; td=304; break;}
Case1: {strcpy (nmes,”noviembre”); tm=31; td=334; break;}
Case1: {strcpy (nmes,”diciembre”); tm=31; td=365; break;}
{
r=td%7;
switch®
{
Case 0: {rr=2; break;}
Case 0: {rr=3; break;}
Case 0: {rr=4; break;}
Case 0: {rr=5; break;}
Case 0: {rr=6; break;}
Case 0: {rr=20; break;}
Case 0: {rr=1; break;}
}
f=tm-rr;
printf(“\n fecha del ultimo domingo del mes=%d”,f);
gotoxy(15,20); printf(“pulsar cualquier tecla”);
getch()
}
/*GENERA 20 VALAS, HASTA QUE LLEGUEN A 70*/
# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
# include <dos.h>
# include <string.h>
Main()
{
Int c[20],I,x;
Clrscr();
Srand(time(NULL));
While(c[x]<70)
# include <stdio.h>
{
# include <conio.h>
X=(rand()%20)+1;
Gotoxy(c[x],x); printf(“”);
# include <stdlib.h>
C[x]=c[x]+1;
Delay(9);
# include <dos.h>
Gotoxy(c[x],x); printf(“%d”,x);
# include
} <string.h>
Main()
Gotoxy(10,5); printf(“fila ganadora=%d”,x);
{ Getch();
}
Int f,c;
Clrscr();
F=1;
C=80;
While(f<20)
Printf(“\n*=%d,*”);
F=f+1;
Getch();
}
# include <stdio.h>
# include <stdlib.h>
# include <dos.h>
# include <string.h>
Main()
Int f,c;
Clrscr();
F=20;
C=80;
While(f>0)
Printf(“\n*=%d,*”);
c=c-1;
Getch();
}
*/DISTINGUE SI EL NUMERO ES PAR O IMPAR/*
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <string.h>
Main()
{
Int C,CP,CI,N,X,R;
Clrscr();
C=0;
CP=0;
CI=0;
Gotxy(10,5);
Printf(“INTRODUCIR EL NUMERO DE DATOS”);
Scanf(“%d”,&N);
While(C<N)
{
Gotoxy(10,6+c);
Printf(“INTRODUCIR LA CANTIDAD”);
Scanf(“%d”,&X);
R=X%2;
If(R!=0)
{
Textcolor(13);
Gotoxy(60,6+C);cprintf(“NUMERO IMPAR”);
CI=CI+1;
}
Else
{
Textcolor(13);
Gotoxy(60,6+C);cprintf(“NUMERO PAR”);
CP=CP+1;
}
C=C+1;
}
Gotoxy(10,20);
Printf (“TOTAL DE NUMEROS IMPARES INTRODUCIDOS= %d”,CP);
Gotoxy(10,21);
Printf(“TOTAL DE NUMEROS IMPARES INTRODUCIDOS= %d”,CI);
Getch();
}
#include <string.h>
#include <stdlib.h>
#include <dos.h>
#include <stdio.h>
Int x[4][3];
Main()
{
Int c,f,s;
Clrscr();
For(f=1;f<=4;f=f+1)
{
S=0;
For(c=1;c<=3;c=c+1)
{
Gotoxy(c*5,f*2);
Scanf(“%d”,&x[f][c]);
S=S+x[f][c];
}
Gotoxy(25,f*2);
Printf(“%d”s);
}
Delay(20);
Clrscr();
For(c=1;c<=4;c=c+1)
{
S=0;
For(f=1;f<=3;f=f+1)
{
Gotoxy(c*5,f*2);
Scanf(“%d”,&x[c][f]);
S=S+x[c][f];
}
Gotoxy(c*5,10);printf(“%d”,s);
}
Getch();
}
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<string.h>
main()
{
int i,A[11]={0,1,2,3,4,5,6,7,8,9,10},x;
clrscr();
for(i=1; i<=10; i=i+1)
{
gotoxy(5,i);printf("%d",A[i]);
}
x=A[10];
for(i=9; i>=1; i=i-1)
{
A[i+1]=A[i];
}
A[1]=x;
for(i=1; i<=10; i=i+1)
{
gotoxy(20,i);printf("%d",A[1]);
}
getch();
}
PIRAMIDE #3
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<string.h>
main()
{
int cf,c,cl,f;
clrscr();
cf=80;
f=1;
while(f<=20)
{
c=80;
while(c>=(cf-20))
{
gotoxy(c,f);cprintf("$");
delay(30);
c=c-1;
}
f=f+1;
cf=cf+1;
}
getch();
}
PIRAMIDE #4
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<string.h>
main()
{
int nf,cf,ci,f,c;
clrscr();
nf=24;
f=1;
cf=41;
ci=41;
while(f<=nf)
{
c=ci;
while(c<=cf)
{
textcolor(c);
gotoxy(c,f);printf("&");
delay(30);
c=c+1;
}
f=f+1;
ci=ci-1;
cf=cf+1;
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
main()
{
intf,nf,c,cf;
clrscr();
cf=1;
f=1;
nf=24;
while (f<=nf)
{
c=1;
while (c<=cf)
{
textcolor(c);
gotoxy(c,f);printf(“myc 16”);
delay(30);
c=c+1;
}
cf=cf+1
f=f+1;
}
getche();
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
main()
{
intf,nf,c,cf;
clrscr();
nf=24;
cf=nf;
f=1;
while (f<=nf)
{
c=1;
while (c<=cf)
{
textcolor(c);
gotoxy(c,f);printf(“myc 16”);
delay(30);
c=c+1;
}
cf=cf-1
f=f+1;
}
getche();
}
/* GENERA DATOS DE 1 AL 100, PERMITE 40 DATOS QUE SE ALMACENA EN EL
ARREGLO X */
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
main()
{
int H,E,D,X[40],i,c,f;
clrscr();
srand(time(NULL));
H=0;
while (H<40)
{
E=0;
While(E==0)
{
E=1;
D=(rand()%101)+1;
for(i=0;i<40;i=i+1)
{
if(D==X[i])
E=0;
}
}
X[H]=D;
H=H+1;
}
C=10;
F=1;
for(i=0;i<40;i=i+1)
{
gotoxy(C,F);printf(“%d”,X[i]);
F=F+1;
if(F==21)
{
C=C+10;
F=1;
}
}
getch();
}
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
main ()
{
int c,cf,f;
clrscr()
c=1:
f=1:
while(c<80)
{
gotoxy(c,f):printf("*");
c=c+1;
}
getch();
}
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
main()
{
int a,b,x,y;
clrscr():
gotoxy(5,6);printf(“introducir el valor de a:”);
scanf(“%d”,&a);
gotoxy(5,7);printf(“introducir el valor de b:”);
scanf(“%d”,&b);
if(a>b)
{
x=1;
printf(“x=%d”,x);
}
else
{
y=4;
printf(”y=%d”,y);
}
gotoxy(10,8);printf(“hola”);
getch();
}
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
main()
{
int c,ic,f,tf;
clrscr();
c=1;
ic=1;
f=10;
tf=1;
textcolor(30);
gotoxy(c,f);printf(“myc16”);
while(!kbhit())
{
delay(5);
textcolor(30);
gotoxy(c,f);printf(“m”);
if(f==1)
tf=1;
if(f==22)
tf=-1;
if(c==80)
ic=-1;
if(c==1)
ic=1;
c=c+ic;
f=f+tf;
delay(5);
textcolor(30);
gotoxy(c,f);printf(“c”);
}
getch();
}