Documente Academic
Documente Profesional
Documente Cultură
Prob4 nerecursiv
#include <stdio.h>
#include <iostream.h>
#include <math.h>
int n,k,sum;
int main()
cout <<"n=";
cin >>n;
if (n>=1)
sum=sum+(4*k-3);
<<sum<< endl;
return 0;
}
Prob4 recursiva
#include <stdio.h>
#include <iostream.h>
#include <math.h>
int n,k,s;
if (n==0) return 0;
int main()
cout <<"n=";
cin >>n;
return 0;
}
Prob5 recursiva
#include <stdio.h>
#include <iostream.h>
#include <math.h>
int n,k,s;
int suma (int n)
if (n==0) return 0;
int main()
cout <<"n=";
cin >>n;
return 0;
}
Prob5 nerecursiv
#include <stdio.h>
#include <iostream.h>
#include <math.h>
int n,k,sum;
int main()
cout <<"n=";
cin >>n;
if (n>=1)
{
sum=sum+(5*k-4);
<<sum<< endl;
return 0;
}
Prob6 recursiv
#include <stdio.h>
#include <iostream.h>
#include <math.h>
#include <conio.h>
int a,b;
if (a==b)return a;
int main()
{
cout <<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"CMMDC("<<a<<","<<b<<")="
<<CMMDC (a,b);
getch ();
return 0;
}
Prob6 nerecursiv
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
int a,b,a1,b1;
int main()
cin>>a1;
a=a1;
cout<<"Dati b1=";
cin>>b1;
b=b1;
while (a!=b)
{
if (a>b) a=a-b;
if (b>a) b=b-a;
if (a==b)
cout<<"CMMDC("<<a1<<","<<b1<<")="<<a;
getch ();
return 0;
Prob7
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
int a,b,c;
if (a==b)return a;
int main()
cin>>a;
cout<<"Dati b=";
cin>>b;
cout<<"Dati c=";
cin>>c;
if ((a>0)&&(b>0)&&(c>0))
getch ();
return 0;
}
Nerecursiv
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
int a,b,c,a1,b1,c1;
int main()
cin>>a1;
a=a1;
cout<<"Dati b1=";
cin>>b1;
b=b1;
cout<<"Dati c1=";
cin>>c1;
c=c1;
while (a!=b)
if (a>b) a=a-b;
if (b>a) b=b-a;
while (a!=c)
if (a>c) a=a-c;
if (c>a) c=c-a;
while (c!=b)
if (b>c) b=b-c;
if (c>b) c=c-b;
if ((a>0)&&(b>0)&&(c>0));
if ((a==b)&& (a==c))
cout<<"CMMDC("<<a1<<","<<b1<<","<<c1<<")="<<a;
getch ();
return 0;
}
Prob8 recursivitatea indirecta
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
int x;
int f(int x)
if (x>1)return g(x)-2;
if (x<=1)return x+2;
int g(int x)
{
if (x<0)return -x;
if (x>=0)return f(-x)+1;
int main()
cin >>x;
cout <<"f(x)="<<f(x)<<endl;
cout <<"g(x)="<<g(x)<<endl;
getch ();
return 0;
}
Modernizat
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
int x;
int f(int x)
if (x>1)return g(x)-2;
if (x<=1)return x+2;
int g(int x)
if (x<0)return -x;
if (x>=0)return f(-x)+1;
int main()
cout <<"f("<<x<<")="<<f(x)<<endl;
cout <<"g("<<x<<")="<<g(x)<<endl;
getch ();
return 0;
}
Prob 10
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
int x;
int c(int x)
if (x<5)return b(x+1);
if (x>=5)return a(x)+1;
}
int b(int x)
if (x<5)return c(-1)-1;
if (x>=5)return a(x)+5;
int a(int x)
if (x<6)return c(x-1);
if (x>=6)return b(x-2);
int main()
cin >>x;
cout <<"a("<<x<<")="<<a(x)<<endl;
cout <<"b("<<x<<")="<<b(x)<<endl;
cout <<"c("<<x<<")="<<c(x)<<endl;
getch ();
return 0;
}
Prob11
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
int n;
double a0,b0;
double b (int n)
double a (int n)
if (n==0)return a0;
int main ()
cin >>n;
cin>>a0;
cin>>b0;
if (n>=0)cout <<"a("<<n<<")="<<a(n)<<endl;
if (n>=0)cout <<"b("<<n<<")="<<b(n)<<endl;
getch ();
return 0;
Prob12
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
int n;
double a0,b0,c0;
double c (int n)
double a (int n)
if (n==0)return a0;
double b (int n)
if (n==0)return b0;
int main ()
cin>>a0;
cin>>b0;
cin>>c0;
if (n>=0)cout <<"a("<<n<<")="<<a(n)<<endl;
if (n>=0)cout <<"b("<<n<<")="<<b(n)<<endl;
if (n>=0)cout <<"c("<<n<<")="<<c(n)<<endl;
getch ();
return 0;
}
Prob13 recursiv
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
int m,n;
int main ()
cout<<"Dati m=";
cin>>m;
cout<<"Dati n=";
cin>>n;
cout<<"Ack("<<m<<","<<n<<")="<<ack(m,n);
getch(); return 0;
}
Prob 14 recursiv
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
int x;
int F(int x)
int main ()
cin >>x;
cout<<"F("<<x<<")="<<F(x);
getch ();
return 0;
}
Prob15 HERMITE
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
double x;
int n;
if (n==0)return 1; else
if (n==1)return x;
if(n>1)
return H1(x,n-1)-(n-1)*H1(x,n-2);
int main()
{
cout <<"Dati x="<<endl;
cin >>x;
cin >>n;
cout<<"H("<<x<<","<<n<<")="<<H1(x,n);
getch ();
return 0;
}
Prob16
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
double x;
int n;
if (n==0)return 1; else
if (n==1)return 0;
if(n>1)
return 2*x*T1(x,n-1)-T1(x,n-2);
int main()
{
cout <<"Dati x="<<endl;
cin >>x;
cin >>n;
cout<<"T("<<x<<","<<n<<")="<<T1(x,n);
getch ();
return 0;
}
Prob16 ROLLY1
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
double x;
int n;
if (n==0)return 1;
if (n==1)return 0;
if (n==2)return 2;else
if(n>=3)
return 3*x*R1(x,n-1)-R1(x,n-2)-0.01*R1(x,n-3);
int main()
{
cin >>x;
cin >>n;
cout<<"R("<<x<<","<<n<<")="<<R1(x,n);
getch ();
return 0;
}
Prob18 REULY1
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
double x;
int n;
if (n==0)return 1;
if (n==1)return 0;
if(n>10)
return 3*x*Z1(x,n-1)-(n-1)*Z1(x,n-2)-(n-2)*Z1(x,n-3);
int main()
{
cin >>x;
cin >>n;
cout<<"Z("<<x<<","<<n<<")="<<Z1(x,n);
getch ();
return 0;
}
Prob19 Manna-Pneuli2
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
int x;
int F(int x)
int main ()
cin >>x;
cout<<"F("<<x<<")="<<F(x);
getch ();
return 0;
#include <conio.h>
#include <iostream.h>
#include <math.h>
if (n==1)
{printf ("%c%c\n",X,Y);
else
H (n-1,X,Z,Y);
printf("%c%c\n",X,Y);
H (n-1,Z,Y,X);
int main ()
int n;
scanf("%d",&n);
H(n,'X','Y','Z');
getch ();
}
Program in C++
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
if (n==1)
cout <<X<<Y<<endl;
else
H (n-1,X,Z,Y);
cout <<X<<Y<<endl;
H (n-1,Z,Y,X);
int main ()
int n;
cin >>n;
H(n,'X','Y','Z');
getch ();
return 0;
}
Prob 21
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
double f(double x)
if (x<5)return 2*pow(x,2)+1;
if ((x>=5)&&(x<8))return pow(x,4)+2;
if (x>=8)return 3;
double g(double x)
if (x<=1)return 5*pow(x,2)-3*x+2;
int main ()
{double x;
cin >>x;
cout <<"f(g(f("<<x<<")))="<<f(g(f(x)))<<endl;
cout <<"g(f(g("<<x<<")))="<<g(f(g(x)))<<endl;
cout <<"f(g(f(g(f("<<x<<")))))="<<f(g(f(g(f(x)))))<<endl;
cout <<"f(g(f(f("<<x<<"))))="<<f(g(f(f(x))))<<endl;
cout <<"f(g(g(f(f("<<x<<")))))="<<f(g(g(f(f(x)))))<<endl;
getch ();
return 0;
}
Problema 25
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
int i,h,x,y;
double k;
if(i>0) {
delay(10);
A(i-1);x=x+h;y=y-h;lineto((double)x*k,(double)y*k);
B(i-1);x=x+h;x=x+h;lineto((double)x*k,(double)y*k);
D(i-1);x=x+h;y=y+h;lineto((double)x*k,(double)y*k);
A(i-1);
};
if(i>0) {
B(i-1);x=x-h;y=y-h;lineto((double)x*k,(double)y*k);
C(i-1);y=y-h;y=y-h;lineto((double)x*k,(double)y*k);
A(i-1);x=x+h;y=y-h;lineto((double)x*k,(double)y*k);
B(i-1);
if(i>0) {
C(i-1);x=x-h;y=y+h;lineto((double)x*k,(double)y*k);
D(i-1);x=x-h;x=x-h;lineto((double)x*k,(double)y*k);
B(i-1);x=x-h;y=y-h;lineto((double)x*k,(double)y*k);
C(i-1);
if(i>0) {
D(i-1);x=x+h;y=y+h;lineto((double)x*k,(double)y*k);
A(i-1);y=y+h;y=y+h;lineto((double)x*k,(double)y*k);
C(i-1);x=x-h;y=y+h;lineto((double)x*k,(double)y*k);
D(i-1);
void main(void)
clrscr();
errorcode = graphresult();
if (errorcode != grOk){
getch();
}else{
setbkcolor(15);
do{
moveto((double)x*k,(double)y*k);
A(i);x=x+h;y=y-h;lineto((double)x*k,(double)y*k);
B(i);x=x-h;y=y-h;lineto((double)x*k,(double)y*k);
C(i);x=x-h;y=y+h;lineto((double)x*k,(double)y*k);
D(i);x=x+h;y=y+h;lineto((double)x*k,(double)y*k);
}while (!(i==n));
getch();
closegraph();
}
N=1 n=2
n=3
N=5
N=8
Prob26
//covorul Sierpinski
#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
int n=100;
delay(1);
if(r>0){// 4 colturi
}
}
void main(void)
clrscr();
errorcode = graphresult();
if (errorcode != grOk){
getch();
}else{
setbkcolor(15);
setfillstyle(SOLID_FILL,1);
getch();
closegraph();
}
Prob28
#include <graphics.h>
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
{ x=ceil (xc+(x1-xc)*cos(unghi)-(y1-yc)*sin(unghi));
y= ceil (yc+(x1-xc)*sin(unghi)+(y1-yc)*cos(unghi));
void desenez (int x1, int y1, int x2, int y2, int n, int ls)
{int x,y;
if (n<=ls)
setcolor (l+random(14));
setcolor (1);
desenez (x2,y2,x,y,n+1,ls);
}
}
void main()
{randomize(); clrscr();
cout<<"ls="; cin>>ls;
errorcode = graphresult();
if (errorcode!=grOk){
getch();
}else{
setbkcolor (15);
getmaxy()-250,1, ls);
getch();
closegraph();
N=4
N=8
N=10
Prob27
#include <graphics.h>
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <math.h>
{ x = ceil(xc+(x1-xc)*cos(unghi)-
(y1-yc)*sin(unghi));
y = ceil(yc+(x1-xc)*sin(unghi)+
(y1-yc)*cos(unghi));
{ moveto(x1,y1);
lineto(div((2*x1+x2),3).quot,
div((2*y1+y2),3).quot);
lineto(x3,y3);
lineto(div((x1+2*x2),3).quot,
div((y1+2*y2),3).quot);
lineto(x2,y2);
{ int x,y;
rotplan(div((2*x1+x2),3).quot,
div((2*y1+y2),3).quot,
div((x1+2*x2),3).quot,
div((y1+2*y2),3).quot,
x,y,M_PI/3);
if (n<ls)
{generator(x1,y1,div((2*x1+x2),
3).quot,div((2*y1+y2),
3).quot,n+1,ls);
generator(div((2*x1+x2),
3).quot,div((2*y1+y2),
3).quot,x,y,n+1,ls);
generator(x,y,div((x1+2*x2),
3).quot,div((y1+2*y2),
3).quot,n+1,ls);
generator(div((x1+2*x2),
3).quot,div((y1+2*y2),
3).quot,x2,y2,n+1,ls);
else desenez(x1,y1,x2,y2,x,y);
void main()
clrscr();
errorcode = graphresult();
if (errorcode != grOk){
getch();
}else{
setbkcolor(15);
setfillstyle(SOLID_FILL,1);
setcolor(RED);
setlinestyle(SOLID_LINE, 0, 3);
L = getmaxx()-320;
generator(160,getmaxy()-150,
160+L,getmaxy()-150,1,ls);
generator(160+L,getmaxy()-
150,160+div(L,2).quot,
getmaxy()-150-
ceil(L*(sqrt(3)/2)),1,ls);
generator(160+div(L,2).quot,
getmaxy()-150-
ceil(L*(sqrt(3)/2)),160,
getmaxy()-150,1,ls);
setfillstyle(1,GREEN);
floodfill(div(getmaxx(),2)
.quot,div(getmaxx(),
2).quot,RED);
getch();
closegraph();
}
N=4
N=6
N=8
N=10