Sunteți pe pagina 1din 15

UNIVERSITATEA DE STAT DIN MOLDOVA

FACULTATEA DE MATEMATIC I INFORMATIC


DEPARTAMENTUL INFORMATICA

DARE DE SEAM
Disciplina: Fundamentele Programrii
I.11 INFORMATIC

Conductor tiinific:

Climenco Elena, lector universitar

Autorul:

Butnaru Oleg

Chiinu, 2014

1. S se realizeze schemele bloc pentru selecie, ciclu i ramifica ie dup


formule.
a) Pentru Selectia:

U
f

a2 x+ ex cosbx
bx ln ( a+ x )b 3 x ln ( bx )

e 2 x ln ( a+ x )b3 x ln ( bx)

Unde:

a=0,5
b=2,9

b) Pentru Ramificatie:
c) Pentru Ciclu:

Z=
Unde:

i 2 +1
i2 +1
asin
, sin
>0
n
n

( ) ( )
1
i +1
cos (i+ ) , sin (
<0
n
n )
2

i [ 1 ; 10 ]
i=1

A) Selectia

Start

B) Ramificatia

Start
a, i, n

sin

a, b, x

a2 x+ ex cosbx

bx ln ( a+ x )b 3 x ln ( bx )

i 2+1
>0
n

( )

( 1n )

z=cos i+

asin

( i +1n )

f =e 2 x ln ( a+ x )b3 x ln ( bx)

U, f

Stop

Stop

Start

C) Ciclu
i 10

sin

( )

Stop

i +1
>0
n

i 2+1
Z =sin
>0
n

( )

( 1n )

z=cos i+

2. Calcul dup o formul


2x

3x

S se scrie programul ce va calcula valoarea lui f= e ln ( a+ x )b ln ( bx)


a2 x+ ex cos bx
u=
x
bxe sin bx +1
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main ()
{
clrscr();
float a, b, x;
double u, f;
printf("Introduceti a, b, x:");
scanf ("%f%f%f",&a, &b, &x);
u=(pow(x,2)+exp(-x)*cos(b*x))/(b*x-exp(-x)*sin(b*x)+1);
f=exp(2*x)*log(a+x)-pow(b,3*x)*log(b-x);
printf ("u=%lf, f=%lf", u, f);
getch ();
}

3. Dimensiunea cmpului de afiare a datelor


S se scrie programul ce va afia la consol urmtorul mesaj:
1 2 3

4 5 6 7 8 9
B U T N A R
R O M A N I A
B A
1 2 . 3
1 7 . 8
1
0 0 0 2 . 1
1
2

2 5

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
main ()

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
U
O L E G
S A R A B I

6 . 3
6 . 3
1 5 . 8
1 6

A
T R I

1 2 . 5
C O L O R

1 5 .
8 2 5

{
clrscr();
printf ("123456789012345678901234\n");
printf ("%-10s%-8s\n","BUTNARU", "OLEG");
printf ("%7s\n", "ROMANIA");
printf ("%-16S%-7f\n","BASARABIA",12.5);
printf (" %4.1f%-.9f\n", 1.1);
printf ("%-7.2f%5,2f%6s\n", 22.15, 14.22, "ANA");
printf ("%7i%6i%ri\n", 425, 240, 15);
getch();
}

4. Structuri decizionale
S se calculeze valoarea lui y cu ajutorul funciei if_else.

( )

i +1
i +1
a sin
; sin
> 0,a=0,3
n
n
Z=
1
i 2 +1
cos i + ; sin
< 0,n=10
n
n

( )

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
main ()
{
clrscr();
float z, a, i, n;
printf("Introduceti. a, i, n");
scanf ("%f%f%f",&a, &i, &n);
if(sin((pow(i,2)+1)/n)>0) z=a*sin((pow(i,2)+1)/n); else
z=cos(i+1/n);
printf ("z=%7.2f", z);
getch();
}

5. Operatorul Condiional
6. S se calculeze valoarea funciei y definit pe mulimea numerelor reale, pentru un x
citit de la tastatur.
x, dac x<0
y = 0, dac 0 x 3
x-3, dac x>3

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
void main()
{clrscr();
float y,x;
printf ("Introdu x:\n");
scanf("%f",&x);
if (x<0) y=x; else if(x>=0&&x<=3) y=0;
else y=x-3;
printf ("y=%5.2f",y);
getch();
}

2) S se calculeze valoarea lui f.


max2 (at ; 2 b ; xz )
f=
+3,4
min ( 2 t ; 4 z ; x +4 )
#include<conio.h>
#include<stdio.h>
#<math.h>
#include<string.h>
main()

{
clrscr();
int a, b, t, z, x; float max, min, f;
printf("introd. a, b, t, z, x");
scanf("%i%i%i%i%i", &a, &b, &t, &z, &x);
if (a*t>2*b) max=a*t; else max=2*b;
if (x*z>max) max=x*z;
if (2*t>4*z) min=4*z; else min=2*t;
if (x+4<min) min=x+4;
f=pow(max,2)/min+3.4*b;
printf ("max=%7.2f \nmin=%7.2f \nf=%7.2f", max, min, f);
getch();
}

7. Instruciunea switch ( )
1) S se scrie un program care afieaz meniul cu zilele sptminii.
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
main ()
{clrscr();
int a;
printf("Alege:\n");
printf("1. Luni \n");
printf("2. Marti \n");
printf("3. Miercuri \n");
printf("4. Joi \n");
printf("5. Vineri \n");
printf ("6. Simbata \n");
printf("7. Duminica \n");
scanf ("%i",&a);
switch (a)
{case 1:printf("Ati ales Luni"); break;
case 2:printf("Ati ales Marti"); ; break;
case 3:printf("Ati ales Miercuri"); break;

case 4:printf("Ati ales Joi") ; break;


case 5:printf("Ati ales Vineri") ; break;
case 6:printf("Ati ales Simbata") ; break;
case 7:printf("Ati ales Duminica") ; break;
default: printf("Ziua a %i nu exista",a);
}
getch();
}

