Sunteți pe pagina 1din 52

//Scrieti un program care realizeaza suma, diferenta, produsul si mpartirea a doua numere reale.

//Afisarea se va face sub forma tabelara: #include <stdio.h> #include <stdlib.h> int main() {float x,y; printf("X="); scanf("%f",&x); printf("Y="); scanf("%f",&y); printf("\n\n\t---------------------------------------------------------"); printf("\n\t| X | Y | X+Y | X-Y | X*Y | X/Y |"); printf("\n\t---------------------------------------------------------"); printf("\n\t|%7.2f|%7.2f|%9.2f|%9.2f|%9.2f|%9.2f|",x,y,x+y,x-y,x*y,x/y); printf("\n\t---------------------------------------------------------\n\n"); getchar(); getchar(); return 0; } /* S se scrie un program care citete un numr natural n intervalul [1600, 4900] ce reprezint un an i verific dac este bisect sau nu.*/ #include <stdio.h> #include <stdlib.h> int main() { int n; citire: {printf("n= "); scanf("%d",&n); goto verificare; } verificare: {if (n<=4900 && n>=1600) goto continuare; else { printf("valoare incorecta \n"); goto citire;} } continuare: { ((n%4==0 && n%100!=0)||(n%400==0))?printf("%d e an bisect\n",n):printf("%d nu e an bisect\n",n); getchar(); printf("\nContinuati ? (q to exit)"); if (getchar()!='q') goto citire; } return 0; }

/*Folosind expresii conditionale, sa se scrie un program care citeste valoarea reala a lui x si calculeaza valoarea functiei: f(x)={ 0 , x=0; x^2+5*x, x>-2 (x+2)^2, x<-2*/ #include <stdio.h> #include <stdlib.h> # include <math.h> int main() { float x; printf("x="); scanf("%f",&x); (x<-2)?printf("%10.2f",pow(x+2,2)):(x==0)?printf("0 "):(x>-2)?printf("%10.2f",x*x+5*x):printf("caz exceptat"); getchar(); getchar(); return 0; } /* 3.6. S se scrie un program care citete un numr real x, ce reprezint msura unui unghi n radiani, i l transform n grade, minute i secunde sexagesimale*/ #include <stdio.h> #include <stdlib.h> # include <math.h> int main() { float x,x1; int g,m,s; printf("x="); scanf("%f",&x); x1=x; x=x*180/M_PI; g=(int)x; x-=g; x*=60; m=(int)x; x-=m; x*=60; s=x; printf("%5.2f radiani are %d grade, %d minute, %d secunde",x1,g,m,s); getchar(); getchar(); return 0; }

/*Sa se scrie un program care simuleaza functionarea unui numarator de tip ceas (se indica ora, minutul si secunda).*/ #include <stdio.h> #include <stdlib.h> # include <time.h> //Problema facuta sub linux unde printf("\033[34m"); chiar se executa, sub windows stergeti acele printf int secunda() {clock_t start,stop; start=clock(); do{stop=clock(); }while(((stop-start)/CLOCKS_PER_SEC)<1); return 1; } int main() {char ch[30]; int h,m,s,a,b,c; printf("Specificati ora sub formatul HH:MM:SS: \n"); scanf("%d:%d:%d",&a,&b,&c); sprintf(ch,"%s",__TIME__); sscanf(ch,"%d:%d:%d",&h,&m,&s); printf("Ora curenta %s\n",ch); do { printf("\033[34m"); printf("%02d:%02d:%02d\n",h,m,s); printf("\033[4;1H"); if (secunda()) s++; if(s==60) {m++;s=0;} if(m==60) {h++;m=0;} if(h==24) {h=0;} }while((a*3600+b*60+c-h*3600-m*60-s)!=0); printf("%02d:%02d:%02d\n",h,m,s); printf("\033[36m"); printf("Apasati o tasta pentru a iesi");getchar(); getchar(); return 0;

/*Sa se scrie un program care citeste numerele ntregi a,b,c,d si determina cea mai mare dintre fractiile a/b si c/d.*/ #include <stdio.h> #include <stdlib.h> void citire(int *a) {printf("\nnr:"); scanf("%d",a); } int main() {int a,b,c,d; citire(&a); citire(&b);

citire(&c); citire(&d); if(a*d>b*c) printf("\n %d/%d > %d/%d",a,b,c,d); else if(a*d==b*c) printf("\n %d/%d = %d/%d",a,b,c,d); else printf("\n %d/%d < %d/%d",a,b,c,d); getchar(); getchar(); return 0;

/*Sa se stabileasca pozitia unei drepte fata de un cerc dat. Se citesc: coordonatele centrului cercului, raza acestuia, precum si coordonatele a doua puncte situate pe dreapta.*/ #include <stdio.h> #include <stdlib.h> #include <math.h> struct punct {int x,y; }; void citire(struct punct *a) {printf("\nx="); scanf("%d",&a->x); printf("y="); scanf("%d",&a->y); } float d(struct punct O,struct punct A,struct punct B) {float r,r1; if (B.x-A.x==0) return (A.x-O.x); r1=(float)(B.y-A.y)/(B.x-A.x); r=r1*O.x-r1*A.x+A.y-O.y; r=abs(r); r=r/sqrt(pow(r1,2)+1); return r; } int main() { struct punct O,A,B; printf("A:"); citire(&A); printf("B:"); citire(&B); printf("O:"); citire(&O); float r,r1; printf("R="); scanf("%f",&r); r1=d(O,A,B); if (r1>r) printf("\n Dreapta exterioara cercului"); if (r1==r) printf("\n Dreapta tangenta cercului"); if (r1<r) printf("\n Dreapta secanta cercului"); getchar(); getchar(); return 0; }

/*Se citesc coordonatele vrfurilor unui triunghi n plan.Sa se scrie un program care stabileste pozitia fata de triunghi a unui punct oarecare din plan dat prin coordonatele lui.*/ #include <stdio.h> #include <stdlib.h> #include <math.h> struct punct {float x,y; }; float aria(struct punct a,struct punct b,struct punct c) { float d; d=a.x*b.y+b.x*c.y+a.y*c.x-b.y*c.x-a.x*c.y-a.y*b.x; d=abs(d)/(float)2; return d; } void citire(struct punct *a) {printf("\nx="); scanf("%f",&a->x); printf("y="); scanf("%f",&a->y); } int main() { struct punct A,B,C,P; printf("A:"); citire(&A); printf("B:"); citire(&B); printf("C:"); citire(&C); printf("P:"); citire(&P); if (aria(A,B,C)==aria(A,B,P)+aria(A,C,P)+aria(B,C,P)) printf("\n Punctul P este in interiorul triunghiului ABC"); else printf("\n Punctul P nu este in interiorul triunghiului ABC"); //printf("ABC %f \n ABP %f \n ACP %f \n BCP %f",aria(A,B,C),aria(A,B,P),aria(A,C,P),aria(B,C,P)); getchar(); getchar(); return 0; } /*Scrieti un program care calculeaza greutatea ideala a unei persoane, utiliznd formulele: G_barbat=50 + 0.75*(naltime-150) + (vrsta-20)/4; G_femeie=G_barbat - 10; Se citesc: sexul, naltimea(n cm), vrsta (n ani).*/ #include <stdio.h> #include <stdlib.h> int main() { int h,v; char s; printf("sex: (M/F)"); s=getchar();

printf("inaltime:"); scanf("%d",&h); printf("varsta:"); scanf("%d",&v); float g=0; switch(s) {case 'M':case 'm':g=50+0.75*(h-150)+(float)(v-20)/4;break; case 'F':case 'f':g=50+0.75*(h-150)+(float)(v-20)/4-10;break; } printf("\n\tGreutate ideala: %5.2f kg",g); getchar(); getchar(); return 0;

/*Scrieti un program care transforma coordonatele carteziene ale unui punct din plan n coordonate polare.*/ #include <stdio.h> #include <stdlib.h> #include <math.h> int main() { float r,t,x,y; printf("x="); scanf("%f",&x); printf("y="); scanf("%f",&y); r=sqrt(pow(x,2)+pow(y,2)); if(x>0 && y>=0) t=atan(y/x); if(x>0 && y<0) t=atan(y/x)+2*M_PI; if(x<0) t=atan(y/x)+M_PI; if(x==0 && y>0) t=M_PI/2; if(x==0 && y<0) t=3*M_PI/2; if (r!=0) printf("\nA(%4.2f,%4.2f) -> A(%4.2f,%4.2fpi)",x,y,r,t/M_PI); else printf("\nA(%4.2f,%4.2f) -> A(%4.2f,t) ,t apartine R",x,y,r); getchar(); getchar(); return 0; } /*2. De la tastatur se citesc 4 perechi de numere reale, care reprezint n coordonate rectangulare vrfurile unui patrulater. S se stabileasc natura acestui patrulater. */ # include <stdio.h> # include <stdlib.h> # include <math.h> struct punct { float x,y; }; //b==1 => camp x //b==0 => camp y //a==1 => max //a==0 -> min

