Whiskey mi-a spus sa fac asta,contactati-l pe discord

#1
10
#include<stdio.h>
#include<stdlib.h>
#define N 30
int main()
{
char *s1,s2[N];
int i;
s1=(char*)malloc(sizeof(char)*(N+1));
if(!s1)
{
printf("Memorie insuficienta");
exit(1);
}
printf("Introduceti un sir de caractere de maxim 30 de caractere.");
for(i=0;(*(s1+i)=getchar())!='\n';i++)
;
*(s1+i)='\0';
puts(s1);

printf("sirul 1 copiat in sirul 2 este:\n");
for(i=0;*(s2+i)=*(s1+i);i++)
;
puts(s2);

}

14
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define N 30
#define M 30
int main()
{
int a[M][N],m, n,i,j,sum=0,nr=0;
double ma;
printf("introduceti dimensiunea matricii:");
if(scanf("%d%d",&m,&n)!=2 || m<0| n<0 | m>M ||n>N)
{
printf("date eronate");
exit(1);
}
printf("introduceti elemntele matricii:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{ printf("a[%d][%d]=",i,j);
if(scanf("%d",&a[j])!=1)
{
printf("Date eronate");
exit(1);
}

}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[j]);
}
printf("\n");
}

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[j]%2==0)
{
sum=sum+a[j];
nr=nr+1;
}
}
}
ma=(double)sum/nr;
printf("Media artimetica este %g ",ma);
}


16
#include<stdio.h>
#include<stdlib.h>
#define N 30
int main()
{
char *s;
int i,l;

s=(char*)malloc(sizeof(char)*(N+1));
if(!s)
{
printf("Memorie insuficienta");
exit(1);
}
printf("Introduceti sirul.\n");
for(i=0;(*(s+i)=getchar())!='\n' && i<N;i++)
;
*(s+i)='\0';
puts(s);
for(l=0;*(s+l)!='\0';l++)
;
printf("Lungimea sirului este %d",l);
}

bilet2
#include<stdio.h>
#include<stdlib.h>
#define N 100
#define M 100
int main()
{
int a[N][M],n,m,c=0,s=0,i,j;
double ma;
printf("Introduceti dimensiunile matricei n linii si m coloane");
if(scanf("%d %d",&n,&m)!=2 || n<0 ||n>N || m<0 ||m>M)
{
printf("Date eronate");
exit(1);
}
printf("Introduceti elementele matricei.\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("\na[%d][%d]=",i,j);
if(scanf("%d",&a[j])!=1)
{
printf("Date eronate");
exit(1);
}
}
}
printf("Matricea a:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d\t",a[j]);
}
printf("\n");
}
//media aritmetica a elementelor de sub diagonala principala inclusiv
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
s=s+a[j];
c++;
}
}
ma=(double)s/c;
printf("Media aritmetica a elementelor de sub diagonala principala inclusiv este %g",ma);
}


bilet 9
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define N 100
#define M 100
int main()
{
int m, n, i, j, imax, jmax;
float elmax,a[M][N];
printf("Introduceti dimensiunea matricii (m<%d,n<=%d):\n",M,N);
if(scanf("%d%d",&m,&n)!=2 ||m>N ||m<1 || n>N || n<1)
{
printf("Date eronate");
exit(1);
}
//citire matrice A
printf("Introduceti elementele matricii A:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
if(scanf("%f",&a[j])!=1)
{
printf("Date eronate");
exit(1);
}
}
//afisare matrice A
printf("Matricea A este:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%g\t",a[j]);
printf("\n");
}
//maxim dintre elem pozitive
elmax=a[0][0];
imax=jmax=0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
if(a[j]>0 && a[i][j]>elmax)
{
elmax=a[i][j];
imax=i;
jmax=j;
}

}
printf("maxim=%g=a[%d][%d] \n", elmax, imax, jmax);
return 0;
}

