Reprez. Grafica A Functiei Radical: Problema 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Problema 1

Reprez. grafica a functiei radical


#include<math.h>
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main()
{ int i,n,gd,gm;
printf("introduceti val. sup. a intervalului ");
scanf("%d",&n);
gd=DETECT;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\borlandc\\bgi");
line(0,getmaxy(),0,0);
outtextxy(5, 5, "X"); outtextxy(getmaxx() - 5, getmaxy(), "X");

line(0,getmaxy(),getmaxx(),getmaxy() );
for(i = 0; i < n; i++)
putpixel(i,getmaxy() - sqrt(i),GREEN);
getch();
closegraph();
}
Problema 1
Calculul unei sume simple
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
int n,i;
float s;
clrscr();
printf("introduceti limita: ");
scanf("%d",&n);
s = 0;
for(i = 0; i < n; i++) {

s += (float)1 / (2 + i);
}
printf("suma este: %f", s);
getch();
}
Problema 2
Calculul unei sume duble
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
int n,i,j;
float s;
clrscr();
printf("introduceti limita: ");
scanf("%d",&n);
s = 0;
for(i = 0; i < n; i++)
for(j = 0; j < i; j++)
s +=(float) (i + j) / (j + 2) ;
printf("suma este: %f", s);
getch();
}
Problema 1
Aplicatii ale legii lui Ohm
##include<stdio.h>
#include<conio.h>
void main(void)
{
int u,i,r;
clrscr();
printf("Introduceti I si R: ");
scanf("%d %d",&i,&r);
u = r * i;

printf("\n Valoarea U = %d", u);


getch();
}

Problema 2
Produsul a doua numere complexe
#include<stdio.h>
#include<conio.h>

struct complex {
int re;
int im;
};
void main(void)
{
complex a, b, c;
clrscr();
printf( "introduceti cele 2 nr. complexe \n");
scanf("%d %d %d %d", &a.re,&a.im, &b.re,&b.im);
c.re = a.re * b.re - a.im * b.im;
c.im = a.re * b.im - a.im * b.re;
printf("\n produsul celor 2 nr. complexe este %d %d", &c.re, &c.im);
getch();
}

Problema 3
Calculul valorii unei functii intr-un punct (f(x)=sqrt(x*x-4))
#include<stdio.h>
#include<conio.h>

#include<math.h>
void main(void)
{
float x;
scanf("%f",&x);
if(x*x-4>0)
printf("%f",sqrt(x*x-4));
}
else
printf("Nu se poate calcula");
}

Problema 4
Ecuatia de gradul al doilea
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
int a,b,c;
float x1,x2,d;
clrscr();
printf("introduceti coef. ecuatiei \n");
scanf("%d %d %d",&a, &b, &c);
if (a==0)
if ( b== 0)
printf("ecuatia nu are solutii");
else
{
x1 = -c / (b * 1.0);
printf("ecuatie de grad 1, cu solutia %f", x1);
}
else
{
d= b * b - 4 * a * c;

if ( d >=0)
{
x1 = (-b + sqrt(d)) / (2 * a * 1.0);
x2 = (-b - sqrt(d)) / (2 * a * 1.0);
print("radacinile reale ale ecuatiei sunt %f %f", x1, x2);
}
else printf( "ecuatia nu are solutii reale");
}
getch();
}
Problema 1
Calculul maximului dintr-un vector
#include<stdio.h>
#include<conio.h>

void main(void)
{
int a[100],max,i,n;
clrscr();
printf("introduceti dimensiunea vectorului: ");
scanf("%d",&n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
max = a[0];
for(i = 1; i < n; i++)
if (max < a[i]) max = a[i];
printf("\n maximul este: %d", max);
getch();
}

Problema 2
Ordonarea unui vector
#include<stdio.h>
#include<conio.h>
#include<math.h>

void main(void)
{
int a[100],i,j,n,aux;
clrscr();
printf("introduceti dimens vectorului: ");
scanf("%d",&n);
printf("\n introduceti elementele ");
for(i = 0; i < n; i++)
scanf("%d", &a[i]);
for(i = 0; i < n; i++)
printf("%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]);
getch();
}

Problema 3
Suma pe linii intr-o matrice
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
int a[100][100],s[100],i,j,n,m,k;
clrscr();
printf("introduceti dimens matricei: ");

scanf("%d %d",&n,&m);
printf("\n introduceti elementele matricei: ");
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
scanf("%d %d", &a[i][j]);
for(i = 0; i < n; i++) s[k] = 0;
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++)
s[k] += a[i][j];
k++;
}
printf("vectorul de sume este \n:");
for(i = 0; i < n; i++)
printf("%d ", s[i]);
}