float minmax(struct punct v[4],int a,int b) {float m; if(b) m=v[0].x; else m=v[0].y; int i; for (i=1;i<=3;i++) if(a){if(b){if(v[i].x>m) m=v[i].x;}else{if(v[i].y>m) m=v[i].y;}} else {if(b){if(v[i].x<m) m=v[i].x;}else {if(v[i].y<m) m=v[i].y;}} return m; } float det(struct punct a,struct punct b,struct punct c) {float m; m= (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); return m; } int paralel(struct punct a,struct punct b) {if(a.x*b.y==a.y*b.x) return 1; return 0; } int perpend(struct punct a,struct punct b) {if(a.x*b.x+a.y*b.y==0) return 1; return 0; } int egal(struct punct a,struct punct b) {if (sqrt(pow(a.x,2)+pow(a.y,2))==sqrt(pow(b.x,2)+pow(b.y,2)))return 1; return 0; } int main() {int i,j,a=0,b=0; struct punct v[4],aux,d[4]; for (i=0;i<4;i++) {printf("\nv[%d].X=",i+1); scanf("%f",&v[i].x); printf("v[%d].Y=",i+1); scanf("%f",&v[i].y); } for (i=0;i<3;i++) {if(i==1) a++; if(i==2) b++; for (j=0;j<4;j++) if((v[j].x==minmax(v,a,1))&&(v[j].y==minmax(v,b,0))) {aux=v[i];v[i]=v[j];v[j]=aux;} } if(det(v[0],v[1],v[2])<0||det(v[1],v[2],v[3])<0||det(v[2],v[3],v[1])<0) printf("\n patrulaterul este concav\n"); else { d[0].x=v[1].x-v[0].x;d[0].y=v[1].y-v[0].y; d[1].x=v[2].x-v[1].x;d[1].y=v[2].y-v[1].y; d[2].x=v[2].x-v[3].x;d[2].y=v[2].y-v[3].y; d[3].x=v[3].x-v[0].x;d[3].y=v[3].y-v[0].y; if (paralel(d[0],d[2])&&paralel(d[1],d[3])) {if(!perpend(d[0],d[1])) {if(egal(d[0],d[1])) printf("\n romb\n");

} else if((paralel(d[0],d[2])&&!paralel(d[1],d[3]))||(!paralel(d[0],d[2])&&paralel(d[1],d[3]))) printf("\ntrapez\n"); else printf("\n patrulater convex oarecare"); } getchar(); return 0; } /*De pe mediul de intrare sunt citite elementele reale ale unui sir de dimensiunea n. Sa se gaseasca pozitia elementelor de valoare minima si valoare maxima din sir.*/ #include <stdio.h> #include <stdlib.h> int main() { int n; float *v,max,min; register int i; printf("n="); scanf("%d",&n); v=calloc(n,sizeof(float)); if(v==NULL) exit(1); for (i=0;i<n;i++) {printf("v[%d]=",i+1); scanf("%f",v+i); if(i==0) max=min=v[0]; else {if (v[i]<min) min=v[i]; if(v[i]>max) max=v[i]; } } printf("\n Pozitiile elementleor minime: "); for (i=0;i<n;i++) if(v[i]==min) printf("%d ",i+1); printf("\n Pozitiile elementleor maxime: "); for (i=0;i<n;i++) if(v[i]==max) printf("%d ",i+1); getchar(); getchar(); return 0; } /*4. S se scrie un program pentru generarea tuturor numerelor prime mai mici sau egale cu un numr natural n. */ #include <stdio.h> #include <stdlib.h> #include <math.h>

else printf("\n paralelogram\n"); } else {if (egal(d[0],d[1]))printf("\n patrat\n"); else printf("\n dreptunghi\n"); }

int prim(int a) {if(a==0||a==1)return 0; register int i; for (i=2;i<=sqrt(a);i++) if(a%i==0) return 0; return 1; } int main() { int n; //printf("\033[2J"); printf("n="); scanf("%d",&n); register int i; for (i=2;i<=n;i++) if(prim(i)) printf("%d ",i); getchar(); return 0; } /* Se citete un numr natural n. S se gseasc cel mai mare ptrat perfect mai mic sau egal cu n. Aceeai problem, dar s se indice numrul prim cel mai mic, dar mai mare sau egal cu numrul citit. */ #include <stdio.h> #include <stdlib.h> #include <math.h> int prim(int a) {if(a==0||a==1)return 0; register int i; for (i=2;i<=sqrt(a);i++) if(a%i==0) return 0; return 1; } int main() {int n; printf("n="); scanf("%d",&n); int i; for (i=n;i>0;i--) if(sqrt(i)==(int)sqrt(i)) {printf("patrat perfect: %d\n",i);break;} for (i=n;i>0;i--) if(prim(2*n-i)){printf("numar prim: %d\n",2*n-i);break; } getchar(); getchar(); return 0; }

/*6. De pe mediul de intrare se citete un numr natural n. S se verifice dac numrul respectiv este palindrom. */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int s,inv=0,ch; printf("n="); scanf("%d",&s); ch=s; while(ch) {inv=inv*10+ch%10;ch/=10;} inv==s?printf("%d este palindrom\n",s):printf("%d nu este palindrom\n",s); getchar(); getchar(); return 0; } /* De pe mediul de intrare se citesc cifrele hexazecimale ale unui numr ntreg n baza 16. Sa se calculeze i s se afieze reprezentarea numrului n baza 10.*/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int main() {char s[50]; printf("n="); gets(s); strrev(s); int i,n=0; for (i=0;i<strlen(s);i++) switch(s[i]) {case 'A' : {n+=pow(16,i)*10;break;} case 'B' : {n+=pow(16,i)*11;break;} case 'C' : {n+=pow(16,i)*12;break;} case 'D' : {n+=pow(16,i)*13;break;} case 'E' : {n+=pow(16,i)*14;break;} case 'F' : {n+=pow(16,i)*15;break;} default : {n+=pow(16,i)*(s[i]-'0');} } printf("%s in hex is %d in dec\n ",strrev(s),n); getchar(); getchar(); return 0; } /*Se citete gradul i coeficienii polinomului p(x)=a0 +a1x1+......+ anxn S se calculeze valoarea polinomului n x= x0 (x0 se citete). */ #include <stdio.h> #include <stdlib.h>

#include <math.h> int main() {int n,v[100],x,i; printf("n="); scanf("%d",&n); printf("x="); scanf("%d",&x); unsigned long int u=0; for (i=0;i<n;i++) {printf("a%d=",i);scanf("%d",&v[i]);u+=v[i]*pow(x,i);} printf("valoare %ld",u); getchar(); getchar(); return 0; } /*Sa se scrie un program pentru efectuarea operatiilor de adunare, scadere, nmultire si mpartire ntre doua polinoame: A(x)=a0 +a1x1+......+ anxn B(x)=b0 +b1x1+......+ bmxm Gradele si coeficientii reali ai polinoamelor se citesc de pe mediul de intrare. */ #include <stdio.h> #include <stdlib.h> void citire(float *a,int n) {int i;printf("\n"); for(i=0;i<=n;i++) {printf("coef x^%d:",i); scanf("%f",&a[i]); } } void afisare(float *a,int n) {int i; for (i=0;i<=n;i++) if (a[i]!=0) i==n?printf("%+4.2f*x^%d",a[i],i):printf("%+4.2f*x^%d",a[i],i); } void reset(float *p,int n) {int i; for(i=0;i<=n;i++) p[i]=0; } void inmultire(float *a,int n,float *b,int m,float *c) {int i,j; for (i=0;i<=n;i++) for (j=0;j<=m;j++) c[i+j]+=a[i]*b[j]; } void adunare(float *a,int n,float *b,int m,float *c) {int p=n<m?n:m,i; for (i=0;i<=p;i++)