2) S se scrie un program ce afieaz meniul urmtor:


1) Calculeaz u i f
2) Determina max(2b, 3k, c)
3) Calculeaza y
2
x
a x+ e cosbx
u=
x
bxe sinbx+1
f =e 2 x ln ( a+ x )b3 x ln ( bx)

( )

i +1
i +1
; sin
>0, a=0,3
n
n
y=
1
i 2+ 1
cos i + ; sin
<0, n=10
n
n
a sin

( )

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
void main ()
{clrscr();
int k,l, c, e, d, MAX; float a, b,n, x,i, f, u, y,z, w, q;
printf("Alege:\n");
printf("1. Calc. u si f\n");
printf("2. MAX(2b, 3k)\n");
printf("3. Calc. z \n");

scanf ("%i",&e);
switch (e)
{case 1:printf("Introducet a, b si x");
scanf("%f%f%f", &a, &b, &x);
u=(pow(x,2)+exp(-x)*cos(b*x))/(b*x-exp(-x)*sin(b*x)+1);
f=exp(2*x)*log(a+x)-pow(b,3*x)*log(b-x);
printf("u=%7.2f f=%7.2f", u, d);
break;
case 2:printf("Introduceti k, l si c \n");
scanf("%i%i%i",&k, &l, &c);
if (2*k>3*l) MAX=2*k; else MAX=3*l;
if (c>MAX) MAX=c;
printf ("MAX=%i", MAX);
break;
case 3:printf("Introduceti q,z si w");
scanf("%f%f%f", &q, &z,&w);
if (sin((pow(z,2)+1)/w)>0) y=q*sin(pow(z,2)+1/w);
else y=cos(i+(1/n));
printf("y=%7.2f \n",y); break;
default: printf("Punctul %i nu exista",e);
}
getch();
}

8. Structuri Iterative
1) Calculai valoarea lui P utilizind bucla FOR.
4

P=

j+0,3+c
j=1

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
main ()
{ clrscr();
int j,c; float p;
printf ("introduceti c \n");
scanf ("%i", &c);
p=1;
for(j=1; j<4; j=j+1)
{
p=p*(j+0.3+c);
printf("p=%5.2f \n", p);}
getch();}

2) Calculai valoarea expresiei y utiliznd bucla for.

( )

i +1
i +1
; sin
>0, a=0,3
n
n
y=
2
1
i +1
cos i + ; sin
<0, n=10
n
n
a sin

( )

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
main ()
{ clrscr();
int n,i; float a, z;
printf ("introduceti a \n");

scanf ("%f", &a);


n=10;
for(i=1; i<10; i=i+1)
{
if (sin((pow(i,2)+1)/n)>0) z=a*sin(pow(i,2)+1/n);
else z=cos(i+(1/n));
printf("i=%i z=%5.2f \n",i, z);}
getch();}

3) Calculai valoarea expresiei y utiliznd bucla while.

( )

i +1
i +1
; sin
>0, a=0,3
n
n
y=
1
i 2+ 1
cos i + ; sin
<0, n=10
n
n
a sin

( )

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
main ()
{ clrscr();
int n,i; float a, z;
printf ("introduceti a si n \n");
scanf ("%f%i", &a, &n);
i=1;
while(i<=10)
{
if (sin((pow(i,2)+1)/n)>0) z=a*sin(pow(i,2)+1/n);
else z=cos(i+(1/n));
printf("i=%i z=%5.2f \n",i, z); i=i+1;}
getch();}

4) Calculati pentru aceiai expresie utilizind do while


#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
main ()
{ clrscr();
int n,i; float a, z;
printf ("introduceti a, n \n");
scanf ("%f%i", &a, &n);
i=1;
do {
if (sin((pow(i,2)+1)/n)>0) z=a*sin(pow(i,2)+1/n);
else z=cos(i+(1/n));
printf("i=%i z=%5.2f \n",i, z); i=i+1;}
while(i<=10);
getch();}

9. Tablouri unidimensionale
S se scrie programul ce va introduce de la tastatur elementele tabloului unidimensional
i va calcula media aritmetica a elementelor acestuia.
#include <stdio.h>

#include <conio.h>
#include <math.h>
#include <string.h>
main ()
{ clrscr();
int i,n, a[10];
float med, d;
printf ("dati nr de element a tab.:");
scanf ("%i",&n);
for (i=0; i<n; i++)
{printf("intr a[%i]=",i);
scanf("%i", &a[i]);
}
d=0;
for(i=0; i<n; i++){
d=d+a[i];}
printf("\n %5.2f", d);
med=d/n;
printf("\n %5.2f", med);
getch();}

10.Tablouri bidimensionale
S se scrie programul ce va introduce de la tastatur elementele tabloului bidimensional i va
zerografia diagonala principal.
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
main ()
{ clrscr();
int i, j, n, m, a[10][10];
printf ("n=");
scanf ("%i",&n);
for (i=0; i<n; i++)
for (j=0; j<n; j++)
{printf("\n a[%i,%i]=", i, j);

scanf ("%i",&a[i][j]);}
for (i=0; i<n; i++) {
printf("\n");
for (j=0; j<n; j++)
printf("%i", a[i][j]);}
for(i=0; i<n; i++)
for (j=0; j<n; j++){
if (i==j) a[i][i]=0;}
for (i=0; i<n; i++) {
printf("\n");
for (j=0; j<n; j++)
printf("%i", a[i][j]);}
getch();}