Problema 4
Inmultirea a doua matrice
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
int a[100][100],b[100][100],c[100][100],i,j,n,m,k;
clrscr();
printf("introduceti dimens matricei: ");
scanf("%d %d",&n,&m);
printf("\n introduceti elementele matricei 1: ");
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
scanf("%d", &a[i][j]);
printf("\n introduceti elementele matricei 2: ");
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)

scanf("%d", &b[i][j]);
for(i = 0; i < n; i++)
for(j = 0; j < m; j++) c[i][j] = 0;
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
for(k = 0; k < n; k++)
c[i][j] += a[i][k] * b[k][j];
printf("\n matricea rezultat este:");
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
printf("%d", c[i][j]);
getch();
}

Problema 1
Generarea fisierului de intrare
#include <stdio.h>
#include <conio.h>
struct elev{
char nume[10];
int varsta, ms1, ms2;
float mg;
};
void main()
{
int i, n;
struct elev v[20];
FILE *f;
scanf( %d,&n);
for(i=0;i<n;i++)
scanf(%s%d%d%d, v[i].nume,&v[i].varsta, &v[i].ms1, &v[i].ms2);
f=fopen(c:\\student\\elev.dat,w);
fscanf(f, %d,&n);

for(i=0;i<n;i++)
fprintf(f,\n%s\n%d\n%d\n%d, v[i].nume,v[i].varsta,v[i].ms1,v[i].ms2);
fclose(f);
getch();
}
Problema 2
Afisarea datelor din fisier
#include <stdio.h>
include <conio.h>
struct elev{
char nume[10];
int varsta, ms1, ms2;
float mg;
};
void main()
{
int i, n;
struct elev v[20];
FILE *f;
f=fopen(c:\\student\\elev.dat,r);
fscanf(f, %d,&n);
for(i=0;i<n;i++)
fscanf(f,%s%d%d%d, v[i].nume,&v[i].varsta, &v[i].ms1, &v[i].ms2);
for(i=0;i<n;i++)
printf(\n%s\n%d\n%d\n%d, v[i].nume,v[i].varsta,v[i].ms1,v[i].ms2);
fclose(f);
getch();
}

Problema 3
Calcularea mediei generale
#include <stdio.h>
#include <conio.h>
struct elev{
char nume[10];

int varsta, ms1, ms2;


float mg;
};
void main()
{
int i, n;
struct elev v[20];
FILE *f;
f=fopen(c:\\student\\elev.dat,r);
fscanf(f, %d,&n);
for(i=0;i<n;i++)
fscanf(f,%s%d%d%d, v[i].nume,&v[i].varsta, &v[i].ms1, &v[i].ms2);
fclose(f);
for(i=0;i<n;i++)
{ v[i].mg=(float)(v[i].ms1+v[i].ms2)/2;
printf(\n%s\n%d\n%d\n%d\m%f, v[i].nume,v[i].varsta,v[i].ms1,v[i].ms2,v[i].mg);
}
f=fopen(c:\\student\\elev.dat,w);
fscanf(f, %d,&n);
for(i=0;i<n;i++)
fprintf(f,\n%s\n%d\n%d\n%d\n%f, v[i].nume,v[i].varsta,v[i].ms1,v[i].ms2,v[i].mg);
fclose(f);
getch();
}

Problema 4
Realizarea histogramei
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
struct elev{
char nume[10];
int varsta, ms1, ms2;
float mg;
};

void main()
{
int i, n,gd,gm;
struct elev v[20];
FILE *f;
float y[3],kx,ky,ymax,d;

f=fopen(c:\\student\\elev.dat,r);
fscanf(f, %d,&n);
for(i=0;i<n;i++)
fscanf(f,%s%d%d%d%f, v[i].nume, &v[i].varsta, &v[i].ms1, &v[i].ms2, &v[i].mg);
fclose(f);
y[0]=0;y[1]=0;y[2]=0;
for(i=0;i<n;i++)
if (v[i].mg<5)
y[0]++;
else
if (v[i].mg>8)
y[2]++;
else
y[1]++;
gd=DETECT;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,c;\\borlandc\\bgi);
ymax=y[0];
for(i=0;i<3;i++)
if(ymax<y[i])
ymax=y[1];
d=getmaxx()/3;
ky=(float)getmaxy()/ymax;
for(i=0;i<3;i++)
y[i]*=ky; // sau y[i]=y[i]*ky;
for(i=0;i<3;i++)

y[i]=getmaxy()-y[i];
for(i=0;i<3;i++)
bar3d(i*d,getmaxy(),(i+1)*d-30,y[i],10.1);
closegraph();
getch();
}

You might also like