c[i]=a[i]+b[i]; if(p==n) for (i=n+1;i<=m;i++) c[i]=b[i]; if(p==m) for (i=m+1;i<=n;i++) c[i]=a[i]; } void scadere(float *a,int n,float *b,int m,float *c) {int p=n<m?n:m,i; for (i=0;i<=p;i++) c[i]=a[i]-b[i]; if(p==n) for (i=n+1;i<=m;i++) c[i]=(-1)*b[i]; if(p==m) for (i=m+1;i<=n;i++) c[i]=a[i]; } int grad(float *a,int n) {int m=-1,i; for (i=0;i<=n;i++) if(a[i]) m=i; return m; } void impartire(float *a,int n,float *b,int m,float *c,float *r) {int i; float *p,*p1; p=calloc(n,sizeof(float)); p1=calloc(n,sizeof(float)); if(p==NULL) exit(1); if(p1==NULL) exit(1); c[n-m]=a[n]/b[m]; reset(p1,n); inmultire(c,n-m,b,m,p1); scadere(a,n,p1,n,p); n=grad(p,n); while(grad(p,n)>=grad(b,m)) {c[n-m]=p[n]/b[m]; reset(p1,n); inmultire(c,n-m,b,m,p1); scadere(p,n,p1,n,p); n=grad(p,n); } for (i=0;i<=n+1;i++) r[i]=p[i]; } int main() { float *a,*b,*c,*r; int n,m,p,q; printf("n="); scanf("%d",&n); printf("m="); scanf("%d",&m); a=calloc(n,sizeof(float)); if(a==NULL) exit(1);

b=calloc(m,sizeof(float)); if(b==NULL) exit(1); citire(a,n); citire(b,m); p=n>m?n:m; c=calloc(p,sizeof(float)); printf("\nf="); afisare(a,n); printf("\ng="); afisare(b,m); adunare(a,n,b,m,c); printf("\n\nf+g="); afisare(c,p); scadere(a,n,b,m,c); printf("\nf-g="); afisare(c,p); scadere(b,m,a,n,c); printf("\ng-f="); afisare(c,p); c=calloc(n+m,sizeof(float)); inmultire(a,n,b,m,c); printf("\nf*g="); afisare(c,n+m); q=n>m?n-m-1:m-n-1; r=calloc(q,sizeof(float)); if(r==NULL) exit(1); c=calloc(q+1,sizeof(float)); if(c==NULL) exit(1); n>m?impartire(a,n,b,m,c,r):impartire(b,m,a,n,c,r); n>m?printf("\nf/g="):printf("\ng/f="); afisare(c,q+1); if (grad(r,q)!=-1) { printf("\n\tr="); afisare(r,q); } getchar(); getchar(); return 0; } //Problema asta merge dar partial, nu am folosit functii de free() pentru ca codeblocksul dadea ceva erori la alocare //de memorie.... /*O matrice patrata cu elemente reale este mpartita de diagonalele sale n patru zone. Se considera ca elementele situate pe diagonale nu apartin nici unei zone. Sa se scrie un program care calculeaza media aritmetica a elementelor fiecarei zone.*/ #include <stdio.h> #include <stdlib.h> void citire(float **a,int n) {int i,j; for(i=0;i<n;i++) {printf("\n"); for(j=0;j<n;j++) {printf("a[%d][%d]=",i+1,j+1); scanf("%f",&a[i][j]); } }

} void ma(float **a,int n) { float maN=0,maS=0,maE=0,maV=0; int contN=0,contS=0,contE=0,contV=0,i,j; for (i=0;i<n;i++) for (j=0;j<n;j++) { if(i>j&&i+j<n-1) {maV+=a[i][j];contV++;} if(i>j&&i+j>n-1) {maS+=a[i][j];contS++;} if(i<j&&i+j>n-1) {maE+=a[i][j];contE++;} if(i<j&&i+j<n-1) {maN+=a[i][j];contN++;} } printf("\n MaN= %4.2f\nMaE= %4.2f\nMaS= %4.2f\nMaV= %4.2f\n",maN/contN,maE/contE,maS/contS,maV/contV); } int main() { int n,i; float **a; printf("n="); scanf("%d",&n); a=calloc(n,sizeof(float *)); if(a==NULL) exit(1); for (i=0;i<n;i++) {a[i]=calloc(n,sizeof(float)); if(a[i]==NULL) exit(1); } citire(a,n); ma(a,n); getchar(); getchar(); return 0;

/* 13. Se d un ir de n elemente reale ordonate cresctor. S se verifice dac o valoare citit x se gsete n ir i s se indice poziia sa */ #include <stdio.h> #include <stdlib.h> int v[100],n,x; void cautare(int i,int j) {int m=(i+j)/2; (v[m]==x)?printf("\n element gasit pe pozitia %d\n",m+1):(i<j)?(x<v[m])?cautare(i,m1):cautare(m+1,j):printf("\nelementul nu s-a gasit\n"); } int ordonat(int v[100],int n) {int i; for (i=0;i<n-1;i++) if(v[i+1]<=v[i]) return 0; return 1; }

int main() {int i; citire:{printf("\nn="); scanf("%d",&n); for (i=0;i<n;i++) {printf("\nv[%d]= ",i+1);scanf("%d",&v[i]);} } if (!ordonat(v,n)) {printf("\n sir neordonat\n ");//printf("\033[2J"); goto citire; } printf("\nx="); scanf("%d",&x); cautare(0,n-1); getchar(); getchar(); return 0; } //Se da un sir de n numere ntregi. Sa se extraga subsirul ordonat crescator de dimensiune maxima. #include <stdio.h> #include <stdlib.h> int *secventa(int *p) {int *q; q=p; while (q&&*(q+1)>*q) q++; return q; } void afisare(int *k,int l) {printf("\n"); int i; for(i=0;i<l;i++) printf("%d ",k[i]); } int main() { int a[50],p[50],q[50],r[50],n,max=0,i; printf("n="); scanf("%d",&n); for (i=0;i<n;i++) {printf("a[%d]=",i+1); scanf("%d",&a[i]); } r=a; p=a; max=1; do {q=secventa(p); if(max<=q+1-p) {max=q+1-p;r=p;} p=q+1; }while (p-a<n-1&&q-a<n-1); afisare(r,max); getchar();

getchar(); return 0;

/* 15. Pentru elaborarea unui test de aptitudini se dispune de un set de n ntrebri, fiecare ntrebare i fiind cotat cu un numr de pi puncte. S se elaboreze toate chestionarele avnd q ntrebri, fiecare chestionar totaliznd ntre a i b puncte. ntrebrile sunt date prin numr i punctaj. */ #include <stdio.h> #include <stdlib.h> int x[100],p[100],a,b,n,q; int solutie (int k) {int i,cont=0; if (k!=q) return 0; for (i=1;i<=k;i++) cont+=p[x[i]-1]; if(cont>a&& cont<b) return 1; return 0; } void afisare (int k) {int i; printf("\n\nChestionar:"); for (i=1;i<=k;i++) printf("\nintrebarea %d cu %d puncte",x[i],p[x[i]-1]); } int valid(int k) {register int i,j; for (i=1;i<k;i++) for (j=i+1;j<=k;j++) {if(x[i]==x[j]) return 0;if(x[i]>x[j]) return 0;} return 1; } void back(int k) {int i; for (i=1;i<=n;i++) {x[k]=i; if(valid(k)) if(solutie(k)) afisare(k); else if(k<q)back(k+1); } }

int main() { int i; printf("n="); scanf("%d",&n); for(i=0;i<n;i++)

{printf("\n p[%d]=",i+1); scanf("%d",&p[i]); } printf("\nnumar de intrebari:"); scanf("%d",&q); printf("\nval minima acceptata pentru punctaj:"); scanf("%d",&a); printf("\n val maxima acceptata pentru punctaj:"); scanf("%d",&b); back(1); getchar(); return 0;

/* 16. Se dau 2 iruri de n si respectiv m elemente de tip ntreg. S se calculeze: a) irul ce conine elementele comune ale celor dou iruri; b) irul ce conine toate elementele celor dou iruri luate o singura dat; c) irul ce conine elementele primului ir din care au fost eliminate elementele comune. */ #include <stdio.h> #include <stdlib.h> int a[100],b[100],c[100],d[200],e[100]; void afisare(int a[100],int n) {printf("\n"); int i,ok=0; for (i=0;i<n;i++) {printf("%d ",a[i]);if(a[i]) ok=1;} if(!ok) printf("multime vida"); } void intersectie(int a[100],int n,int b[100],int m,int c[100],int *p) {register int i,j; //printf("%d",p); for (i=0;i<n;i++) for (j=0;j<m;j++) if(a[i]==b[j]) {c[*p]=a[i];(*p)++;} } int gasit(int a,int b[100],int n) {register int i; for (i=0;i<n;i++) if(b[i]==a) return 1; return 0; } void reuniune(int a[100],int n,int b[100],int m,int c[200],int *p) {register int i; for (i=0;i<n;i++) if(!gasit(a[i],c,*p)) {c[*p]=a[i];(*p)++;} for (i=0;i<m;i++) if(!gasit(b[i],c,*p)) {c[*p]=b[i];(*p)++;}

} void diferenta(int a[100],int n,int b[100],int m,int c[100],int *p) {int i; for (i=0;i<n;i++) if(!gasit(a[i],b,m)) {c[*p]=a[i];(*p)++;} } int main() { int i,n,m,p=0,q=0,r=0; printf("n="); scanf("%d",&n); printf("m="); scanf("%d",&m); printf("\n"); for (i=0;i<n;i++) {printf("a[%d]= ",i+1);scanf("%d",&a[i]);} printf("\n"); for (i=0;i<m;i++) {printf("b[%d]= ",i+1);scanf("%d",&b[i]);} intersectie(a,n,b,m,c,&p); reuniune(a,n,b,m,d,&q); diferenta(a,n,c,p,e,&r); printf("\n\n Intersectie:"); afisare(c,p); printf("\n Reuniune:"); afisare(d,q); printf("\n\n Diferenta:"); afisare(e,r); getchar(); getchar(); return 0;

/* 18. Se d un numr natural n. a) S se gseasc numrul obinut prin eliminarea cifrelor care apar de mai multe ori n numr. b)S se gseasc numrul obinut prin interschimbarea ntre ele a primei cifre cu ultima , a celei de a doua cu penultima .a.m.d. c)S se gseasc cel mai mare numr ce se poate obine din cifrele sale. */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main() {char s[11],p[11],*pt; unsigned int a[10],b[10]={0},n,m; printf("n="); gets(s); int i,j; i=strlen(s);

n=m=i; while (i>=0) {a[i]=s[i]-'0';i--;} strcpy(p,s); for (i=0;i<n-1;i++) for (j=i+1;j<n;j++) if(a[i]==a[j]) b[a[i]]=1; i=0; while(i<m) { if(b[p[i]-'0']) {pt=p;strcpy(pt+i,pt+i+1);m--;} else i++; } puts(pt); printf("\n%s\n",strrev(s)); for (i=0;i<n-1;i++) for (j=i+1;j<n;j++) if(s[i]<s[j]) {char c;c=s[i],s[i]=s[j];s[j]=c;} printf("\n%s\n",s); getchar(); getchar(); return 0; } //Se da o matrice de nxn elemente 0 si 1. Sa se stabileasca daca matricea respectiva este simetrica #include <stdio.h> #include <stdlib.h> int simetric(int a[50][50],int n) {int i,j; for (i=0;i<n;i++) for(j=0;j<n;j++) if(a[i][j]!=a[j][i]) return 0; return 1; } int main() { int n,a[50][50],i,j; printf("n="); scanf("%d",&n); for (i=0;i<n;i++) for(j=0;j<n;j++) {printf("a[%d][%d]=",i+1,j+1); scanf("%d",&a[i][j]); } simetric(a,n)==1?printf("\nMatrice simetrica "):printf("\nMatricea nu e simetrica"); getchar(); getchar(); return 0; }

/* 20. De pe mediul de intrare se citete o propoziie. S se indice numrul cuvintelor i cuvntul cel mai lung din propoziie. */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main() {char s[255],q[]=" ,.?!",*p,r[200]; printf("propozitie:"); gets(s); int i=0,j=0; p=strtok(s,q); while (p!=NULL) {i++; //printf("%s\n",p); if(strlen(p)>j) {j=strlen(p);strcpy(r,p);} p=strtok(NULL,q); } printf("\n Exista %d cuvinte.\n Cuvantul de lungime maxima este \"%s\"",i,r); getchar(); getchar(); return 0; } /*Se spune ca un numar natural este frumos daca are ca factori primi doar pe 2,3 si 5. Sirul numerelor frumoase este: 1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,30,... Sa se scrie un program care afiseaza pe ecran primele n numere frumoase, cte 10 pe o linie (1<=n<=1000).*/ #include <stdio.h> #include <stdlib.h> #include <math.h> int frumos(int a) { register int k; if(a==1||a==0) return 0; if(a%2!=0&&a%3!=0&&a%5!=0) return 0; for (k=6;k<=a;k++) if(k%2!=0&&k%3!=0&&k%5!=0) if(a%k==0) return 0; } int main() { int n,i,cont=0; printf("n="); scanf("%d",&n); for (i=2;i<=n;i++) {if(frumos(i)) if(cont<10) {printf("%d ",i);cont++;} else {printf("\n%d ",i);cont=0;} } getchar(); getchar(); return 0; } return 1;

/*Se citeste de la tastatura ora, minutul si secunda indicate de un ceas. Sa se calculeze unghiul masurat n sens trigonometric ntre indicatorul orar si minutar.*/ #include <stdio.h> #include <stdlib.h> #include <math.h> int main() { char ch[20]=""; int H,M,S,g,m,s; double h,m1,x; printf("ora: (HH:MM::SS) "); gets(ch); sscanf(ch,"%d:%d:%d",&H,&M,&S); if(H>11) H-=12; h=M_PI/6*(H+(double)M/60); m1=M_PI/30*(M+(double)S/60); x=h-m1; if(x<0) x=2*M_PI-x; x*=180/M_PI; g=(int)x; x-=g; x*=60; m=(int)x; x-=m; x*=60; s=x; printf("\n Unghi de %d grade, %d minute si %d secunde",g,m,s); getchar(); getchar(); return 0; #error Erori la impartire reala Problema neterminata integral } /*De pe mediul de intrare se citeste gradul unui polinom si coeficientii sai, care sunt numere ntregi. n P x p p x + pn x ( ) = + 1 + ... 01 n care p0 este nenul. Stiind ca polinomul admite numai radacini ntregi simple, sa se gaseasca radacinile polinomului.*/ #include <stdio.h> #include <stdlib.h> #include <math.h> int divizori(int a,int *p) {int nr=0,k; for(k=1;k<=abs(a);k++) if(a%k==0) {p[nr]=k;p[++nr]=(-1)*k;nr++;} return nr; } int radacina(int a,int *p,int *n)

{ int *b,i,s,nr=0; b=calloc(*n-1,sizeof(int)); if(b==NULL) {fprintf(stderr,"\nEroare la alocarea de memorie ");exit(1);} rad: {if (*n==0) return nr; b[*n-1]=p[*n]; for (i=*n-1;i>0;i--) b[i-1]=a*b[i]+p[i]; s=b[0]*a+p[0]; if (s!=0&&nr==0) return 0; if(s!=0&&nr!=0) return nr; nr++; for (i=0;i<*n;i++) p[i]=b[i]; p[*n]=0; *n=*n-1; } goto rad; } int main() { int n,*p,i,m,r,q[20]={0},ok=1; printf("n="); scanf("%d",&n); p=calloc(n,sizeof(int)); if(p==NULL) {fprintf(stderr,"\nEroare la alocarea de memorie ");exit(1);} for (i=0;i<=n;i++) {printf("p^%d= ",i); scanf("%d",p+i); } m=divizori(p[0],q); for (i=0;i<m;i++) if((r=radacina(q[i],p,&n))>0) {printf("\n %d este radacina de ordin %d",q[i],r);ok=0;} if(ok) printf("\n\n Polinomul nu are radacini intregi "); getchar(); getchar(); return 0; } /*Se dau dou iruri de caractere care reprezint numere ntregi zecimale foarte mari. S se scrie un program de efectuare a operaiilor aritmetice asupra lor */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int v3[100]={0},v1[100]={0},v2[100]={0}; void afisare( int v[100],int n) {int i; for(i=n-1;i>=0;i--) printf("%d",v[i]); }

void adunare(int a[100],int n,int b[100],int m) {int s=0,ok,i; //n>m?ok=n:ok=m; if(n>m) ok=n; else ok=m; for (i=0;i<ok;i++) {v3[i]=s; s=a[i]+b[i]; int b=v3[i]+s; if(b>=10) {v3[i]=b%10;s=b/10;} else {v3[i]+=s%10;s/=10;} } if(s>0) {v3[ok]=s;ok++;} afisare(v3,ok); } void scadere(int a[100],int n,int b[100],int m) {int s=0,i,a1[100]={0}; if(n>=m) {for (i=0;i<n;i++) a1[i]=a[i]; for (i=0;i<n;i++) { if (a1[i]<0) {a1[i+1]--;a1[i]+=10;} scadere:{s=a1[i]-b[i];}; if(s<0) {a1[i+1]--; a1[i]+=10;goto scadere;a1[i]-=10;} v3[i]=s; } if(a1[n]<0) {printf("-");scadere(b,m,a,n);} else afisare(v3,n); } else {printf("-");scadere(b,m,a,n);}

} int main() {char s[100]; int n,m,i; citire: {printf("a="); gets(s); for (i=strlen(s)-1;i>=0;i--) {if(!isdigit(s[i])) {printf("\nValoare eronata a numarului !!!\nIntroduceti numere naturale\n"); goto citire;} v1[strlen(s)-i-1]=s[i]-'0'; } n=strlen(s); printf("b="); gets(s); for (i=strlen(s)-1;i>=0;i--) {if(!isdigit(s[i])) {printf("\nValoare eronata a numarului !!!\nIntroduceti numere naturale\n"); goto citire;} v2[strlen(s)-i-1]=s[i]-'0';

} m=strlen(s); printf("\na+b="); adunare(v1,n,v2,m); printf("\na-b="); scadere(v1,n,v2,m); getchar(); return 0;

/*S se scrie funciile pentru adunarea, scderea i nmulirea a dou matrice i apoi s se realizeze calculul A=B*C 2*(B+C), unde B i C sunt dou matrice ptratice de ordinul n */ # include <stdio.h> # include <stdlib.h> //C++ int n; class matrice {public: int **p; int n; int m; matrice(int i,int j) {p= new int*[i]; if(p==NULL) exit(1); for (int k=0;k<i;k++) p[k]=new int[j];

matrice() {p= new int*[50]; if(p==NULL) exit(1); for (int k=0;k<50;k++) p[k]=new int[50]; n=m=50;

void init(int a,int b) {n=a;m=b;} void citire() {printf("\n"); for(int i=0;i<n;i++) for(int j=0;j<n;j++) {printf("a[%d][%d]=",i+1,j+1); scanf("%d",&p[i][j]); } } void afisare() {printf("\n"); for(int i=0;i<n;i++)

{printf("\n"); for(int j=0;j<n;j++) printf("%d ",p[i][j]); } ~matrice() {for (int i=0;i<n;i++) delete [] p[i]; delete [] p; }

matrice operator +(matrice b) {matrice c(10,10); c.init(::n,::n); for (int i=0;i<n;i++) for(int j=0;j<n;j++) c.p[i][j]=p[i][j]+b.p[i][j]; } return c;

void operator =(matrice b) { for (int i=0;i<n;i++) for(int j=0;j<n;j++) p[i][j]=b.p[i][j]; } matrice operator -(matrice b) {matrice c(10,10); c.init(::n,::n); for (int i=0;i<n;i++) for(int j=0;j<n;j++) c.p[i][j]=p[i][j]-b.p[i][j]; } return c;

matrice operator *(matrice b) {matrice c(10,10); c.init(::n,::n); int i=0,j,s,k=0; while (i<n) {s=0; for (j=0;j<n;j++) s+=p[i][j]*b.p[j][k]; c.p[i][k]=s; if(k==n-1) {i++;k=0;} else k++; } return c; } matrice operator *(int a) {matrice c(10,10); c.init(::n,::n); int i,j;

for (i=0;i<n;i++) for (j=0;j<n;j++) c.p[i][j]=a*p[i][j]; return c; } }; int main() { printf("n="); scanf("%d",&n); matrice a(10,10); a.init(n,n); matrice b(10,10); b.init(n,n); a.citire(); b.citire(); matrice c(10,10); c.init(n,n); c=a*b-(a+b)*2; c.afisare(); getchar(); return 0;

/*Fiind date anul, luna, ziua, sa se scrie o functie care sa returneze a ctea zi din an este ziua respectiva si cte zile au mai ramas din anul respectiv.*/ #include <stdio.h> #include <stdlib.h> int bisect(int a) { if ((a%4==0&&a%100!=0)||(a%400==0)) return 1; return 0; } int main() { int a,l,zile=0,z; citire: {printf("\nan: "); scanf("%d",&a); printf("luna: "); scanf("%d",&l); if(l<1||l>12) {printf("\n\n\t\tValoare eronata a lunii!!!");goto citire;} printf("zi:"); scanf("%d",&z); if(z<1||z>31) {printf("\n\n\t\tValoare eronata a zilei!!!");goto citire;} if(l==2) if(!bisect(a)&&z==29) {printf("\n\n\t\tAnul nu e bisect si ziua 29 nu exista!!!");goto citire;} }

if(l!=9&&l!=10) zile=(l-1)/2*30+(l-1-(l-1)/2)*31; else zile=((l-1)/2-1)*30+(l-2-(l-1)/2)*31; if(l>2) if(bisect(a)) zile-=1;else zile-=2; zile+=z; printf("\n\t Ziua este a %d -a din an\n\tAu mai ramas %d zile din an",zile,bisect(a)?366-zile:365-zile); getchar(); getchar(); return 0;

/*S se scrie o funcie care primind ca parametru un numr roman sub forma unui ir de caractere, returneaz numrul respectiv ca numr arab n baza 10. */ #include <stdio.h> #include <stdlib.h> #include <string.h> long int roman (char *s) {int i=0; int v[255]={0}; v[(int)'I']=v[(int)'i']=1; v[(int)'V']=v[(int)'v']=5; v[(int)'X']=v[(int)'x']=10; v[(int)'L']=v[(int)'l']=50; v[(int)'C']=v[(int)'c']=100; v[(int)'D']=v[(int)'d']=500; v[(int)'M']=v[(int)'m']=1000; long int suma=0; while (i<strlen(s)) { if(v[(int)s[i+1]]>v[(int)s[i]]) suma+=-v[(int)s[i]]; else suma+=v[(int)s[i]]; i++; } return suma; } int main() {char s[255],*p; p=s; printf("s:"); gets(s); printf(" %ld\n",roman(p)); getchar(); return 0; } /*S se scrie o funcie care primind ca parametru un numr arab n baza 10, calculeaz irul de caractere ce reprezint numrul respectiv sub form roman. */ #include <stdio.h> #include <stdlib.h> #include <string.h>

int main() {int v[5]={0},n,c10[5]={0},c5[4]={0}; c10[0]=(int)'I'; c10[1]=(int)'X'; c10[2]=(int)'C'; c10[3]=(int)'M'; c5[0]=(int)'V'; c5[1]=(int)'L'; c5[2]=(int)'D'; char s[100]="",lch[5]=""; printf("an:"); scanf("%d",&n); int i=0; while (n) {v[i]=n%10;n/=10;i++;} n=i; for (i=n-1;i>=0;i--) switch (v[i]) {case 1: lch[0]=(char)c10[i];lch[1]=NULL;strcat(s,lch);break; case 2:case 3:{int j;for (j=0;j<v[i];j++) lch[j]=(char)c10[i];lch[v[i]]=NULL; strcat(s,lch);break;} case 4: lch[0]=(char)c10[i];lch[1]=(char)c5[i];lch[2]=NULL;strcat(s,lch);break; case 5: lch[0]=(char)c5[i];lch[1]=NULL;strcat(s,lch);break; case 6:case 7:case 8: lch[0]=(char)c5[i]; int j; for (j=1;j<=v[i]-5;j++) lch[j]=(char)c10[i];lch[v[i]4]=NULL;strcat(s,lch);break; case 9: lch[0]=(char)c10[i];lch[1]=(char)c10[i+1];lch[2]=NULL;strcat(s,lch);break; } printf("an: %s",s); getchar(); getchar(); return 0; } /*Dndu-se forma postfixata a unei expresii aritmetice care contine numai numere ntregi si operatori +,-,*,/, sa se scrie un program pentru evaluarea sa.*/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> struct nod {int val; struct nod *urm; }; int main() { struct nod *vf; char s[100],*p,ch[]=", "; int i,n=0,m=0; citire: { printf("\nIntroduceti expresia, valori separate prin virgula (2,3,+): \nE="); gets(s); if(strlen(s)==0) {printf("\n\t Valoare eronata a expresiei");goto citire;} for (i=0;i<strlen(s);i++)

{if (!isdigit(s[i])&&s[i]!=','&&s[i]!='+'&&s[i]!='-'&&s[i]!='/'&&s[i]!='*') {printf("\n\t Valoare eronata a expresiei");goto citire;}} } p=strtok(s,ch); while (p) {if(isdigit(p[0])) { if(vf==NULL) {vf=malloc(sizeof(struct nod)); if(vf==NULL) {fprintf(stderr,"\n Eroare la alocare de memorie");exit(1);} vf->urm=NULL; vf->val=atoi(p); } else { struct nod *q; q=malloc(sizeof(struct nod)); if(q==NULL) {fprintf(stderr,"\n Eroare la alocare de memorie");exit(1);} q->urm=vf; q->val=atoi(p); vf=q; } n++; } else {m++; if (m>=n) {free(vf);printf("\n\tExpresie scrisa incorect");n=0;m=0;goto citire;} switch(p[0]) {case '+' : vf->urm->val=vf->val+vf->urm->val;break; case '-' : vf->urm->val=vf->urm->val-vf->val;break; case '*' : vf->urm->val=vf->val*vf->urm->val;break; case '/' : vf->urm->val=vf->urm->val/vf->val;break; } struct nod *q;q=vf;vf=vf->urm;free(q); } p=strtok(NULL,ch); } printf("\nE= %d",vf->val); getchar(); getchar(); return 0; } //Sa se scrie un program pentru calculul c.m.m.d.c. si c.m.m.m.c a doua polinoame //beta version...erori de alocare de memorie..deci nu stiu ce afiseaza #include <stdio.h> #include <stdlib.h> void citire(float *a,int n) {int i;printf("\n"); for(i=0;i<=n;i++) {printf("coef x^%d:",i); scanf("%f",&a[i]); } } void afisare(float *a,int n) {int i; for (i=0;i<=n;i++) if (a[i]!=0) i==n?printf("%+4.2f*x^%d",a[i],i):printf("%+4.2f*x^%d",a[i],i); }

void reset(float *p,int n) {int i; for(i=0;i<=n;i++) p[i]=0; } void inmultire(float *a,int n,float *b,int m,float *c) {int i,j; for (i=0;i<=n;i++) for (j=0;j<=m;j++) c[i+j]+=a[i]*b[j]; } void adunare(float *a,int n,float *b,int m,float *c) {int p=n<m?n:m,i; for (i=0;i<=p;i++) c[i]=a[i]+b[i]; if(p==n) for (i=n+1;i<=m;i++) c[i]=b[i]; if(p==m) for (i=m+1;i<=n;i++) c[i]=a[i]; } void scadere(float *a,int n,float *b,int m,float *c) {int p=n<m?n:m,i; for (i=0;i<=p;i++) c[i]=a[i]-b[i]; if(p==n) for (i=n+1;i<=m;i++) c[i]=(-1)*b[i]; if(p==m) for (i=m+1;i<=n;i++) c[i]=a[i]; } int grad(float *a,int n) {int m=-1,i; for (i=0;i<=n;i++) if(a[i]>0) m=i; return m; } void impartire(float *a,int n,float *b,int m,float *c,float *r) {int i; float *p,*p1; p=calloc(n,sizeof(float)); p1=calloc(n,sizeof(float)); if(p==NULL) exit(1); if(p1==NULL) exit(1); c[n-m]=a[n]/b[m]; reset(p1,n); inmultire(c,n-m,b,m,p1); scadere(a,n,p1,n,p); n=grad(p,n); while(grad(p,n)>=grad(b,m)) {c[n-m]=p[n]/b[m]; reset(p1,n); inmultire(c,n-m,b,m,p1);

scadere(p,n,p1,n,p); n=grad(p,n); } for (i=0;i<=n+1;i++) r[i]=p[i];

int main() { float *a,*b,*c,*r,*d,*e; int n,m,p; printf("n="); scanf("%d",&n); printf("m="); scanf("%d",&m); a=calloc(n,sizeof(float)); if(a==NULL) exit(1); b=calloc(m,sizeof(float)); if(b==NULL) exit(1); citire(a,n); citire(b,m); p=n<m?n:m; c=calloc(p,sizeof(float)); if(c==NULL) exit(1); r=calloc(50,sizeof(float)); if(r==NULL) exit(1); impartire(a,n,b,m,r,c); if(grad(c,p)==-1) {printf("\n c.m.m.d.c= ");afisare(b,p);c=b;} else {printf("\n c.m.m.d.c= ");afisare(c,--p);} reset(r,p); inmultire(a,n,b,m,r); d=calloc(50,sizeof(float)); if(d==NULL) exit(1); e=calloc(p,sizeof(float)); if(e==NULL) exit(1); impartire(r,n+m,c,p,d,e); printf("\n c.m.m.m.c= "); afisare(d,n+m-p); getchar(); getchar(); return 0; } //S se implementeze noiunea de mulime i operaiile permise // asupra sa. #include <stdio.h> #include <stdlib.h> #include <string.h> #include "multime.c" int main() { multime a,b,c(NM);

c=a+b; printf("\nReuniune:"); c.afisare(); c=a*b; printf("\nIntersectie:"); c.afisare(); printf("\nDiferenta:"); c=a-b; c.afisare(); printf("\nDiferenta simetrica:"); c=(a-b)+(b-a); c.afisare(); getchar(); return 0;

Multime.c: #define NM 100 #include <stdio.h> #include <string.h> #include <stdlib.h> class multime { private: int *p,n; public: multime() {p=new int [NM]; if(p==NULL) exit(1); citire(); } multime(int a) {p=new int [NM]; if(p==NULL) exit(1); n=a; } int gasit(int a) {int i; for (i=0;i<n;i++) if(p[i]==a) return 1; return 0; } void citire() {char s[NM],x[]=",{}",*q; citire: {n=0; printf("\nMultime:"); gets(s); q=strtok(s,x); while (q) { if (gasit(atoi(q))) {printf("\n Valoarea introdusa nu respecta notiunea de multime !!!");goto citire;} else {p[n]=atoi(q);n++;} q=strtok(NULL,x);

} } } void setn(int a) {n=a;} void afisare() {printf("\n"); int i; if(n==0) printf("Multimea vida "); else for (i=0;i<n;i++) printf("%d ",p[i]); } multime operator *(multime b) // INTERSECTIE {multime c(NM); int i,j,k=0; for (i=0;i<n;i++) for (j=0;j<b.n;j++) if(p[i]==b.p[j]) {c.p[k]=p[i];k++;} c.setn(k); return c; } multime operator +(multime b) // REUNIUNE {multime c(NM); int i,j,k=0,ok; for (i=0;i<n;i++) {c.p[k]=p[i];k++;} for (i=0;i<b.n;i++) {ok=1; for (j=0;j<n;j++) if(b.p[i]==c.p[j]) ok=0; if(ok) {c.p[k]=b.p[i];k++;} } c.setn(k); return c;

multime operator -(multime b) {multime c(NM); int i,j,k=0,ok; for (i=0;i<n;i++) {ok=1; for (j=0;j<b.n;j++) if(p[i]==b.p[j]) ok=0; if(ok) {c.p[k]=p[i];k++;} } c.setn(k); return c; } };

//S se implementeze un editor de texte care s permit cteva operaii definite de Dvs. //(inserarea unui text, tergere, modificare etc. ..) #include <stdio.h> #include <stdlib.h> #include <string.h> #include "editor.c" int main() {char s[255]="",ch[100]=""; printf("Text:");gets(s); citire: {printf("\noperatie dorita (I/A/S/M/E): "); gets(ch); switch (ch[0]) {case 'I':case 'i': inserare(s);break; case 'A':case 'a': afisare(s);break; case 'S':case 's': stergere(s);break; case 'M':case 'm': modificare(s);break; } } if(ch[0]!='E'&&ch[0]!='e') goto citire; getchar(); return 0;

Editor.c: void inserare(char s[255]) { char a[255]; printf("\n Introduceti text:"); gets(a); strcat(s,a); } void afisare(char s[255]) {printf("\n %s\n",s); } void stergere(char *s) {char s1[100],s2[100],*p,*q; printf("\n Introduceti cuvantul de la care sa incepa stergerea:"); gets(s1); printf("Introduceti cuvantul pana la care sa se stearga:"); gets(s2); p=strstr(s,s1); q=strstr(p,s2); strcpy(p,q); } void modificare(char *s) {char ch[100],*p,*q,q1[100]; printf("Introduceti textul ce va fii modificat:"); gets(ch); p=strstr(s,ch);

q=p+strlen(ch); printf("introduceti noul text:"); gets(ch); strcpy(q1,q); strcpy(p,ch); p=p+strlen(ch); strcpy(p,q1); } /*Folosind numai pointeri si expresii cu pointeri, se vor scrie functii de citire, afisare si nmultire a doua matrice.*/ #include <stdio.h> #include <stdlib.h> #define NM 50 int **init() {int **p,i; p=calloc(NM,sizeof(int)); if(p==NULL) exit(1); else for (i=0;i<NM;i++) {p[i]=calloc(NM,sizeof(int)); if(p[i]==NULL) exit(1); } return p; } void citire(int **p,int *n) {printf("n="); scanf("%d",n); int i,j; for (i=0;i<*n;i++) for (j=0;j<*n;j++) {printf("a[%d][%d]=",i+1,j+1); scanf("%d",&p[i][j]); } } void afisare(int **p,int n) { printf("\n"); int i,j; for (i=0;i<n;i++) {printf("\n"); for(j=0;j<n;j++) printf("%d ",p[i][j]); } } int **inmultire(int **p,int n,int**q,int m) {if (n!=m) {printf("\nMatrici diferite ca rang!"); return NULL;} else{ int i=0; int **c; c=init(); while (i<n) { int j,k,s=0; for (j=0;j<n;j++) {s=0;

} afisare(c,n); return c; }

for (k=0;k<n;k++) s+=p[i][k]*q[k][j]; c[i][j]=s; } i++;

void del (int **p) {int i; for (i=0;i<NM;i++) free(p[i]); //free(p); } int main() { int **p,**q,**r,n,m; p=init(); q=init(); citire(p,&n); citire(q,&m); afisare(p,n); afisare(q,m); inmultire(p,n,q,m); del(p); del(q); del(r); getchar(); return 0; } /* Using only pointers and pointer expressions, write a function to sort a vector with real number elements.*/ #include <stdio.h> #include <stdlib.h> #define NM 50 float *init() {float *p; p=calloc(NM,sizeof(float)); if(p==NULL) exit (1); return p; } void citire(float *p,int *n) { printf("n="); scanf("%d",n); int i; for (i=0;i<*n;i++) {printf("a[%d]=",i+1); scanf("%f",p+i); } }

void sort(float *p,int n) {int i,j; for (i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(*(p+j)<*(p+i)) {float aux=*(p+i);*(p+i)=*(p+j);*(p+j)=aux;} } void afisare(float *p, int n) {int i;printf("\n"); for (i=0;i<n;i++) printf("%5.2f ",*(p+i)); } int main() {float *p; int n; p=init(); citire(p,&n); sort(p,n); afisare(p,n); getchar(); return 0; } /*Using only pointers and pointer expressions, write a function to merge two vectors. The given vectors contain real number elements, in ascending order. The result vector must contain only the distinct elements of the two given vectors, also in ascending order*/ #include <stdio.h> #include <stdlib.h> #define NM 50 float *init(int a) {float *p; p=calloc(a*NM,sizeof(float)); if(p==NULL) exit (1); return p; } void citire(float *p,int *n) { printf("\nn="); scanf("%d",n); int i=0; citire: {printf("a[%d]=",i+1); scanf("%f",p+i); if (i>0&&*(p+i)<=*(p+i-1)) {printf("\n\tValoare gresita!\r\n");i--;} i++; } if (i<*n)goto citire; } void afisare(float *p, int n) {int i;printf("\n"); for (i=0;i<n;i++) printf("%5.2f ",*(p+i));

} void merge(float *a,int n, float *b,int m) {int i,j,k; i=j=k=0; float *c; c=init(2); verificare: {if (a[i]<b[j]) {c[k]=a[i];k++;i++;} else if (b[j]<a[i]) {c[k]=b[j];k++;j++;} else {c[k]=a[i];k++;i++;j++;} } if (i<n&&j<m) goto verificare; while (n-i>0) {c[k]=a[i];k++;i++;} while (m-j>0) {c[k]=b[j];j++;k++;} printf("\n Interclasare: "); afisare(c,k); } int main() {float *a,*b; int n,m; a=init(1); b=init(1); citire(a,&n); citire(b,&m); merge(a,n,b,m); getchar(); return 0; } //Write a function to sort ascending n character strings*/ #include <stdio.h> #include <stdlib.h> #define NM 250 #include <string.h> char *init() {char *p; p=calloc(NM,sizeof(char)); if(p==NULL) exit (1); return p; } void citire(char **p, int *n) {printf("n="); scanf("%d",n); gets(p[0]); int i; for (i=0;i<*n;i++) {p[i]=init(); printf("sir:"); gets(p[i]); } }

void afisare(char **p,int n) {int i;printf("\n"); for (i=0;i<n;i++) printf("\n %s",p[i]); } void sort (char **p,int n) {int i,j; for (i=0;i<n-1;i++) for (j=i+1;j<n;j++) if (stricmp(p[i],p[j])>0) {char s[250];strcpy(s,p[i]);strcpy(p[i],p[j]);strcpy(p[j],s);} } int main() {char **p; int n; *p=init(); citire(p,&n); sort(p,n); afisare(p,n); getchar(); return 0; } /*Sa se scrie o functie care calculeaza produsul a doua polinoame, folosind numai lucrul cu pointeri si expresii cu pointeri.*/ #include <stdio.h> #include <stdlib.h> void citire(int *a,int n) {int i; printf("\n"); for (i=0;i<=n;i++) {printf("x^%d=",i); scanf("%d",&a[i]); } } void afisare(int *a,int n) {int i; for (i=0;i<=n;i++) if (a[i]!=0) i==n?printf("%+d*x^%d",a[i],i):printf("%+d*x^%d",a[i],i); } void inmultire(int *a,int n,int *b,int m,int *c) {int i,j; for (i=0;i<=n;i++) for (j=0;j<=m;j++) c[i+j]+=a[i]*b[j]; } int main() {int *n,*m,*a,*b,*c; n=malloc(sizeof(int)); if (n==NULL) {fprintf(stderr,"\n\tEroare la alocarea de memorie"); exit(1);}

m=malloc(sizeof(int)); if(m==NULL) {fprintf(stderr,"\n\tEroare la alocarea de memorie"); exit(1);} printf(" n= "); scanf("%d",n); printf(" m= "); scanf("%d",m); a=calloc(*n+1,sizeof(int)); if(a==NULL) {fprintf(stderr,"\n\tEroare la alocarea de memorie"); exit(1);} b=calloc(*m+1,sizeof(int)); if(b==NULL) {fprintf(stderr,"\n\tEroare la alocarea de memorie"); exit(1);} citire(a,*n); citire(b,*m); c=calloc(*n+*m+2,sizeof(int)); if(c==NULL) {fprintf(stderr,"\n\tEroare la alocarea de memorie"); exit(1);} inmultire(a,*n,b,*m,c); printf("\n"); afisare(c,*n+*m); getchar(); getchar(); return 0;

/*Sa se scrie o functie care calculeaza puterea k a unei matrici patrate, folosind pointeri pentru referentierea elementelor matricei. Matricea obtinuta va fi afisata sub forma naturala.*/ #include <stdio.h> #include <stdlib.h> void citire(int **a, int n) { register int i,j; for (i=0;i<n;i++) for(j=0;j<n;j++) {printf("a[%d][%d]= ",i+1,j+1); scanf("%d",&a[i][j]); } } void atribuire (int **b,int **a,int n) {int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) b[i][j]=a[i][j]; } void inmultire(int **b,int **a, int n) {register int i,j,k; int **c,s=0; c=calloc(n,sizeof(int *)); if(c==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");} for (i=0;i<n;i++) {c[i]=calloc(n,sizeof(int)); if(c[i]==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");} } i=0; while (i<n) {for(j=0;j<n;j++) {s=0; for(k=0;k<n;k++)

} i++; } atribuire(b,c,n); for (i=0;i<n;i++) free(c[i]); free(c);

s+=b[i][k]*a[k][j]; c[i][j]=s;

void afisare(int **a,int n) {printf("\n"); int i,j; for (i=0;i<n;i++) {printf("\n"); for(j=0;j<n;j++) printf("%d ",a[i][j]); } } int main() { int n,j,**a,**b,k; register int i; printf("n="); scanf("%d",&n); printf("k= "); scanf("%d",&k); a=calloc(n,sizeof(int *)); if(a==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");} for (i=0;i<n;i++) {a[i]=calloc(n,sizeof(int)); if(a[i]==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");} } b=calloc(n,sizeof(int *)); if(b==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");} for (i=0;i<n;i++) {b[i]=calloc(n,sizeof(int)); if(b[i]==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");} } for (i=0;i<n;i++) for(j=0;j<n;j++) b[i][j]=1; citire(a,n); atribuire(b,a,n); for (i=1;i<k;i++) inmultire(b,a,n); printf("\nMatricea la puterea %d:",k); afisare(b,n); getchar(); getchar(); return 0;