bilet 14 matrice
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define N 100
#define M 100
int main()
{
int m, n, i, j, nrp, s;
float a[M][N], ma;
printf("Introduceti dimensiunea matricii (m<%d,n<=%d):\n",M,N);
if(scanf("%d%d",&m,&n)!=2 ||m>N ||m<1 || n>N || n<1)
{
printf("Date eronate");
exit(1);
}
//citire matrice A
printf("Introduceti elementele matricii A:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
if(scanf("%f",&a[i][j])!=1)
{
printf("Date eronate");
exit(1);
}
}
//afisare matrice A
printf("Matricea A este:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%g\t",a[i][j]);
printf("\n");
}
nrp=0;
s=0;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(fmod(a[i][j], 2)==0)
{
s=s+a[i][j];
nrp++;
}
ma=(float)s/nrp;
printf("media aritmetica=%g", ma);

return 0;
}

bilet 18
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
int n, a;
FILE *f; //pointer catre fisier
f=fopen("f1.txt", "w"); //crearea fisierului in directorul curent si deschiderea pt scriere
if(!f)
{
printf("fisierul nu a fost deschis");
exit(1);
}
printf("introduceti un numar intreg: (pt a termina apasati CTRL+z) \n");
while((a=scanf("%d", &n))!=EOF)
{
if(a!=1)
{
printf("Date incorecte \n");
fflush(stdin);
}
else
fprintf(f, "%d \n", n);
}
fclose(f);
return 0;
}
25
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define N 100

int main()
{
int i, j, n ;
float x[N], y[N], t[N][N];
printf("Introduceti dimensiunea(n<%d): \n", N);
if(scanf("%d", &n)!=1 || n<1 || n>N)
{
printf("Dimensiune eronata");
exit(1);
}
printf("Introduceti %d elemente reale \n", n);
for(i=0; i<n; i++)
{
printf("x[%d]=", i);
if(scanf("%f", &x[i])!=1)
{
printf("Date eronate");
exit(1);
}
}
printf("Vectorul x este: \n");
for(i=0; i<n; i++)
printf("%g\t", x[i]);
//afisare vector x pana aici
printf("Introduceti %d elemente reale \n", n);
for(i=0; i<n; i++)
{
printf("y[%d]=", i);
if(scanf("%f", &y[i])!=1)
{
printf("Date eronate");
exit(1);
}
}
printf("Vectorul y este: \n");
for(i=0; i<n; i++)
printf("%g\t", y[i]);



for(i=0;i<n;i++)
for(j=0; j<n; j++)
t[i][j]=x[i]*y[j];
printf("\n produsul transpus este: \n");
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
printf("%g\t", t[i][j]);
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define N 100
#define M 100
int main()
{
int m,n,i,j,imin,jmin;
float elmin, a[M][N];
double p;
printf("Introduceti dimensiunea matricii (m<%d,n<=%d):\n",M,N);
if(scanf("%d%d",&m,&n)!=2 ||m>M ||m<1 || n>N || n<1)
{
printf("Date eronate");
exit(1);
}
//citire matrice A
printf("Introduceti elementele matricii A:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
if(scanf("%f",&a[i][j])!=1)
{
printf("Date eronate");
exit(1);
}
}
//afisare matrice A
printf("Matricea A este:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%g\t",a[i][j]);
printf("\n");
}
elmin=a[0][0];
imin=0;
jmin=0;
for(j=0;j<n;j=j+2) //parcurgem coloanele impare
for(i=0;i<m;i++)
if(a[i][j]<elmin)
{
elmin=a[i][j];
imin=i;
jmin=j;
}
printf("minimul de pe coloanele impare este: %g=a[%d][%d]", elmin, imin, jmin);
return 0;
}
constr vector clasic
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#define N 50

