Sie sind auf Seite 1von 3

# /* Ecuatia de gradul doi*/

#include <iostream.h>
#include <conio.h>
#include <math.h>
void main (void)
{
clrscr();
float a,b,c,delta,x1,x2;
cout<<"a="; cin>>"%f",&a;
cout<<"b="; cin>>"%f",&b;
cout<< "c="; cin>>"%f",&c;
if (a) { delta=b*b-4*a*c;
else { x1=(-b-sqrt(delta))/(2*a);
x2=(-b+sqrt(delta))/(2*a);
cout<<"\n\t x1=%10.3f",x1;
cout<<"\n\t x2=%10.3f",x2;
}
}
else cout<<"\n\t ecuatie de gradul 1";
getch();
}
/*minim si maxim dintre 3 numere*/
#include <stdio.h>
#include <conio.h>
void main (void)
{
float a,b,c,min,max;
printf ("a=");scanf ("%f", &a);
printf ("b=");scanf ("%f", &b);
printf ("c=");scanf ("%f", &c);
if (a<b) { min=a; max=b;}
else {min=b; max=a;};
if (min>c) min=c;
if (max<c) max=c;
printf ("Min=%f\n", min);
printf ("Max=%f\n", max);
getch();
}

/*factorial*/
#include <stdio.h>
#include <conio.h>
void main ()
{
clrscr ();
int n, i=1;
long int f=1;
printf ("n="); scanf ("%d", &n);
do
{
f*=i;
i++;
}
while (i<=n);
printf ("n!=%d",f);
getch ();
}
/*schimbarea a doua numere intregi intre ele*/
#include <stdio.h>
#include <conio.h>
main ()
{
clrscr ();
int a, b, aux;
printf ("introduceti cele doua variabile (a, b):"); scanf("%d%d", &a, &b);
aux=a;
a=b;
b=aux;
printf ("dupa interschimbare: a=%d b=%d",a, b);
getch();
return 0;
}

## /*suma a n numere intregi*/

# include <stdio.h>
#include <conio.h>
void main ()
{
clrscr ();
int n, i, a[50];
long int s;
printf ("n="); scanf ("%d", &n);
for (i=1; i<=n; i++)
{
printf ("A(%d)=", i); scanf ("%d", &a[i]);
}
s=0;
for (i=1; i<=n; i++) s=s+a[i];
printf ("s=%ld", s);
getch ();
}
/*divizibilitatea cu 6*/
#include <stdio.h>
#include <conio.h>
void main ()
{
clrscr ();
int n;
printf ("n="); scanf ("%d", &n);
printf ("%d este multiplu de 6", n);
switch (n%3)
{
case 1: switch (n%2)
{
case 0: printf ("\t plus 4"); break;
case 1: printf ("\t plus 1"); break;
} break;
case 2: switch (n%2)
{
case 0: printf ("\t plus 2"); break;
default: printf ("\t plus 5");
} break;
default: if (n%2) printf ("\t plus 3");
}
getch ();
}

/*divizibilitate cu 4*/
#include <stdio.h>
#include <conio.h>
void main ()
{
clrscr ();
int n;
printf ("n="); scanf ("%d",&n);
printf ("numarul este multiplu de 4");
switch (n%4)
{
case 1: printf ("plus 1"); break;
case 2: printf ("plus 2"); break;
case 3: printf ("plus 3"); break;
}
getch ();
}
/*minimul si maximul unui sir*/
#include <stdio.h>
#include <conio.h>
void main ()
{
clrscr ();
int a[100], i, n, min, max;
printf ("n="); scanf ("%d", &n);
for (i=1; i<=n; ++i)
{
printf ("a(%d)=", i); scanf ("%d", &a[i]);
}
min=a[1]; max=a[1];
for (i=2; i<=n; ++i)
{
if (a[i]>max) max=a[i];
else if (a[i]<min) min=a[i];
}
printf ("min=%d", min);
printf ("max=%d", max);
getch ();
}

/*testeaza cod*/
#include <stdio.h>
#include <conio.h>
#include <process.h>
void main ()
{
char i;
unsigned int cod=1234, pin;
i=1;
while (i-4)
{
clrscr ();
printf ("pin="); scanf ("%d", &pin);
if (cod==pin) break;
++i;
}
if (i>3) exit (1);
else printf ("cod corect");
getch ();
}
/*produsul a doua matrici*/
#include <stdio.h>
#include <conio.h>
void main ()
{
clrscr ();
int n, p, q, i, j, k;
int a[10][10], b[10][10], c[10][10];
printf ("n="); scanf ("%d", &n);
printf ("p="); scanf ("%d", &p);
printf ("q="); scanf ("%d", &q);
for (i=0; i<n; ++i)
for (j=0; j<p; ++j)
{
printf ("a(%d,%d)=", i+1, j+1); scanf ("%d", &a[i][j]);
}
for (i=0; i<p; ++i)
for (j=0; j<q; ++j)
{
printf ("b(%d,%d)=", i+1, j+1); scanf ("%d", &b[i][j]);
}
for (i=0; i<n; ++i)
for (j=0; j<q; ++j)
{
c[i][j]=0;
for (k=0; k<p; ++k)
c[i][j]+=a[i][k]*b[k][j];
}
for (i=0; i<n; ++i)
{
for (j=0; j<q-1; ++j)
printf ("%6d ", c[i][j]);
printf ("%6d\n", c[i][q-1]);
}
getch ();
}

#include <stdio.h>
#include <conio.h>
void main ()
{
clrscr ();
float a, x=1, y, z;
const float delta=0.0001;
printf ("introduceti un numar pozitiv"); scanf ("%f", &a);
if (a<0) printf ("numar negativ");
else {
y=(x+a/x)/2;
z=x-y;
if (z<0) z=-z;
while (z>delta)
{
x=y;
y=(x+a/x)/2;
z=x-y;
if (z<0) z=-z;
};
printf ("radical din %f este %f", a, y);
getch();
}
}
/*testare numere reale*/
#include <stdio.h>
#include <conio.h>
void main ()
{
clrscr ();
float x;
printf ("introduceti un numar real:"); scanf ("%f", &x);
if (x>0) printf ("pozitiv");
else
{
if (x<0) printf ("negativ");
else printf ("nul");
}
getch ();
}