/*Sa se scrie o functie care calculeaza matricea transpusa a unei matrice, folosind pointeri si expresii cu pointeri pentru referentierea elementelor matricei. Matricele vor fi afisate sub forma naturala.*/ #include <stdio.h> #include <stdlib.h> void citire(int **a, int n) { register int i,j; for (i=0;i<n;i++) for(j=0;j<n;j++) {printf("a[%d][%d]= ",i+1,j+1); scanf("%d",&a[i][j]); } } void atribuire (int **b,int **a,int n) {int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) b[i][j]=a[i][j]; } void transpusa(int **b,int **a,int n) {register int i,j; atribuire(b,a,n); for (i=0;i<n;i++) for(j=0;j<n;j++) if(i<=j) {int aux=b[j][i];b[j][i]=b[i][j];b[i][j]=aux;} } void afisare(int **a,int n) {printf("\n"); int i,j; for (i=0;i<n;i++) {printf("\n"); for(j=0;j<n;j++) printf("%d ",a[i][j]); } } int main() { int n,**a,**b; register int i; printf("n="); scanf("%d",&n); a=calloc(n,sizeof(int *)); if(a==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");} for (i=0;i<n;i++) {a[i]=calloc(n,sizeof(int)); if(a[i]==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");} } b=calloc(n,sizeof(int *)); if(b==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");}