int main()
{
int i,n,k;
double v[N],w[N];
printf("Introduceti dimensiunea vectorului (n<%d):\n",N);
if(scanf("%d",&n)!=1||n<1||n>N)
{
printf("Date eronate");
exit(1);
}
printf("Introduceti %d elemente reale:\n",n);
for(i=0;i<n;i++)
{
printf("v[%2d]=",i);
if(scanf("%lf",&v[i])!=1)
{
printf("Date eronate");
exit(1);
}
}
printf("Vectorul introdus este:\n");
for(i=0;i<n;i++)
{
printf("%g\t",v[i]);
}
k=0;
for(i=n-1;i>=0;i--)
{
if(fmod(v[i],5)==0)
{
w[k]=v[i];
k++;
}
}
printf("\nVectorul w este:\n");
for(i=0;i<k;i++)
printf("%g\t", w[i]);
return 0;
}

constr vector pointeri
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#define N 50

int main()
{
double *v,*w;
int i,n,k;
printf("Introduceti dimensiunea vectorului n<=%d\n",N);
if(scanf("%d", &n)!=1||n>N||n<1)
{
printf("Date eronate");
exit(1);
}
v=(double*)malloc(sizeof(double));
if(!v)
{
printf("Memorie insuficienta");
exit(1);
}
w=(double*)malloc(sizeof(double));
if(!w)
{
printf("Memorie insuficienta");
exit(1);
}
printf("Introduceti %d numere reale:\n",n);
for(i=0;i<n;i++)
{
printf("v[%d]=",i);
if(scanf("%lf",&v[i])!=1)
{
printf("Date eronate");
exit(1);
}
}
printf("Vectorul v este:\n");
for(i=0;i<n;i++)
printf("%g\t",*(v+i));
k=0;
for(i=n-1;i>=0;i--)
{
if(fmod(*(v+i),5)==0)
{
*(w+k)=*(v+i);
k++;
}
}
printf("\nVectorul w este:\n");
for(i=0;i<k;i++)
printf("%g\t", *(w+i));
free(v);
free(w);
return 0;
}
data nasterii
#include<stdlib.h>
#include<stdio.h>
typedef struct
{
int zi, luna, an;
}Data_cal;
int valid_zi(int, int, int);
int main()
{
Data_cal dn, dc;
int varsta;
printf("Introduceti data nasterii(zi/luna/an): \n");
if(scanf("%d/%d/%d", &dn.zi, &dn.luna, &dn.an)!=3 || valid_zi(dn.zi, dn.luna, dn.an)==0 || dn.luna<1 || dn.luna>12 || dn.an<1600 || dn.an>4900)
{
printf("Data eronata");
exit(1);
}
printf("Introduceti data curenta(zi/luna/an): \n");
if(scanf("%d/%d/%d", &dc.zi, &dc.luna, &dc.an)!=3 || valid_zi(dc.zi, dc.luna, dc.an)==0 || dc.luna<1 || dc.luna>12 || dc.an<1600 || dc.an>4900 || dc.an<dn.an || (dn.an==dc.an && dc.luna<dn.luna) || (dc.an==dn.an && dc.luna==dn.luna && dc.zi<dn.zi))
{
printf("Data eronata");
exit(1);
}
varsta=dc.an-dn.an;
if(dc.luna<dn.luna)
varsta--;
if(dc.luna=dn.luna && dc.zi<dn.zi)
varsta--;
printf("Varsta persoanei este=%d ani \n", varsta);
return 0;
}
int valid_zi(int zz, int ll, int an)
{
int bis=an%4==0 && an%100!=0 || an%400==0;
int zile[]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(zz>=1 && zz<=zile[ll]+(bis && ll==2))
return 1;
else
return 0;
}


