Sunteți pe pagina 1din 49

2 la puterea n

#include <stdio.h>
void main(void)
{
int i,p=1;
int n;
printf("n= ");
scanf("%d",&n);
for (i=1;i<=n;i++)
p=p*2;
if (n==0)
printf("2 la puterea 0 este 1\n");
else
printf("2 la puterea %d este %d\n",n,p);
}

Afisare linii matrice


#include <stdio.h>
#include<conio.h>
main()
{int a[10][10],i,j,n,m;
printf("n=");scanf("%d",&n);
printf("m=");scanf("%d",&m);
for(i=1;i<=n;i++)
{for(j=1;j<=m;j++)
{printf("a[%d][%d]=",i,j);scanf("%d",&a[i][j]);}
}
for(i=1;i<=n;i++)
{printf("linia %d este",i);
for(j=1;j<=m;j++)
printf("%d ",a[i][j]);
printf("\n");
}
}

Afisare numere Fibonacci mai mici decat N


#include<stdio.h>
main()
{int n,a=1,b=1,c;
printf("n=");scanf("%d",&n);
printf("%d ",a);
do {printf("%d ",b);
c=a+b;
a=b;
b=c;} while(c<n);
}

Afiseaza urmatoarea cifra dupa n


#include<stdio.h>

void main(void)
{int i,j,n;
printf("introduceti valoarea lui n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=i; j++);
printf("Urmatoarea dupa %d este %d\n",n,j);
}

Afiseaza secventa 1 12 123 1234


#include<stdio.h>
void main(void)
{
int n,i,j;
printf("Introduceti valoarea lui n:");
scanf("%i",&n);
for(i=2;i<=n;i++)
for(j=1;j<=i;j++) printf("%d",j);
}
Calculeaza aria triunghiului
#include<stdio.h>
#include<math.h>

void main(void)
{
float a,b,c,p,aria;
printf("introduceti laturile triunghiului:");
scanf("%f %f %f", &a, &b, &c);
p=(a+b+c)/2;
aria=sqrt(p*(p-a)*(p-b)*(p-c));
printf("aria triunghiului este %f\n",aria);
}

Converteste un numar in baza 10 intr-un numar in


baza 16
#include <stdio.h>
void main(void)
{int i,n10, indice16=0,rest16;
char n16[6];
printf("numarul in baza 10:");scanf("%d",&n10);
while (n10)

{ rest16=n10%16;
if (rest16<10) n16[indice16]=rest16+'0';
else n16[indice16]=rest16-10+'A';
indice16++;
n10=n10/16;

for (i=indice16-1;i>=0;i--)
printf("%c",n16[i]);
putchar('\n');
}
Converteste un numar in baza 16 intr-un numar in
baza 10

#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
void main(void)
{
int n10=0, i, inmultitor=1;
char n16[17];
printf("Introduceti numarul in baza 16: ");
scanf("%s",n16);
for (i=strlen(n16)-1; i>=0;i--)
{
if ((n16[i]>='0')&&(n16[i]<='9'))
n10+=(n16[i]-'0')*inmultitor;

else
if ((n16[i]>='A')&&(n16[i]<='F'))
n10+=(n16[i]-'A'+10)*inmultitor;
else
{
printf("Sirul citit nu e un numar in baza 16\n");
exit(1);
}
inmultitor*=16;
}
printf("Numarul in baza 10 este: %d\n",n10);
}

Converteste un numar din baza p in baza q


#include<stdio.h>
#include<conio.h>
void main(void)
{
int np, p ,q, putere=1, n10=0, uc,nq=0,rest;
printf("Dati baza p: ");
scanf("%d",&p);
printf("Dati baza q: ");
scanf("%d",&q);
printf("Dati numarul in baza p: ");
scanf("%d",&np);

while(np)
{
uc=np-(np/10)*10;
n10=n10+uc*putere;
putere=putere*p;
np=(np/10);
}
putere=1;
while(n10)
{
rest=n10-(n10/q)*q;
nq=nq+rest*putere;
putere=putere*10;
n10=(n10/q);
}
printf("Numarul in baza q este: %d\n",nq);
getch();
}

Converteste din Baza zece in baza 2


#include<stdio.h>
void main(void)
{
int i,n10,indice2=0,rest2;
char n2[30];
printf("Introduceti numarul in baz 10:"); scanf("%d",&n10);
while(n10)
{
rest2=n10%2;
if(rest2<2) n2[indice2]=rest2+'0';
indice2++;
n10/=2;
}
for(i=indice2-1;i>=0;i--) printf("%c",n2[i]);
printf("\n");
}

Converteste din baza 2 in baza 10


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main(void)
{
int n10=0,inmultitor=1,i;
char n2[30];
printf("Introduceti un numar in baza 2: "); gets(n2); //gets se
foloseste pentru a citi un sir de caractere.E acelas lucru cu scanf("%s",n16)
for(i=strlen(n2)-1;i>=0;i--)
{
if((n2[i]>='0')&&(n2[i]<='1')) n10+=(n2[i]-'0')*inmultitor;
else
{
printf("Acest numar nu este in baza 2.Folositi numai 0
si 1");
exit(1);
}
inmultitor*=2;
}
printf("Numarul in baza 10 este: %d\n",n10);
}

Cel mai mic divizor comun


#include<stdio.h>
int a,b,d,i,r;
void main(void)
{
printf("Introduceti valorea nr a=");
scanf("%i", &a);
printf("Introduceti valoarea nr b=");
scanf("%i", &b);
d=a;
i=b;
while(i!=0)
{r=d%i;
d=i;
i=r;
}
printf("...........\n");
printf("C.M.M.D.C (%ld,%ld)=%ld\n",a,b,d);
}

Cate cifre contine un numar n dat de la


tastatura
#include<stdio.h>
void main(void)
{
int i,n,nrcifre=0,a[10],uc;
printf("Introduceti valoarea lui n:");
scanf("%i", &n);
for(i=0;i<=9;i++) a[i]=0;
while(n!=0)
{uc=n%10;
a[uc]=1;
n/=10;
}
for(i=0;i<=9;i++) nrcifre+=a[i];
printf("Numarul contine %d cifre\n",nrcifre);
}

Cate cifre contine un sir


#include <stdio.h>
#include <ctype.h>

void main (void)


{
char sir[80], nr_cifre=0,*p;
printf("introduceti sirul:");
gets(sir);
p=sir;
for(;*p;p++)
{
if (!isdigit(*p)) continue;
nr_cifre++;
}
printf("numarul de cifre din sir este %d\n",nr_cifre);
}

Cate cifre distincte are N


#include<stdio.h>
main()
{int v[10],i,n,c,nr=0;
for(i=0;i<=9;i++)
v[i]=0;
printf("n=");scanf("%d",&n);
while(n!=0) {c=n%10;
v[c+1]++;
n=n/10;}
for(i=0;i<=9;i++)
if(v[i]==1) nr++;
printf("%d cifre distincte",nr);
}
Cate cuvinte sunt intr-o propozitie care se
termina la introducerea $
#include<stdio.h>
main()
{char a[10],c; int i=-1,nr=0,j;
do {scanf("%c",&c);
if(c!='$') {i++;
a[i]=c;
}
}while(c!='$');
for(j=0;j<=i;j++)
if((a[j]==' ')||(a[j]==',')) nr++;
printf("sunt %d cuvinte",nr);
}

Cate numere Fibonacci mai mici decat N


#include<stdio.h>
main()
{int n,a=1,b=1,c,nr=1;
printf("n=");scanf("%d",&n);
do {nr++;
c=a+b;
a=b;
b=c;} while(c<n);
printf("sunt %d nr fibonacci mai mici decat %d",nr,n);
}

Cate numere prime mai mici decat N


#include<stdio.h>
int prim(int x)
{int j,prim=1;
if(x==1) prim=0;
for(j=2;j<=x/2;j++)
if(x%j==0) prim=0;
return prim;
}
main()
{int n,i,nr=0;
printf("n=");scanf("%d",&n);
for(i=2;i<n;i++)
if(prim(i)==1) nr++;
printf("sunt %d nr prime mai mici decat %d",nr,n);
}

Cifrele comune a 2 nr
#include <stdio.h>
main()
{int n,i=-1,gasit,a[10],p,k,j=-1,b[10],m;
printf("n=");scanf("%d",&n);
printf("m=");scanf("%d",&m);
while(n!=0) {i++;
a[i]=n%10;
n=n/10;}
while(m!=0) {j++;
b[j]=m%10;
m=m/10;}
for(k=0;k<=i;k++) {gasit=0;
for(p=0;p<=j;p++)
if(a[k]==b[p]) gasit=1;
if(gasit==1)printf("%d",a[k]);
}
}

Citire numere si ordonare crescatoare


# include <stdio.h>
int main()
{
int a[100],i,j,n,aux;
printf("n=");scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("a[%d]= ",i);scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
for (j=i+1;j<n;j++)
if (a[i]>a[j])
{
aux=a[i];
a[i]=a[j];
a[j]=aux;
}
printf("sirul ordonat cresc e:");
for (i=0;i<n;i++)
{
printf("%d ",a[i]);

}
printf("\n");
return 0;
}

Citire siruri si ordonare crescatoare


# include <stdio.h>
#include<string.h>
int main()
{
char a[20][100], cuv[100];
int i,j,n,aux;
printf("Numarul de siruri este:");scanf("%d",&n);
gets(a[0]);
for(i=0; i<n; i++)
{
printf("a[%d]= ",i);gets(a[i]);
}

for(i=0;i<n;i++)
for (j=i+1;j<n;j++)
if (strcmp(a[i], a[j]) == 1)
{

strcpy(cuv,a[i]);
strcpy(a[i], a[j]);
strcpy(a[j], cuv);

}
printf("sirul ordonat cresc e:");
for (i=0;i<n;i++)
{
printf("%s ",a[i]);

}
printf("\n");
return 0;
}
Cel mai mic divizor comun & cel mai mic multiplu
comun
#include<stdio.h>
int cmmdc(int a,int b)

{
if(a>b)
return cmmdc(a-b,b);
else
if(b>a)
return cmmdc(a,b-a);
else return a;
}
main()
{
int a,b;
printf("a=");
scanf("%d",&a);
printf("b=");
scanf("%d",&b);
printf("cmmdc=%d",cmmdc(a,b));
printf("cmmmc=%d",a*b/cmmdc(a,b));
}}

Cel mai mic divizor comun Euclid


#include <stdio.h>
int euclid(int a, int b)
{int c;
while (b!=0) {c=a%b;
a=b;
b=c;}
return a;
}
main()
{int a,b;
printf("a=");scanf("%d",&a);
printf("b=");scanf("%d",&b);
printf("cmmdc=%d",euclid(a,b));
}
Cel mai mic multimplu comun si cel mai mare
divizor comun a doua numere

#include <stdio.h>
#include<conio.h>
void main(void)
{
int a,b,r,c,x,y;
printf("Dati cele doua numere: ");
scanf("%d %d",&a,&b);
x=a;
y=b;
while(b)
{
r=a % b;
a=b;
b=r;
}
printf("cmmdc= %d\n",a);
c=x*y/a;
printf("cmmmc= %d",c);
putchar('\n');
}

Compararea a doua numere

#include <stdio.h>

void main(void)
{ int a,b;
printf("introduceti primul numar:");
scanf("%d",&a);
printf("introduceti al doilea numar:");
scanf("%d",&b);
printf("maximul dintre cele doua numere este %d:", a>b?a:b);
}
concatenare sir
#include<stdio.h>
void main(void)
{
int m,n,i,j,k,a[21],b[21],c[40];
printf("Introduceti dimensiunea I sir: "); scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("a[%d]= ",i); scanf("%d",a+i); //a+i este acelas lucru
cu &
}
printf("Introduceti elementele sirului II: "); scanf("%d",&m);
for(j=0;j<m;j++)
{
printf("b[%d]= ",j); scanf("%d",b+j);
}
a[n]=b[m-1]+1;
b[m]=a[n-1]+1;
for(i=0,j=0,k=0;k<m+n;k++)
if(a[i]<=b[j])
c[k]=a[i++];
else
c[k]=b[j++];
printf("Sirul concatenat este: ");
for(k=0;k<m+n;k++)
printf("%d ",c[k]);
}

Convertire din hexadecimal in binar


#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

#define FirstDigit 48

void BinToHex(char* BinData, char* HexData)


{
long int Number = 0;
int BinLength = strlen(BinData);

for(int i=0; i<BinLength; i++)


{
Number += ((BinData[BinLength - i - 1] - FirstDigit) * pow(2, i));
}

ltoa(Number, HexData, 16);


}

int main()
{
char* BinBuffer = "11110101";
char HexBuffer[256];

BinToHex(BinBuffer, HexBuffer);
printf("Bin: %s\nHex: %s", BinBuffer, HexBuffer);
getch();
return 0;
}

Convertire numar in baza 16

#include<stdio.h>
void main(void)
{
int i,n10,indice16=0, rest16;
char n16[17];
scanf("%d",&n10);
while(n10)
{
rest16=n10%16;
if(rest16<10) n16[indice16]=rest16+'0';
else
n16[indice16]=rest16-10+'A';
indice16++;
n10/=16;
}
for(i=indice16-1;i>=0;i--) printf("%c",n16[i]);
putchar('\n');
}
Se determina daca trei numere a, b, c
reale pot reprezenta laturile unui triunghi si
sa se calculeze aria sa.
#include<stdio.h>
#include<math.h>
float a, b, c, s, p;

int validare_laturi(float a, float b, float c)


{
return((a>0)&&(b>0)&&(c>0)&&(a+b>c)&&(a+c>b)&&(b+c>a));
}
void main(void)
{
printf("Introduceti laturile triunghiului: ");
scanf("%f %f %f", &a, &b, &c);
if (validare_laturi(a,b,c))
{
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
printf("Aria este %6.2f\n",s);
}
}

Verifica daca numarul e divizibil cu diferenta dintre


cifra maxima si cea minima

#include<stdio.h>
#include<conio.h>
void main(void)
{
int n, s, max=0, min=9, ultcifra, dif;
printf("Dati n: ");
scanf("%d",&n);
s=n;
do
{
ultcifra=s%10;
s/=10;
if(ultcifra>max) max=ultcifra;
if(ultcifra<min) min=ultcifra;
}
while(s);

dif=max-min;

printf("Diferenta dintre maximul %d si minimul %d este: %d\n",max,min,dif);


if((n%dif)==0)
printf("Numarul este divizibil cu diferenta si este egala cu %d\n",n/dif);
else
printf("Numarul nu este divizibil cu diferenta!\n");
getch();
}

Daca un nr este prim sau nu


#include<stdio.h>
void main(void)
{
int n,d,prim;
printf("Introduceti val lui n:");
scanf("%i",&n);
prim=1;
for(d=2;d<=n/2;d++)
if(n%d==0) prim=0;
if(prim==1)
printf("Numarul este prim\n");
else
printf("Numarul nu este prim \n");
}

De cate ori apar cifrele 0-9 intr-un nr


#include<stdio.h>
void main(void)
{
long int n,i,a[10],r;
printf("Introduceti valoarea lui n:");
scanf("%d",&n);
for(i=0;i<=9;i++) a[i]=0;
while(n!=0)
{r=n%10;
a[r]=a[r]+1;
n=n/10;
}
for(i=0;i<=9;i++)
printf("Numarul %d apare de %d\n",i,a[i]);

}
De cate ori apare un caracter intr-o prop
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
void main(void)
{

char s[256],c;
int i,j,l;
j=0;
int strlen(char s[]);

printf("Introduceti sirul: ");


gets(s);
printf("Introduceti sirul cautat: ");
c=getchar();
l=strlen(s);
for (i=1;i<=l;i++)
if(s[i-1]==c)j++;
printf("Caracterul %c a fost gasit in sir de %d ori.\n",c,j);
}
int strlen(char s[])
{
int n;
for(n=0; s[n]; n++);
return n;
}

De cate ori apare un caracter citit intr-un sir


de caractere
#include<stdio.h>
#include<string.h>
void main(void)
{
char s[256],c;
int i,j=0;
printf("Introduceti sirul:");
gets(s);
printf("Introduceti caracterul cautat:");
c=getchar();
for(i=1;i<=strlen(s);i++)
if(s[i-1]==c) j++;
printf("Caracterul %c a fost gasit de %d ori \n",c,j);
}
De cate ori apare o cifra citita intr-un nr
#include<stdio.h>
void main(void)
{int n,k,a,r;
printf("Numarul este=");
scanf("%i",&n);
printf("Cifra cautata este=");
scanf("%i", &a);
k=0;
do
{r=n%10;
if(r==a) k++;
n=n/10;
}
while(n!=0); printf("Numarul %d apare de %d ori \n",a,k);
}

Derivata de ordinul K in punctul V al unui


polinom N
#include<stdio.h>
main()
{int n,k,v,derivata,a[10],i,val=0,putere=1;
printf("n=");scanf("%d",&n);
for(i=0;i<=n;i++)
{printf("a[%d]=",i);scanf("%d",&a[i]);}
printf("k=");scanf("%d",&k);
printf("v=");scanf("%d",&v);
for(derivata=1;derivata<=k;derivata++)
{for(i=0;i<=n;i++)
a[i]=a[i]*(n-i);
n--;
}
for(i=0;i<=n;i++)
printf("%d ",a[i]);
printf("\n");
for(i=n;i>=0;i--)
{val=val+(a[i]*putere);
putere=putere*v;
}
printf("valoarea polinomului=%d",val);
}
Afiseaza derivatele de ordinul k al polinomului

#include<stdio.h>
#include<conio.h>
void main(void)
{
int n, a[20],i,k,der=1;
printf("Dati gradul polinomului: "); scanf("%d",&n);
printf("Dati coeficientii polinomului: ");
for (i=0;i<=n;i++)
{
printf("a[%d]=",i);
scanf("%d",a+i);
}
printf("Dati ordinul derivatei: ");
scanf("%d",&k);

do
{
i=0;
do
{
a[i]=a[i]*(n-i);
i++;
}
while(i<n);
n--;
printf("Derivata de ordinul %d este: \n",der);
for (i=0;i<=n;i++)

printf("a[%d]=%d ",i,a[i]);

der++;
putchar('\n');
}
while(der<=k);
}

Descompunere numar in factori primi


#include<stdio.h>
#include<conio.h>
void main(void)
{int n,d=2,p;
printf("Introduceti nr:");
scanf("%i",&n);
do
{p=0;
while(!(n%d)) p++,n/=d;
if(p) printf("Div %d cu puterea %d \n",d,p);
d++;
}
while(n!=1);
getchar();
}

Determina daca un an este bisect sau nu

#include<stdio.h>
#include<conio.h>

void main(void)
{
int n;
printf("Dati anul: ");
scanf("%d",&n);

if((!(n%100))&&(!(n%400)))
printf("Anul este bisect! \n");
else
if(!(n%4))
printf("Anul este bisect! \n");
else
printf("Anul nu este bisect! \n");
getch();
}

Rezolvarea ecuatiei de gradul 1


#include<stdio.h>
#include<conio.h>
void main()
{float a,b;
printf("Introduceti coeficientul a=");
scanf("%f",&a);
printf("Introduceti coeficientul b=");
scanf("%f",&b);
if(!a)
if(!b) printf("Ecuatie nedeterminata!\n");
else printf("Ecuatie imposibila!\n");
else printf("Ecuatie de gr 1 cu solutia %f\n",-b/a);
getch();
}

Rezolvarea ecuatiei de gradul 2


#include<conio.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
void main (void)
{float a,b,c,x,re,im,d;
printf("Introduceti coeficientul a=");
scanf("%f",&a);
printf("Introduceti coeficientul b=");
scanf("%f",&b);
printf("Introduceti coeficientul c=");
scanf("%f",&c);
if(!a)
if(!b)
if(!c)
printf("Ecuatie nedeterminata!\n");
else printf("Ecuatie imposibila!\n");
else printf("Ecuatie de gradul 1 cu solutia x=%f\n",-c/b);
else
{d=b*b-4*a*c;
if(d>0) printf("Ecuatie cu solutii distincte x1=%f, x2=%f\n",(-b-
sqrt(d))/(2*a),(-b+sqrt(d))/(2*a));
else
if(!d) printf("Ecuatie cu solutie dubla x1=x2=%f\n",-b/(2*a));
else
{re=-b/(2*a);
im=sqrt(-d)/(2*a);
printf("Ecuatie cu solutii imaginare x1=%f+i*%f,x2=%f-
i*%f\n",re,im,re,im);
}
}
getch();
}

Elimina duplicatele dintr-un sir

#include<stdio.h>
void sortare(int a[], int n)
{
int i, j, elem;
{ for (i=0; i<=n-1; i++) for (j=i+1; j<n; j++) if (a[i]>a[j]) { elem=a[i];
a[i]=a[j];
a[j]=elem; } }
}
void main(void)
{
int n, a[20], i;
printf("Introdu dimensiunea sirului: ");
scanf("%d",&n);
printf("Introdu elem sirului: \n");
for(i=0; i<n; i++) { printf("a[%d]= ",i);
scanf("%d",a+i); }
sortare(a,n);
printf(" %d",a[0]);
for (i=1; i<n; i++) { if(a[i]!=a[i-1]) printf(" %d",a[i]); }
}

Genereaza toate numerele perfecte mai mici ca n


#include<stdio.h>
#include<conio.h>

int suma_divizori (int n)


{
int suma=0, i;
for (i=1;i<n; i++)
if (!(n%i)) suma+=i;
return (suma);
}
void main(void)
{
int n;

printf("Dati n: ");
scanf("%d",&n);

if(n==suma_divizori(n))
printf(" Numarul este perfect. ");
else
printf(" Numarul nu este perfect. ");
putchar('\n');

}
exercitare functie nr de elemente dintrun sir
pointer
#include<stdio.h>
int strlen(char*a)
{
char*p;
p=a;
while(*p)p++;
return(p-a);
}
void main(void)
{
char a[30];
printf("introduceti sirul:"); scanf("%s",a);
printf("\n Lungimea sirului este:");
printf("%d\n",strlen(a));
}

Fibonacci fara sir

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

void main()
{int n,f1,f2,f3;

printf("Introd n: ");
scanf("%d",&n);

printf("Sirul Fibonacci este:\n");

f1=1;
f2=1;
printf("%d ",f1);
printf("%d ",f2);
do
{

f3=f2+f1;
f1=f2;
f2=f3;
if(f3>n) exit(1);
printf("%d ",f2);
}
while(f3<=n);
getch();
}
Generare secventa 1223334444
#include<stdio.h>
void main(void)
{
int n,i,j;
printf("Introduceti valoarea lui n:");
scanf("%i",&n);
for(i=1;i<=n;i++)
{for(j=1;j<=i;j++)
printf("%d",i);
}
}

Genereaza sirul primelor n nr prime

#include<stdio.h>
#include<math.h>
#include<conio.h>

int daca_prim(int n)
{
int d=2;

do
{
if((!(n%d))&&(n!=2))
{
return(0);
d=n;
}
d++;
}

while (d<=(sqrt(n)+1));

}
void main()
{
int n, i;
printf("Introduceti val lui n: ");
scanf("%d",&n);
printf("Primele %d numere prime sunt: ",n);
for(i=0;i<=n;i++)
{
if (daca_prim(i))
printf("%d ",i);

} putchar('\n');}
Conjectura lui Goldbach

#include<stdio.h>
#include<math.h>
#include<conio.h>

int daca_prim(int n)
{
int d=2;

do
{
if((!(n%d))&&(n!=2))
{
return(0);
d=n;
}
d++;
}

while (d<=(sqrt(n)+1));

}
void main()
{
int n, i,a,b,s;
printf("Introduceti val lui n: ");
scanf("%d",&n);
if(!(n%2))
{
s=n;
for(i=0;n;i++)
{ a=n-1;
b=s-a;
n-=1;
if((daca_prim(a))&&(daca_prim(b)))
printf("Numerele %d si %d sunt prime, iar adunate dau %d. \n",a,b,s);
}

for(i=0;i<=n;i++)
{
if (daca_prim(i))
printf("%d ",i);

}
}
else
printf("Conjectura lui Goldbach este respectata doar in cazul numerelor
pare!");
putchar('\n');
}
Imparte suma in bancnote si monede
#include <stdio.h>

int main()
{
int n, suma, p;
int b[100], i;

printf("n="); scanf("%d", &n);

for(i=0; i<n; i++)


{
printf("b[i]=", i); scanf("%d", &b[i]);
}
printf("Introduceti suma de bani:"); scanf("%d", &suma);
for(i=0; i<n; i++)
{
p=suma/b[i];
suma=suma%b[i];
printf("suma are %d bancnote de %d lei\n", p, b[i]);
}

return 0;

Inserare intr-un sir ordonat


#include <stdio.h>
main()
{int a[10],i,n,nr,j;
printf("n=");scanf("%d",&n);
for(i=0;i<n;i++)
{printf("a[%d]=",i);scanf("%d",&a[i]);}
printf("nr=");scanf("%d",&nr);
i=0;
while ((nr>a[i])&&(i<n)) i++;
if(i<n) {for(j=n-1;j>=i;j--)
a[j+1]=a[j];
a[i]=nr;
}
else a[n]=nr;
for(i=0;i<=n;i++)
printf("%d ",a[i]);
}
Interclasare medie aritmetica la fiecare 2 nr
#include <stdio.h>
main()
{int i,j=-1,n; float a[50],b[100];
printf("n="); scanf("%d",&n);
for(i=0;i<n;i++)
{printf("a[%d]=",i); scanf("%f",&a[i]);}
for(i=0;i<n-1;i++)
{j++;
b[j]=a[i];
j++;
b[j]=(a[i]+a[i+1])/2;}
j++;
b[j]=a[n-1];
for(i=0;i<=j;i++)
printf("%.2f ",b[i]);
}

Se citesc doua siruri de numere intregi, direct


ordonate crescator.
Sa se scrie programul pentru intercalasarea
celor doua siruri, astfel incat
sa se obtina un al treilea sir direct ordonat
crescator.
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a[20], b[20], c[40], m, n, i, j, k;
printf("Introd lungimea primului sir: ");
scanf("%d",&n);
printf("Introd lungimea celui de-al doilea sir: ");
scanf("%d",&m);

printf("Introduceti elementele primului sir: \n");


for (i=0; i<n; i++)
{
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
printf("Introduceti elementele celui de-al doilea sir: \n");
for (j=0;j<m;j++)
{
printf("b[%d]=",j);
scanf("%d",&b[j]);
}
a[n]=b[m-1]+1;
b[m]=a[n-1]+1;
i=0; j=0;
for(k=0;k<n+m;k++)
if(a[i]<=b[j]) c[k]=a[i], i++;
else c[k]=b[j], j++;
printf("Elementele sirului interclasat sunt: \n");
for(k=0; k<m+n;k++) printf("%d",c[k]);
putchar('\n');
getch();
}

INVERSA UNEI MATRICI


# include <stdio.h>
# include <conio.h>
int n;
float a[10][20];
void extindere_matr(void)
{
int i,j;
for(i=1;i<=n;i++)
for(j=n+1;j<=2*n;j++)
if(i+n==j)
a[i][j]=1;
else a[i][j]=0;
}
int cauta_pivot(int i)
{
int j;
for(j=i+1;j<=n;j++)
if(!a[i][j])
return(j);
return (0);
}
void schimba_linii(int i,int k)
{
int j;
float tmp;
for(j=i;j<=2*n;j++)
{
tmp=a[k][j];
a[k][j]=a[i][j];
a[i][j]=tmp;
}
}
Joc copii

#include<stdio.h>
#include<conio.h>

void main(void)
{
int n,x,i,v[20];
printf("Dati numarul de copii: ");
scanf("%d",&n);

printf("Dati x: ");
scanf("%d",&x);

for(i=1;i<=n;i++) v[i]=i;
for(i=1;i<=n;i++) printf("a[%d]=%d ",i,v[i]);
putchar('\n');
do
{
for(i=1;i<=n;i++)
{
if(x==i)
{ v[x]=v[x+1];
v[n]=0;}}
for(i=1;i<=n;i++) printf("a[%d]=%d ",i,v[i]);
x--;
printf("Copilul %d a fost eliminat. \n",x);
}
while(x);
}

Maxim triunghiul deasupra diagonalei matrice


#include <stdio.h>
#include <conio.h >
int a[10][10],i,j,m,max;
void main()
{
clrscr();
printf("dati m"); scanf("%d",&m);
for (i=0;i<m;i++)
for (j=0;j<m;j++)
{
printf("\n dati a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
max=a[0][1];
for (i=0;i<(m-1)/2;i++)
for (j=i+1;j<m-1-i;j++)
if (a[i][j]>max) max=a[i][j];
printf("maximul este= %d",max);
getch();
}

Minimul elementelor de pe coloana unei matrici


#include <stdio.h>
void main(void)
{
int i,j,n,a[20][20],s=0,min;
printf("Introduceti numarul de linii:\n");
scanf("%d",&n);
printf("Introduceti numarul de coloane:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
min=32000;
for(j=0;j<n;j++)
{
printf("a[%d][%d]=\n",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=0;i<n;i++)
{
min=32000;
for(j=0;j<n;j++)
{
if(min>a[j][i]) min=a[j][i];
}
s=s+min;
}
printf("suma minimelor de pe fiecare coloana este:%d",s);
scanf("%d",&n);
}

Monede si banknote
#include<stdio.h>
main()
{int s,i,k,a[7]={1,5,10,50,100,500,1000};
printf("s=");scanf("%d",&s);
for(i=6;i>=0;i--)
{k=s/a[i];
if(k!=0) printf("diviziunea %d cu %d aparitii\n",a[i],k);
s=s%a[i];
if(s==0) break;
}
}
Calculeaza n factorial
#include<stdio.h>

int factorial(int n)
{ int i,fact=1;
for(i=2;i<=n;i++) fact=fact*i;
return(fact);
}
void main(void)
{ int v;
printf("3!=%d\n",factorial(3));
printf("introd o valoare:");
scanf("%d",&v);
printf("%d!=%d\n",v,factorial(v));
}

Numar aparitie cifra c in n


#include <stdio.h>
void main(void)
{
int n,cifra,nraparitii=0;
printf("Introduceti numarul: ");
scanf("%d",&n);
printf("Introduceti cifra pe care o cautati: ");
scanf("%d",&cifra);
do
{
if(n%10==cifra) nraparitii++;
n=n/10;
}while(n>0);

printf("Cifra %d apare in numar de %d ori.",cifra,nraparitii);


}

Determina numarul de aparitii al fiecarei litere


mici sau mari intr-un sir de caractere
#include<stdio.h>
#include<ctype.h>
void main (void)
{
int a[26],i;
char ch;
for(i=0;i<26;a[i++]=0);
while((ch=getchar())!='\n')
if(isalpha(ch)) a[toupper(ch)-'A']++;
for(i=0;i<26;i++)
if(a[i])
printf("Literele %c si %c apar de%d ori \n",i+'a',i+'A',a[i]);
}

Numaram consoanele si vocalele dintr-o


propozitie

# include <stdio.h>
# include <string.h>
int main()
{
int c,v,i;
char sir[30];

printf("introd sirul "); gets(sir);


v=0;c=0;
for (i=0; sir[i]; i++)
if ((sir[i]>='a' && sir [i]<='z') || (sir[i]>='A' &&
sir[i]<='Z'))
{
if (sir[i]=='a'|| sir[i]=='e'||
sir[i]=='i'||sir[i]=='o'||
sir[i]=='u'||sir[i]=='A'||
sir[i]=='E'||sir[i]=='I'||
sir[i]=='O'||sir[i]=='U')
{
v++;
}
else
{
c++;
}
}
printf("sirul contine %d vocale si %d consoane\n", v,c);

return 0;
}

Nr de palindroame intr-un sir


#include <stdio.h>
int rasturnat(int x)
{int c,rast=0;
while(x!=0) {c=x%10;
rast=rast*10+c;
x=x/10;}
return rast;
}
main()
{int n,i,a[10];
printf("n=");scanf("%d",&n);
for(i=0;i<n;i++)
{printf("a[%d]=",i);scanf("%d",&a[i]);}
for(i=0;i<n;i++)
if(a[i]==rasturnat(a[i])) printf("%d ",a[i]);
}

Numar maxim utilizand cifrele lui N


#include<stdio.h>
main()
{int v[10],i,j,n,c,nr=0;
for(i=0;i<=9;i++)
v[i]=0;
printf("n=");scanf("%d",&n);
while(n!=0) {c=n%10;
v[c]++;
n=n/10;}
for(i=9;i>=0;i--)
if(v[i]!=0) for(j=1;j<=v[i];j++)
printf("%d",i);
}

Numar de divizori pari


#include<stdio.h>
#include<conio.h>
int pari(int n, int i)
{
if(i>n) return 0;
else if((n%i==0)&&(i%2==0)) { printf("divizor par: %d\n",i);
return 1 + pari(n,i+1); }
else return pari(n,i+1);
}
void main(void)
{
int n;
clrscr();
printf("dati nr: ");
scanf("%d",&n);
printf("numarul de divizori pari a lui %d este %d ",n,pari(n,1));
}
Numar de divizori proprii
#include<stdio.h>
#include<conio.h>
int nr_prop(int n, int i)
{
if (i>=n) return 0;
else if (n%i==0) return 1 + nr_prop(n,i+1);
else return nr_prop(n,i+1);
}
void main(void)
{
int n;
clrscr();
printf("dati nr: ");
scanf("%d",&n);
printf("numarul de divizori proprii a lui %d este %d",n,nr_prop(n,2));
}

Numar divizibil cu 3
#include<stdio.h>
#include<conio.h>
int divi3(int n)
{
if (n==0) return 1;
else if (n%3==0) return n%10 * divi3(n/10);
else return divi3(n/10);
}
void main(void)
{
clrscr();
int n;
printf("dati nr: ");
scanf("%d",&n);
printf("%d",divi3(n));
}

Daca numarul e palindrom simplu


#include<stdio.h>
#include<conio.h>
void main (void)
{
int copie,oglindit,c,n;
oglindit=0;
printf("Introduceti valoarea lui n:");
scanf("%d", &n);
copie=n;
while(n!=0)
{
c=n%10;
oglindit=oglindit*10+c;
n=n/10;
}
if(copie==oglindit)
printf("numarul este palindrom");
else
printf ("numarul nu este palindrom");
getch();
}

Numara caracterele din doua siruri


#include<stdio.h>
#include<string.h>

void main(void)
{ char a[256], b[256];
int i,j,nr,l,m,c,d;
printf("introduceti primul sir:"); gets(a);
printf("introduceti al doilea sir:"); gets(b);
l=strlen(a);
m=strlen(b);
c=0;
d=0;
nr=0;
for (i=1;i<=l;i++) c++;
for (j=1;j<=m;j++) d++;
nr=c+d;
printf("nr de caractere din cele doua siruri este: %d\n",nr);
}

Ordonare sir(vector)
#include<stdio.h>
main()
{int a[10],n,i,aux,j;
printf("n="); scanf("%d",&n);
for(i=0;i<n;i++)
{printf("a[%d]=",i); scanf("%d",&a[i]);}
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j]) {aux=a[i];
a[i]=a[j];
a[j]=aux;}
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
Verifica daca un numar e palindrom sau nu

#include<stdio.h>
#include<conio.h>
void main(void)
{
int n, multiplicator=1, nrc,s,i,ult,a,b=0;

printf("Dati n: ");
scanf("%d",&n);
s=a=n;
for (nrc=0; n;nrc++) n/=10;

for(i=1;i<nrc;i++) multiplicator*=10;
for(i=0;i<nrc;i++)
{
ult=s%10;
b+=ult*multiplicator;
s/=10;
multiplicator/=10;
}
if(a==b)
printf("Numarul este palindrom!\n");
else
printf("Numarul nu este palindrom!\n");
getchar();
}

Palindrom
#include<stdio.h>
int rasturnat(int x)
{int r=0,c;
while(x>0) {c=x%10;
r=r*10+c;
x=x/10;}
return r;
}
main()
{int n;
printf("n=");scanf("%d",&n);
if(n==rasturnat(n)) printf("palindrom");
else printf("nu e palindrom");
}

Primele N numere Fibonacci


#include<stdio.h>
main()
{int n,a=1,b=1,c,nr=1;
printf("n=");scanf("%d",&n);
printf("%d ",a);
do {printf("%d ",b);
nr++;
c=a+b;
a=b;
b=c;} while(nr<n);
}

Primele N numere prime


#include<stdio.h>
int prim(int x)
{int j,prim=1;
if(x==1) prim=0;
for(j=2;j<=x/2;j++)
if(x%j==0) prim=0;
return prim;
}
main()
{int n,i=2,nr=1;
printf("n=");scanf("%d",&n);
while(nr<=n) {if(prim(i)==1) {printf("%d ",i);
nr++;}
i=i++;}
}

Primul nr perfect dintr-un sir


#include <stdio.h>
int sumadiv(int x)
{int s=0,i;
for(i=1;i<x;i++)
if(x%i==0)s=s+i;
return s;
}
main()
{int i=1,ok=0;
while(ok==0)
if(sumadiv(i)==i) {printf("%d",i);
ok=1;}
else i++;
}

polinom. produs a 2 polinoame


#include <stdio.h>
main()
{
int m,n,a[20],b[20],p[40],i,j;
printf("Dati gradul primului polinom:");
scanf("%d",&m);
printf("Dati gradul celui de-al doilea polinom:");
scanf("%d",&n);
printf("Dati coeficientii:\n");
for(i=m;i>=0;i--)
{printf("a[%d]=",i);
scanf("%d",&a[i]);}
for(j=n;j>=0;j--)
{printf("b[%d]=",j);
scanf("%d",&b[j]);}
for(i=0;i<=(m+n);i++)
p[i]=0;
for(i=0;i<=m;i++)
for(j=0;j<=n;j++)
{
p[i+j]=p[i+j]+a[i]*b[j];
}
printf("Polinomul produs este: P(x)=");
for(i=(m+n);i>=0;i--)
if(p[i]>=0)
printf("+%dx^%d%",p[i],i);
else printf("%dx^%d%",p[i],i);
}

Produsul a doua matrici


#include<stdio.h>
#include<conio.h>
void main(void)
{float a[20][20],b[20][20],c[20][20],v;
int m,n,p,i,j,k;
printf("Introduceti nr de linii pt prima matrice:");
scanf("%d",&m);
printf("Introduceti nr de coloane pt prima matrice:");
scanf("%d",&n);
printf("Introduceti nr de coloane a celei de a doua matrice:");
scanf("%d",&p);
printf("Introduceti elementele primei matrice:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{printf("a[%d][%d]=",i,j);
scanf("%f",&v);
a[i][j]=v;
}
printf("Introduceti elementele celei de a doua matrice:\n");
for(i=0;i<n;i++)
for(j=0;j<p;j++)
{printf("b[%d][%d]=",i,j);
scanf("%f",&v);
a[i][j]=v;
}
for(i=0;i<m;i++)
{c[i][j]=0;
for(k=0;k<n;k++) c[i][j]+=a[i][j]*b[i][j];
}
printf("Elementele matricei produs:\n");
for(i=0;i<m;i++)
{for(j=0;j<p;j++) printf("%f",c[i][j]);
putchar('\n');
}
getch();
}

se citesc coeficientii a doua polinoame de


gradul m respectiv n. sa se calculeze
coeficientii produsului celor doua polinoame.
#include<stdio.h>
#include<conio.h>
void main(void)
{
int i,j,m,n,a[30],b[30],c[60];
printf("Introduceti gradul primului polinom: ");
scanf("%d",&m);

printf("Introduceti gradul celui de al doilea polinom: ");


scanf("%d",&n);

printf("Introduceti coeficientii primului polinom sub forma


am*xm+...+a1*x+a0\n");
for(i=m; i>=0;i--)
{
printf("a[%d]=",i);
scanf("%d",a+i);
}
printf("Introduceti coeficientii celui de al doilea polinom sub forma
bm*xm+...+b1*x+b0\n");
for(i=n; i>=0;i--)
{
printf("b[%d]=",i);
scanf("%d",b+i);
}
for(i=0;i<=m+n;i++) c[i]=0;
for(i=0;i<=m;i++)
for(j=0;j<=n;j++) c[i+j]+=a[i]*b[i];
printf("Coeficientii polinomului produs sunt: \n");
for(i=m+n;i>=0;i--) printf("c[%d]=%d\n",i,c[i]);
putchar('\n');
getch();
}

Radical
#include <stdio.h>
#include <math.h>
double f(double x)
{
double eps = 0.00001, x1, x2;
x1=0;
x2=1;
while (fabs(x2-x1)>eps)
{
x1=x2;
x2 = (x1+x/x1)/2;
}
return x1;
}

int main()
{
double x;
printf("x="); scanf("%lf", &x);
printf("Radical din x este: %.2lf\n", f(x));
return 0;
}

Reprezentarea unui numar in binar


#include<stdio.h>

void main(void)
{
void bin(int);
int a=10;
bin(a);
a>>=1;
bin(a);
}
void bin(int i);
{ int j;
for(j=8*sizeof(i)-1;j>=0;j--)printf("%d",i>>j&1)
}

Rezolvarea ecuatiei ax2 + bx +c = 0


#include<stdio.h>
#include<math.h> // se foloseste pt delta
int main()
{
double a, b, c, d;
printf("a="); scanf("%lf", &a);
printf("b="); scanf("%lf", &b);
printf("c="); scanf("%lf", &c);
if (a==0)
{
if (b==0)
{
if (c==0)
{
printf("Orice x este solutie a
ecuatiei\n");
}
else
{
printf("Nu exista nici o solutie\n");
}
}
else
{
printf("Solutia ecuatiei este x = %lf\n", -
c/b);
}
}
else
{
d = (b*b)-(4*a*c);
if (d>=0)
{
printf("x1 = %lf\nx2= %lf\n", (-
b+sqrt(d))/(2*a), (-b-sqrt(d))/(2*a)); // se foloseste sqrt pentru radical
}
else
{
printf("Nu exista solutie reala\n");
}
}
return 0;

Ridicarea matricii la putere


# include <stdio.h>
int main ()
{
int m,n,p,i,j,k;
double a[100][100], c[100][100];

printf("m="); scanf("%d", &m);


printf("n="); scanf("%d", &n);

printf("Introduceti elementele matricii a\n");


for(i=0;i<m;i++)
for(j=0;j<n;j++)
{

printf("a[%d],[%d]=",i,j);scanf("%lf",&a[i][j]);
}

printf("puterea="); scanf("%d", &p);

for (i=0; i<p; i++)


{

for (i=0; i<m; i++)


for (j=0; j<n; j++)
{
c[i][j]=0;
for (k=0; k<n; k++)
c[i][j]+=a[i][k]*a[k][j];
}

for (i=0; i<m; i++)


{
for (j=0; j<n; j++)
printf("%5.2lf ", c[i][j]);
printf("\n");
}

}
return 0;
}

sa se genereze toate nr de lungime n formate


numai cu cifre pare
#include<stdio.h>
#include<conio.h>

int n, x[10];

void afis()
{ int i;
for(i=1;i<=n;i++)
printf("%d",x[i]);
putchar('\n');
}
void cifre(int i)
{ int j;
for(j=0;j<=8;j=j+2) { x[i]=j;
if(i==n) afis();
else cifre(i+1);
}
}

void main()
{ printf("n=...");
scanf("%d",&n);

cifre(1);
getch();
}
Sirul lui Fibonacci
#include<stdio.h>
int n,a,b,c;
void main(void)
{
printf("Introduceti valoare numarului n:");
scanf("%i", &n);
a=1;
printf("numarul este %d \n",a);
b=1;
while(c<n)
{c=a+b;
printf("numarul este %d \n",c);
a=b;
b=c;
}
}

Suma a doua siruri intr-un alt sir

#include<stdio.h>
#include<conio.h>

void main(void)
{
int m,n,i,max, a[20],b[20],c[40];
printf("Dati lungimea primului sir: ");
scanf("%d",&m);
printf("Dati elementele primului sir: \n");
for(i=0;i<m;i++) { printf("a[%d]=",i); scanf("%d",a+i);}
printf("Dati lungimea celui de al doilea sir: ");
scanf("%d",&n);
printf("Dati elementele celui de al doilea sir: \n");
for(i=0;i<n;i++) { printf("b[%d]=",i); scanf("%d",b+i);}

if(m>n) max=m; else max=n;

for(i=0;i<max;i++) c[i]=a[i]+b[i];

printf("Elemente sirului suma sunt: ");


for(i=0;i<max;i++)

if (c[i]>10) c[i]%=10, c[i-1]++;

for(i=0;i<max;i++)
printf("%d",c[i]);
putchar('\n');
}
Suma cifrelor unui nr natural
#include<stdio.h>
void main(void)
{
long int n,s=0,r;
printf("Introduceti valoarea lui n:");
scanf("%i",&n);
do
{r=n%10;
s=s+r;
n/=10;
}
while(n!=0); printf("Suma cifrelor din numar este %d \n",s);
}

suma de bani cu diviziuni


#include<stdio.h>

main()
{
int s,i,k,a[7]={1,5,10,50,100,500,1000};
printf("s=");scanf("%d",&s);
for(i=6;i>=0;i--)
{
k=s/a[i];
if(k!=0) printf("diviziunea %d cu %d aparitii\n",a[i],k);
s=s%a[i];
if(s==0) break;
}
}

Suma divizorilor
#include<stdio.h>
#include<conio.h>
int suma_divi(int n, int i)
{
if(i==n) return n;
else if(n%i==0) return i + suma_divi(n,i+1);
else return suma_divi(n,i+1);
}
void main(void)
{
int n;
printf("dati nr: ");
scanf("%d",&n);
printf("suma divizorilor lui %d este %d ",n,suma_divi(n,1));
}
Suma elem coloana matrice2

#include <stdio.h>
#include <conio.h>
int a[20][20],b[60],i,j,n,m;
void main()
{
printf("Introduceti numarul de linii:\n");
scanf("%d", &n);
printf("Introduceti numarul de coloane:\n");
scanf("%d", &m);
for(i=0;i<=m-1;i++)
for(j=0;j<=n-1;j++)
{
printf("a[%d][%d]=", i, j);
scanf("%d", &a[i][j]);
}
for(i=0;i<=m-1;i++)
b[i]=0;
for(i=0;i<=m-1;i++)
for(j=0;j<=n-1;j++)
b[i]=b[i]+a[j][i];
for(i=0;i<=m-1;i++)
printf("suma elementelor de pe coloana este:%d\n", b[i]);
getch();
}

Suma elemente deasupra diagonalei matrice


#include <stdio.h>;
#include <conio.h>;
int a[10][10],i,j,m,n,s;
void main()
{
clrscr();
printf("dati nr de linii ");
scanf("%d",&n);
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
printf("dati a[%d][%d]=",i,j);
scanf("%d",&
a[i][j]);
}
s=0;
for (i=1;i<=n-1;i++)
for (j=i+1;j<=n;j++)
{
s=s+a[i][j];
}
printf("\n suma elementelor de deasupra diag principale= %d",s);
getch();
}
Suma elemente max de pe linie matrice
#include<stdio.h>
void main(void)
{
int a[20][20],m,n,i,j,k,max[20],suma=0;
printf("Introduceti numarul de linii ale matricii: "); scanf("%d",&n);
printf("Introduceti numarul de coloane ale matricii: ");
scanf("%d",&m);
printf("Introduceti elementele matrcicii:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("a[%d][%d]= ",i,j); scanf("%d",&a[i][j]);
}
}

for(i=0;i<n;i++)
{
max[i]=a[0][0];
for(j=0;j<m;j++)
for(k=j+1;k<m;k++)
{
if(a[i][j]<a[i][k])
{
max[i]=a[i][k];
}
else
{
max[i]=a[i][j];
}
}
}
printf("Suma cifrelor maxime de pe linii este: ");
for(i=0;i<n;i++)
{
suma+=max[i];
}
printf("%d\n",suma);

Suma elementelor de pe coloane a unei matrici


#include<stdio.h>
#include<conio.h>

void main(void)
{
int a[10][10],i,j,n,m,suma;
printf("n=");scanf("%d",&n);
printf("m=");scanf("%d",&m);
for(i=1;i<=n;i++)
{for(j=1;j<=m;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}

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

Calculul sumei primelor n numere naturale


#include <stdio.h>
int n, s;
void main(void)
{
printf("Introduceti valoarea lui n: ");
scanf("%i",&n);
for(s=0; n>0; n--) s+=n;
printf("Suma este: %d\n", s);
}

Transformare grade Fahrenheit in Celsius

#include<stdio.h>
#include<conio.h>
void main(void)

float fahr, celsius;


printf("Dati temperatura in Fahrenheit: ");
scanf("%f",&fahr);

celsius = (5.0 / 9.0) * (fahr - 32.0);


printf("Temperatura Fahrenheit %4.0f este echivalentul %6.1f
Celsius\n", fahr, celsius);

getch();
}
Citind un sir de caractere de la tastatura,
transforma toate literele mici in litere mari,
pe cele mari lasandu-le neschimbate.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
void main(void)
{
char s[256];
int i;
printf("Introduceti sirul: ");
gets(s);
for(i=1; i<= strlen(s);i++)
if(_islower(s[i-1]))
s[i-1]=_toupper(s[i-1]);
printf("Noul sir este: %s/n",s);
}

Transmitere prin adresa


#include<stdio.h>

void schimbare(int &x,int &y)


{
int a;
a=x;
x=y;
y=a;
}
void main(void)
{
int x=5 ,y=7;
schimbare(x,y);
printf("%d%d\n",y,x);
}

Transmitere prin valoare


#include<stdio.h>

void schimbare(int x,int y)


{
int a;
a=x;
x=y;
y=a;
}
void main(void)
{
int x=5 ,y=7;
schimbare(x,y);
printf("%d%d\n",y,x);
}

Calculeaza valoarea polinomului in punctul v

#include<stdio.h>
void main (void)
{
int n,i,p,put,val,a[20];
printf("dati gradul polinomului:");
scanf("%d",&n);
printf("dati coeficientii polinomului");
for (i=n;i>=0;i--)
{
printf("a[%d]=",i);
scanf("%d",a+i);
}
printf("dati punctul:");
scanf("%d",&p);

val=0;
put=1;
i=n;
do
{ val+=a[i]*put;
i--;
put*=p;
}
while (i>=0);
printf("valoarea polinomului este %.2d\n",val);
}

Verificare daca N e numar Fibonacci


#include<stdio.h>
main()
{int n,a=1,b=1,c,ok=0;
printf("n=");scanf("%d",&n);
if(n==1) {printf("e nr fibonacci");
ok=1;}
do {c=a+b;
if(n==c) {printf("e nr fibonacci");
ok=1;}
a=b;
b=c;} while(c<n);
if(ok==0) printf("nu e nr fibonacci");
}