for (i=0;i<n;i++) {b[i]=calloc(n,sizeof(int)); if(b[i]==NULL) {fprintf(stderr,"\n\tEroare la alocare de memorie");} } citire(a,n); transpusa(b,a,n); afisare(b,n); getchar(); getchar(); return 0;

/*Sa se scrie o functie recursiva si una nerecursiva pentru calculul valorii polinoamelor Hermite H(x) definite astfel: H0(x)=1; H1(x)=2x; Hn(x)=2nHn-1(x)-2(n-1)Hn-2(x), pentru n2.*/ #include <stdio.h> #include <stdlib.h> int hermite(int n,int x) {if (n==0) return 1; if(n==1) return 2*x; return (2*n*hermite(n-1,x)-2*(n-1)*hermite(n-2,x)); } int main() {int n,x; citire:{printf("n= "); scanf("%d",&n); } if(n<1) {printf("\n\t Valoare eronata pentru n");goto citire;} printf("x= "); scanf("%d",&x); printf("\n Valoare polinom Hemite: %d ",hermite(n,x)); getchar(); getchar(); return 0;

/*Problema turnurilor din Hanoi Se considera trei tije verticale A,B,C si n discuri de diametre diferite. Initial toate discurile sunt puse n tija A, n ordinea descrescatoare a diametrului (discul cel mai mare la baza, iar cel mai mic n vrf). Se cere sa se mute discurile de pe tija A pe tija C folosind tija B ca intermediar, folosind conditiile: a) la o manevra se muta un singur disc si anume cel din vrful unei tije; b) nu se poate pune un disc de diametru mai mare peste unul de diametru mai mic; c) n final, pe tija C, discurile trebuie sa fie n aceeasi ordine ca n starea initiala de pe tija A. */ #include <stdio.h> #include <stdlib.h> void hanoi(int n,char a,char b,char c) { if(n==1) printf("\n Mutare disc de pe %c pe %c",a,b);