matrice clasic
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define N 100
#define M 100
int main()
{
int m,n,i,j,imin,imax,jmin,jmax,nrp,nrn,nr0,k;
float s,elmin, elmax, a[M][N],b[M][N],c[M][N],at[N][M];
double p;
printf("Introduceti dimensiunea matricei (m<=%d, n<=%d):\n",M,N);
if(scanf("%d%d",&m,&n)!=2||m>M||m<1||n>N||n<1)
{
printf("Date eronate");
exit(1);
}
//citirea matricei A
printf("Introduceti elementele matricii A:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
if(scanf("%f",&a[i][j])!=1)
{
printf("Date eronate");
exit(1);
}
}
//citirea matricii B
printf("Introduceti elementele matricii B:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("b[%d][%d]=",i,j);
if(scanf("%f",&b[i][j])!=1)
{
printf("Date eronate");
exit(1);
}
}
//afisarea matricii A
printf("Matricea A este:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%g\t", a[i][j]);
printf("\n");
}
//afisarea matricii B
printf("Matricea B este:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%g\t", b[i][j]);
printf("\n");
}
//C=A+B
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
}
printf("Matricea C=A+B este:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%g\t", c[i][j]);
printf("\n");
}
//transpusa matricii A
for(i=0;i<m;i++)
for(j=0;j<n;j++)
at[i][j]=a[j][i];
printf("Transpusa matricii A este:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%g\t", at[i][j]);
printf("\n");
}
elmin=elmax=a[0][0];
imin=imax=jmin=jmax=0;
p=1.0;
s=0;
nrp=nrn=nr0=0;

for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
s=s+a[i][j]; //suma
p=p*a[i][j]; //produs
//minim
if(a[i][j]<elmin)
{
a[i][j]=elmin;
imin=i;
jmin=j;
}
//maxim
if(a[i][j]>elmax)
{
elmax=a[i][j];
imax=i;
jmax=j;
}
//elemente pozitive,negative,nule in matrice
if(a[i][j]>0)
nrp++;
else
if(a[i][j]<0)
nrn++;
else
nr0++;
}
printf("\n suma=%g \n produsul=%g \n minim=a[%d][%d]=%g \n nr poz=%d \n nr neg=%d \n nr nule=%d \n", s, p, imin, jmin, elmin, nrp, nrn, nr0);
printf("\nmaxim=a[%d][%d]=%g \n",imax,jmax,elmax);
return 0;
}

nota 5
//vect v max 50 elem, cit si afis cu pointeri
//vect w care are elem multiplu de 7 din v dar in sens invers de parcurgere si afisare w
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 50
int main()
{
double *v, *w;
int i, n, k;
printf("introduceti dimensiunea vectorului (n<=%d):", N);
if(scanf("%d", &n)!=1 || n>N || n<1)
{
printf("Date eronate");
exit(1);
}
//initializare pointer v
//alocare dinamica de memorie in zona heap
v=(double*)malloc(n*sizeof(double)); //pointer catre double cu conversie explicita
if(!v)
{
printf("memorie insuficienta");
exit(1);
}
w=(double*)malloc(n*sizeof(double)); //pointer catre double cu conversie explicita
if(!w)
{
printf("memorie insuficienta");
exit(1);
}
printf("introduceti %d nr reale: \n", n);
for(i=0; i<n; i++)
{
printf("v[%d]=", i);
if(scanf("%lf", v+i)!=1) // v+i <=> &v[i]
{
printf("Date eronate");
exit(1);
}
}
printf("vectorul v: \n"); //afisare v
// *(v+i)=v[i]
for(i=0; i<n; i++)
printf("%g \t", *(v+i)); //operator * de indirectare
k=0;
for(i=n-1; i>=0; i--) //parcurgere inversa a vectorului
{
if(fmod(*(v+i), 7)==0)
{
*(w+k)=*(v+i); // <=> w[k]=v[i], punem in w valoarea din v
k++;
}
}
printf("vectorul w: \n");
for(i=0; i<k; i++)
printf("%g \t", *(w+i));
free(v);
free(w);
return 0;
}

nota 51
//2 siruri, max 30 caract, s1, s2, citeste s1 si copiaza in s2 folosind pointeri
//afiseaza s2
#include<stdlib.h>
#include<stdio.h>
#define N 31
int main()
{
char *s1, *s2;
int i;
s1=(char*)malloc(N*sizeof(char)); //alocare dinamica de memorie
if(!s1)
{
printf("Memorie insuficienta");
exit(1);
}
s2=(char*)malloc(N*sizeof(char)); //alocare dinamica de memorie
if(!s2)
{
printf("Memorie insuficienta");
exit(1);
}
printf("introduceti un sir de max %d caractere: \n", N-1);
for(i=0; (*(s1+i)=getchar())!='\n' && i<(N-1); i++) //prioritizam citirea caracterului prin paranteza de dinainte de *
;
*(s1+i)='\0'; //suprascriem cu marca de sfarsit de sir
puts(s1);
for(i=0; *(s2+i)=*(s1+i); i++) // s1[i]=s2[i]
;
puts(s2);
return 0;
}

nota 52
//creare f1.txt in directoru crt(ajunge doar numele fisierului, nu trebuie definita o cale)
//citire un intreg, caract, real, pe care un rand in fisier
//la final ctrl+Z
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
int n, a;
char c;
float x;
FILE *f; //pointer catre fisier
f=fopen("f1.txt", "w"); //crearea fisierului in directorul curent si deschiderea pt scriere
if(!f)
{
printf("fisierul nu a fost deschis");
exit(1);
}
printf("introduceti un intreg, un caracter, un real: (pt a termina apasati CTRL+z) \n");
while((a=scanf("%d %c %f", &n, &c, &x))!=EOF)
{
if(a!=3)
{
printf("Date incorecte \n");
fflush(stdin);
}
else
fprintf(f, "%d \t %c \t %g \n", n, c, x);
}
fclose(f);
return 0;
}


proddus vect matrice
#include<stdio.h>
#include<stdlib.h>
#define M 30
#define N 40
int main()
{
int a[M][N], v[M], w[N]; //v?
int i, j, k, m, n, s;

printf("Introduceti dimensiunile matricei m,n:");
if(scanf("%d%d", &m, &n)!=2 || m<1 || n<1 || m>M || n>N)
{
printf("Date Eronate!");
exit(1);
}

printf("Introduceti elementele matricii a:\n");
for(i=0; i<m; i++)
for(j=0; j<n; j++)
{
printf("a[%d][%d]=", i, j);
if(scanf("%d", &a[i][j])!=1)
{
printf("Date eronate!");
exit(1);
}
}

for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
printf("%d\t", a[i][j]);
printf("\n");
}
printf("Introduceti elementele vectorului \n");

for(i=0; i<m; i++)
{
printf("v[%d]=", i);
if(scanf("%d", &v[i])!=1)
{
printf("Date Eronate!");
exit(1);
}
}
printf("Vectorul este: \n");
for(i=0; i<m; i++)
{
printf("%d\t", v[i]);
}

printf("\n Produsul este: \n");
for(i=0; i<n; i++)
{
w[i]=0;// s=0;
for(k=0; k<m; k++)
w[i]=w[i]+v[k]*a[k][i];
}
for(i=0;i<n;i++)
printf("%d\t",w[i]);
return 0;
}

sir de caractere cautare litera
#include <stdio.h>
#define MAX 255
int main()
{
int i;
char prop[MAX];
printf ("Introduceti propozitia : \n");
gets (prop);
puts (prop);
int nr_car=0;
for(i=0;prop[i]!='\0';i++)
nr_car++;

printf ("Propozitia are %d caractere.\n",nr_car);

int nr_cuv=1;
for (i=1;prop[i]!='\0';i++)
if (prop[i]==' ')
nr_cuv++;
printf ("Propozitia are %d cuvinte.\n",nr_cuv);

int nr_a=0;
for (i=0;prop[i]!='\0';i++)
if (prop[i]=='a'||prop[i]=='A')
nr_a++;
printf ("In propozitie intalnim de %d ori litera a sau A.\n",nr_a);
return 0;
}

siruri pointeri
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define N 31