else {hanoi(n-1,a,c,b); printf("\n Mutare disc de pe %c pe %c",a,b); hanoi(n-1,c,b,a); }

int main() { int n; char a='A',b='B',c='C'; printf("n= "); scanf("%d",&n); hanoi(n,a,c,b); getchar(); return 0; } /*Sa se scrie un program recursiv care citeste n cuvinte si le afiseaza n ordinea inversa a introducerii lor.*/ #include <stdio.h> #include <stdlib.h> void citire(int i,int n) {printf("\n cuvant:"); char s[100]; if(i==0) gets(s); gets(s); if(i+1<n) citire(i+1,n); printf("\n%s",s); }

int main() { int n; citire: {printf("\nn="); scanf("%d",&n); } if(n<0) {printf("\n\tValoare negativa a lui n!");goto citire;} if(n>0 )citire(0,n); getchar(); return 0; } //Sa se scrie un program recursiv de generare a produsului cartezian a n multimi. #include <stdio.h> #include <stdlib.h> int ok=0; void afisare(int k,int *x) {if(ok==1) printf(",("); else {printf("(");ok=1;} int i; printf("%d",x[0]); for(i=1;i<=k;i++)

printf(",%d",x[i]); printf(")");

void cartezian(int k,int n, int *v,int *x) {int i; for (i=1;i<=v[k];i++) {x[k]=i; if(k==n-1) afisare(k,x); else cartezian(k+1,n,v,x); } } int main() { int n,i,*v,*x; printf("n= "); scanf("%d",&n); v=calloc(n,sizeof(int)); if(v==NULL) {fprintf(stderr,"\n\tEroare la alocarea de memorie");exit(1);} x=calloc(n,sizeof(int)); if(x==NULL) {fprintf(stderr,"\n\tEroare la alocarea de memorie");exit(1);} printf("\n\t Multimile vor fi {1,2,...,k}\n"); for (i=0;i<n;i++) {printf("k[%d]= ",i+1); scanf("%d",&v[i]); } printf("\n{"); cartezian(0,n,v,x); printf("}"); getchar(); return 0; } /*Sa se scrie un program de generare recursiva a submultimilor de k elemente apartinnd multimii A cu n elemente (combinatiile de n elemente luate cte k).*/ #include <stdio.h> #include <stdlib.h> int x[100],n,k; int valid(int j) {int i; for (i=0;i<j;i++) if(x[i]>=x[j]) return 0; return 1; } void afisare(int j) {printf("\n"); int i; for (i=1;i<=j;i++) printf("%d ",x[i]); } void combinari(int j)