int main()
{
char *s1,*s2;
int i;
s1=(char*)malloc(N*sizeof(char));
if(!s1)
{
printf("Memorie insuficienta");
exit(1);
}
s2=(char*)malloc(N*sizeof(char));
if(!s2)
{
printf("Memorie insuficienta");
exit(1);
}
printf("Introduceti un sir de maxim %d caractere:\n", N-1);
for(i=0;(*(s1+i)=getchar())!='\n'&&i<(N-1);i++)
;
*(s1+i)='\0';
puts(s1);
for(i=0;*(s2+i)=*(s1+i);i++)
;
puts(s2);
free(s1);
free(s2);
return 0;
}
siruri lungimi comparare copiere
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define max 255
int main(void)
{
int i,n,l1=0,l2=0,r;
char v1[max],v2[max],v3[max];

printf("Introduceti sir1:\n");
gets(v1);

printf("Introduceti sir2:\n");
gets(v2);

printf("L sir1=%d\tL sir2=%d\n",strlen(v1),strlen(v2));

for(i=0;v1[i]==v2[i];i++)
if(v1[i]=='\0')
break;
r=v1[i]-v2[i];
if(r!=0)
printf("Rezultatul=%d deci sir1 %c sir2\n",r, r>0?'>':'<');
else
printf("Rezultatul=0 deci sir1=sir2\n");

strcpy(v3,v1);

printf("Sir3: ");
puts(v3);
putch('\n');
printf("Introduceti sirul:\n");
i=0;
while((v1[i]=getchar())!='\n'&&i<max)
i++;
v1[i]='\0';

printf("Sir nou: ");
puts(v1);

return 0;
}

structuri data nasterii
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
int zi,luna,an;
}Data_cal;
int valid_zi(int,int,int);
int main()
{
Data_cal dn, dc;
int varsta;
printf("Introduceti data nasterii(zi/luna/an):\n");
if(scanf("%d%d%d",&dc.zi,&dc.luna,&dc.an)!=3||)
}

sub diag princip drodus suma
#include<stdlib.h>
#include<stdio.h>
#define N 100
#define M 100
int main()
{
int i, j, m, n, s1s=0, s1d=0, s2s=0, s2d=0;
float p1s=1.0, p1d=1.0, p2s=1.0, p2d=1.0, a[M][N];
printf("Introduceti dimensiunea matricii (m<%d,n<=%d):\n",M,N);
if(scanf("%d%d",&m,&n)!=2 ||m>M ||m<1 || n>N || n<1)
{
printf("Date eronate");
exit(1);
}
//citire matrice A
printf("Introduceti elementele matricii A:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
if(scanf("%f",&a[i][j])!=1)
{
printf("Date eronate");
exit(1);
}
}
printf("Matricea A este:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%g\t",a[i][j]);
printf("\n");
}
//validare a matricei (trebuie sa fie patratica)
if(n!=m)
printf("\n The matrix is not a square!");
else
{
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if(j<i)
{
p1s=p1s*a[i][j];
s1s=s1s+a[i][j];
}//suma elementelor de sub diagonala principala
printf("\n Under main elements prod is:%f",p1s);
printf("\n Under main elements sum is:%d",s1s);
}