{int i; for (i=1;i<=n;i++) { x[j]=i; if (valid(j)) { if(j==k) afisare(j); else combinari(j+1); } } } int main() { citire: { printf("n="); scanf("%d",&n); } if(n<0) {printf("\n\t Valore a lui n negativa!");goto citire;} citire1: {printf("k="); scanf("%d",&k); } if(k>n) {printf("\n\tValoare a lui K mai mare decat n!");goto citire1;} combinari(1); getchar(); return 0; } /*Sa se scrie un program de rezolvare a problemei celor 8 regine (determinarea tuturor asezarilor pe tabla de sah a celor 8 regine astfel nct sa nu se atace).*/ #include <stdio.h> #include <stdlib.h> #include <math.h> int valid(int k,int x[]) { int i; for(i=1;i<k;i++) if(x[i]==x[k] || abs(x[i]-x[k])==k-i) return 0; return 1; } void afisare(int k, int x[]) {int i; for(i=1;i<=k;i++) printf("%d ",x[i]); printf("\n"); } void regina(int k,int x[]) {int i; for(i=1;i<=8;i++) {x[k]=i; if(valid(k,x)) {if(k==8) afisare(k,x); else regina(k+1,x);

int main() { int x[9]; regina(1,x); getchar(); return 0; } //Sa se genereze recursiv permutarile multimii A de n elemente. #include <stdio.h> #include <stdlib.h> int valid(int k,int *x) {int i; for(i=0;i<k;i++) if(x[i]==x[k]) return 0; return 1; } void afisare(int k,int *x) {printf("\n"); int i; for (i=0;i<=k;i++) printf("%d ",x[i]); } void permutari(int k,int n,int *x) {int i; for (i=1;i<=n;i++) {x[k]=i; if(valid(k,x)) {if(k==n-1) afisare(k,x); else permutari(k+1,n,x); } } } int main() {int n,*x; printf("n= "); scanf("%d",&n); x=calloc(n,sizeof(int)); if(x==NULL) {fprintf(stderr,"\nEroare la alocare de memorie");exit(1);} permutari(0,n,x); getchar(); return 0; } /*Funcia lui Ackermann. S se scrie programul recursiv care calculeaz funcia lui Ackermann definit astfel: Ack(0,n)=n+1 pentru n N Ack(m,0)=Ack(m-1,1) pentru m N* Ack(m,n)=Ack(m-1,Ack(m,n-1)) pentru m,n N* */