//validare a matricei (trebuie sa fie patratica)
if(n!=m)
printf("\n The matrix is not a square!");
else
{
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if(j>i)
{
s1d=s1d+a[i][j];
p1d=p1d*a[i][j]; //suma elementelor de deasupra diagonalei principale
}
printf("\n Above main elements sum is :%d",s1d);
printf("\n Above main elements prod is:%f",p1d);
}
//validare a matricei (trebuie sa fie patratica)
if(n!=m) printf("\n The matrix is not a square !");
else
{
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if((i+j)>(n-1))
p2s*=a[i][j];
s2s+=a[i][j]; //suma elementelor de sub diagonala secundara
printf("\n Under secondary elements sum is%d",s2s);
printf("\n Under secondary elements prod is%f",p2s);
}
//validare a matricei (trebuie sa fie patratica)
if(n!=m)
printf("\n The matrix is not a square !");
else
{
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if((i+j)<(n-1))
s2d+=a[i][j];
p2d*=a[i][j];
//suma elementelor de deasupra diagonalei secundara
printf("\n Above secondary elements sum is %d", s2d);
printf("\n Above secondary elements prod is %f",p2d);
}
}
suma fractii
#include<stdlib.h>
#include<stdio.h>
typedef struct
{
long numarator, numitor;
}Rational;
void citfr(const char *, Rational*);
void sumfr(Rational*, Rational*, Rational*);
void prodfr(Rational*, Rational*, Rational*);
void rapfr(Rational*, Rational*, Rational*);
void simplif(Rational*);
long cmmdc(long, long);
long cmmmc(long, long);
int main()
{
Rational f1, f2, f3;
citfr("Introduceti fractia f1(numarator/numitor): \n", &f1);
citfr("Introduceti fractia f2(numarator/numitor): \n", &f2);
sumfr(&f1, &f2, &f3);
simplif(&f3);
printf("%ld/&ld+%ld/%ld=%ld/%ld \n", f1.numarator, f1.numitor, f2.numarator, f2.numitor, f3.numarator, f3.numitor);
return 0;
}
void citfr(const char *text, Rational*f)
{
puts(text);
if(scanf("%ld/%ld", &f->numarator, &f->numitor)!=2 || f->numitor==0)
{
printf("Date eronate");
exit(1);
}

}

switch
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
int main(void)
{
double x,y,e;
char op,c;
printf("Introduceti operanzii:\n");
if(scanf("%lf%lf",&x,&y)!=2)
{
printf("Date eronate");
exit(1);
}
printf("\nIntroduceti operatia:\n");
fflush(stdin);
scanf("%c",&op);
switch(op)
{
case '@': e=(x+y)/2.0;
printf("%g %c %g=%g",x,op,y,e);
break;
case '$': e=sqrt(x*x+y*y);
printf("%g %c %g=%g",x,op,y,e);
break;
case '#': e=log(fabs(x+y));
printf("%g %c %g=%g",x,op,y,e);
break;
default: printf("\nOperatie necunoscuta");
}
return 0;
}
vector clasic
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#define N 100
int main()
{
int i,n,j,nr,pmax,pmin,max,min,k;
double v[N],p[N],s,ma;
printf("Introduceti dimensiunea vectorului (n<%d):\n",N);
if(scanf("%d",&n)!=1||n<1||n>N)
{
printf("Date eronate");
exit(1);
}
printf("Introduceti %d elemente reale:\n",n);
for(i=0;i<n;i++)
{
printf("v[%2d]=",i);
if(scanf("%lf",&v[i])!=1)
{
printf("Date eronate");
exit(1);
}
}
printf("Vectorul introdus este:\n");
for(i=0;i<n;i++)
{
printf("%g\t",v[i]);
}
printf("\nIntroduceti nr nat:\n");
if(scanf("%d",&nr)!=1)
{
printf("Date eronate");
exit(1);
}
max=min=v[0];
pmax=pmin=0;
//produsul elementelor
printf("Produsul este:\n");
for(i=0;i<n;i++)
{
p[i]=nr*v[i];
printf("%g\t",p[i]);
}

//elem.max
for(i=0;i<n;i++)
{
if(max<v[i])
{
max=v[i];
pmax=i;
}
}
printf("\nMax este %d\n",max);
//elem.min
for(i=0;i<n;i++)
{
if(min>v[i])
{
min=v[i];
pmin=i;
}
}
printf("\nMin este %d\n",min);
//media aritmetica
ma=0;
s=0.0;
k=0.0;
for(i=0;i<n;i++)
{
if(fmod(v[i],2)==0)
{
k++;
s=s+v[i];
}
}
ma= s/k;
printf("Media este :%g\n",ma);
return 0;
}
cron