#include <stdio.h> #include <stdlib.h> int ack( register int m,register int n) { switch(m) {case 0: return n+1; default: switch (n) {case 0: return ack(m-1,1); default: return ack(m-1,ack(m,n-1)); } } } int main() {int n,m; citire: { printf("n="); scanf("%d",&n); } if(n<0) {printf("\n\t Valore a lui n negativa!");goto citire;} citire1: {printf("m="); scanf("%d",&m); } if(m<0) {printf("\n\tValoare a lui m negativa!");goto citire1;} printf("Ack(%d,%d)=%d",n,m,ack(n,m)); getchar(); return 0;

/*Generarea partitiilor numarului natural n. Sa se scrie o functie recursiva de generare a tuturor partitiilor unui numar natural n. Doua partitii difera ntre ele fie prin valorile elementelor din partitie, fie prin ordinea acestora. Exempu: partitiile numarului 4 sunt: {1,1,1,1},{1,1,2},{1,2,1},{1,3},{2,1,1},{2,2},{3,1},{4}.*/ #include <stdio.h> #include <stdlib.h> int ok=1; int solutie(int k,int n,int *x) {int i,s=0; for (i=0;i<=k;i++) s+=x[i]; if(s==n) return 1; return 0; } void afisare(int k,int *x) {int i; if(ok){printf("{%d",x[0]);ok=0;} else printf(",{%d",x[0]); for (i=1;i<=k;i++) printf(",%d",x[i]);

printf("}");

void part(int k,int n,int *x) {int i; for(i=1;i<=n;i++) {x[k]=i; if(solutie(k,n,x)) afisare(k,x); else if(k<n) part(k+1,n,x); } } int main() {int n,*x; citire: {printf("n= "); scanf("%d",&n); } if(n<0) {printf("\n\tValoare gresita a lui n\n");goto citire;} x=calloc(n,sizeof(int)); if (x==NULL) {fprintf(stderr,"\nEroare la alocare de memorie");exit(1);} part(0,n,x); getchar(); return 0; } /*Un labirint este codificat printr-o matrice de m*n elemente , ale carui culoare sunt reprezentate prin elemente egale cu 1, situate n pozitii consecutive, pe o aceeasi linie sau o aceeasi coloana. Se cere afisarea tuturor traseelor de iesire din labirint, ncepnd cu punctul initial (i,j), cu conditia ca traseele sa nu treaca de mai multe ori prin acelasi loc.*/ #include <stdio.h> #include <stdlib.h> struct element {int x,y;}; int valid(struct element *s,int k,int **v) {int i; if(v[s[k].x][s[k].y]==0) return 0; for (i=0;i<k;i++) if(s[i].x==s[k].x&&s[i].y==s[k].y) return 0; return 1; } int solutie(struct element *s,int k,int n,int m) {if (s[k].y==0||s[k].y==m||s[k].x==0||s[k].x==n) return 1; return 0; } void print(int **a,int n,int m) {int i,j; for (i=0;i<n;i++) {printf("\n"); for(j=0;j<m;j++) if(a[i][j]=='x') printf("%c ",a[i][j]); else printf("%d ",a[i][j]);

} } void afisare(struct element *s,int k,int n,int m) {printf("\n"); int i,**b; b=calloc(n,sizeof(int *)); if(b==NULL) {fprintf(stderr,"\nEroare la alocare de memorie");exit(1);} for(i=0;i<n;i++) {b[i]=calloc(m,sizeof(int)); if(b[i]==NULL) {fprintf(stderr,"\nEroare la alocare de memorie");exit(1);} } for(i=0;i<=k;i++) if(i==0) b[s[i].x][s[i].y]='x'; else b[s[i].x][s[i].y]=i; print(b,n,m); for(i=0;i<n;i++) free(b[i]); free(b); } void labirint(int k,struct element *s,int **v,int n,int m,struct element *p) {int i; for (i=0;i<4;i++) {s[k].x=s[k-1].x+p[i].x; s[k].y=s[k-1].y+p[i].y; if (valid(s,k,v)) {if(solutie(s,k,n,m)) afisare(s,k,n,m); else labirint(k+1,s,v,n,m,p); } } } void citire(int **v,int *n,int *m) {int i,j; FILE *in; in=fopen("matrice.txt","r"); if(in==NULL) {fprintf(stderr,"\nEroare la deschiderea fisierului");exit(1);} for(i=0;i<*n;i++) {v[i]=calloc(*m,sizeof(int)); if(v[i]==NULL) {fprintf(stderr,"\nEroare la alocare de memorie");exit(1);} } fscanf(in,"%d %d",&i,&j); for(i=0;i<*n;i++) for(j=0;j<*m;j++) fscanf(in,"%d",&v[i][j]); fclose(in); print(v,*n,*m); } int main() {int *n,*m,**v; struct element *s,p[]={{-1,0},{0,1},{1,0},{0,-1}}; n=malloc(sizeof(int)); if(n==NULL) {fprintf(stderr,"\nEroare la alocare de memorie");exit(1);} m=malloc(sizeof(int)); if(m==NULL) {fprintf(stderr,"\nEroare la alocare de memorie");exit(1);} FILE *in; in=fopen("matrice.txt","r");

if(in==NULL) {fprintf(stderr,"\nEroare la deschiderea fisierului");exit(1);} fscanf(in,"%d %d",n,m); v=calloc(*n,sizeof(int *)); if(v==NULL) {fprintf(stderr,"\nEroare la alocare de memorie");exit(1);} s=calloc(*n**m,sizeof(struct element)); if(s==NULL) {fprintf(stderr,"\nEroare la alocare de memorie");exit(1);} fclose(in); citire(v,n,m); citi: { printf("pozitia initiala:\nx="); scanf("%d",&s[0].x); printf("y="); scanf("%d",&s[0].y); } #error Codeblock prost da erori la alocari de memorie if(v[s[0].x][s[0].y]==0) {printf("\n Pozitia introdusa este zid\n");goto citi;} labirint(1,s,v,*n,*m,p); getchar(); return 0;

/*Cunoscnd data de nastere a Dvs. si stiind ca n anul curent va aniversati ziua de nastere n ziua de x [luni, marti, ..., duminica], scrieti un program pentru a afisa ziua (din saptamna) n care vati nascut*/ #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct {int zi,luna,an; } data;

int bisect(int a) { if ((a%4==0&&a%100!=0)||(a%400==0)) return 1; return 0; } int main() {data a; int s,i,b; char ch[10]; printf("zi nastere:"); scanf("%d",&a.zi); printf("luna:"); scanf("%d",&a.luna); printf("an:"); scanf("%d",&a.an); gets(ch); printf("zi din saptamana de nastere din anul curent:"); gets(ch); if(!strcmp(ch,"Duminica")) b=0; if(!strcmp(ch,"Luni")) b=1; if(!strcmp(ch,"Marti")) b=2;

if(!strcmp(ch,"Miercuri")) b=3; if(!strcmp(ch,"Joi")) b=4; if(!strcmp(ch,"Vineri")) b=5; if(!strcmp(ch,"Sambata")) b=6; sscanf(__DATE__,"%*s %*d %d",&s); for (i=s;i>a.an;i--) if(bisect(i)) {if(b==0) b=5;else if(b==1) b=6; else b-=2;} else {if(b==0) b=6;else b--;} switch(b) {case 0:printf("\nDuminica");break; case 1:printf("\nLuni");break; case 2:printf("\nMarti");break; case 3:printf("\nMiercuri");break; case 4:printf("\nJoi");break; case 5:printf("\nVineri");break; case 6:printf("\nSambata");break; } getchar(); return 0; }

/* P.s. Nu toate problemele sunt aici , am pus cat am reusit sa fac Daca ceva problema nu merge, asta-i viata...intentia conteaza Spor :* */