Esempio n. 1
0
void impartire(float p1[],float p2[],int grad1,int grad2)
{
	if(grad1<grad2)
	{
		printf("\np1/p2=0 + ");
	    afisare(p2,grad2);
		return;
	}

	int i,j,k,grad_cat=grad1-grad2,grad_rest=grad2-1;
    float cat[grad_cat+1],rest[grad_rest+1];
    initialize(cat,grad_cat);
    initialize(rest,grad_rest);
    for(i=grad1-grad2,j=grad1;i>=0;i--,j--)
    {
        cat[i]=p1[j]/p2[grad2];
        for(k=grad2;k>=0;k--)
            p1[i+k]=p1[i+k]-cat[i]*p2[k];
            p1[j]=0;
    };
    for(i=0;i<=grad2-1;i++)
        rest[i]=p1[i];

	printf("\np1/p2=");
	afisare(cat,grad_cat);
	printf("\np1%%p2=");
	afisare(rest,grad_rest);
}
Esempio n. 2
0
int main()
{
    int n;
    init();
    addfirst(12);
    addlast(9);
    n=count();

    afisare();
node_t *b=keyfind(4);
if(b!=NULL)

{
    printf("%d",b->k);
}
else{printf("Valoarea nu exista");}

    removekey(2);
    afisare();
    printf("%d",count());




    return 0;
}
Esempio n. 3
0
main(){
  citire();
  afisare();
  lista_fig();
  afisare();
  for(int i=0;i<n;i++) delete fig[i];
}
Esempio n. 4
0
int main(void)
{
  citire();
  rezolva();
  afisare();
  return 0;
}
Esempio n. 5
0
void cadouri(long *pret, long n, FILE *f) {
	long *nr = malloc(n*sizeof(long));	//nr de cadouri bune pt fiecare indice
	long *prev = calloc(n,sizeof(long));	//contine indicele cadoului precedent
	long i,j,pv;
	long nr_max = 1;		//nr max de cadouri bune
	long sf = 0;		//indicele ultimului cadou bun
	nr[0]= 1;	//macar un cadou este bun
	prev[0]= -1;	//primul cadou nu are un cadou precedent cu pret mai mic
	for(i=1;i<n;i++) {		//parcurg lista cu preturile cadourilor
		pv = -1;	//indice local al cadoului precent 
		nr[i] = 1;	//indicele curent are macar un cadou potrivit ca pret
		for(j=0;j<i;j++) {	//parcurg lista de cadouri pana la indicele curent
			if(pret[j]<pret[i] && nr[i]<(nr[j]+1)) { //daca am vreun cadou bun
				nr[i]= nr[j]+1;	//creste numarul de cadouri bune ptr indice
				pv = j;		//indicele cadoului precedent se actualizeaza
			}
		}
		prev[i] = pv;	//se retine indicele ultimului cadou bun indicelui curent
		if(nr_max < nr[i]) {	//daca am un nr de cadouri mai mare ca maximul
			nr_max = nr[i];		//se retine
			sf = i;		//retin indicele ulimului cadou din secventa
		}
	}
	afisare(pret,prev,sf,f);	//afisarea indicilor buni in fisier
	free(prev);		//eliberarea zonelor de memorie
	free(nr);
}
Esempio n. 6
0
void main()
{
    int x;

    clrscr();
    printf("\n");

eti:
    citire_date();
    x= caut_max();
    clrscr();
    afisare(x);
    printf("\n Aceasta este configuratia buna (d/n) ? ");
    scanf("%c", &c);
    scanf("%c", &c);
    if (c == 'n')
    {
        for (i= 1; i <= n; i++)
        {
            p= varf[i];
            while (p != NULL)
            {
                q= p;
                p= p->leg;
                delete q;
            }
        }
        goto eti;
    }

    return;
}
Esempio n. 7
0
void suma_diferenta(float p1[],float p2[],int max)
{
	int i;
	float sum[max+1],dif[max+1];
	for(i=0;i<=max;i++)
	{
		sum[i]=p1[i]+p2[i];
		dif[i]=p1[i]-p2[i];
	}

	printf("\np1+p2=");
	afisare(sum,max);

	printf("\np1-p2=");
	afisare(dif,max);
}
Esempio n. 8
0
int main(){
   int a[10][10],n;
   scanf("%d",&n);
   citire(a,n);
   afisare(a,n);
   if(n%2==1)
      printf("%d ", a[n/2][n/2]);
      printf("\n");
return 0;
}
Esempio n. 9
0
void produs(float p1[],float p2[],int grad1,int grad2)
{
	int i,j;
	float prod[grad1+grad2+1];
	initialize(prod,grad1+grad2);
	for(i=0;i<=grad1;i++)
	for(j=0;j<=grad2;j++)
    	prod[i+j]+=p1[i]*p2[j];
	printf("\np1*p2=");
	afisare(prod,grad1+grad2);    
}
Esempio n. 10
0
int main()
{
	int grad1,grad2,max=0,i;

	printf("Introduceti gradele polinoamelor:");
	scanf("%d %d",&grad1,&grad2);
	(grad1>=grad2)?(max=grad1):(max=grad2);

	//vectori in care retinem coeficientii polinoamelor
	float p1[max+1],p2[max+1];

	initialize(p1,max);
	initialize(p2,max);	

	printf("Introduceti coeficientii lui p1:");
	for(i=0;i<=grad1;i++)
		scanf("%f",&p1[i]);

	printf("Introduceti coeficientii lui p2:");
	for(i=0;i<=grad2;i++)
		scanf("%f",&p2[i]);

	printf("p1=");
	afisare(p1,grad1);

	printf("p2=");
	afisare(p2,grad2);

	//suma si diferenta polinoamelor
	suma_diferenta(p1,p2,max);

	//produsul
	produs(p1,p2,grad1,grad2);

    //catul
	impartire(p1,p2,grad1,grad2);

	return 0;			
}
Esempio n. 11
0
File: test.c Progetto: vegitto/Test
int main() {
    int x,y;
    citire(&x,&y);
    int n1, n2;
    n1 = palindrom(x);
    n2 = palindrom(y);
    if (n1 == 1 && n2 == 1 ) {
        printf("Da\n");
    } else {
        printf("Nu\n");
    }
    afisare(x,y);
    printf("min is %d\n", get_min(x,y));
    printf("max is %d\n", get_max(x,y));
    return 0;
}
int main ( ) {
  cout<<"dati valori pt. arbore, la sf. CTRL+Z ";	cin>>m;
  id=0;
  while ( cin.good ( ) ) {
    crarb ( r, m );
    cout<<"Dati o noua valoare ";	cin>>m;
  }
  id=0;
  crarb ( r, m );
  if ( id ) {
    cap=NULL;
    ant=cap;
    drs ( r );
    cout<<"Valorile din arbore ordonate descrescator ";
    afisare ( cap );
  }
  else cout<<"Lista nu s-a creat. Noua valoare exista deja";
  getch ( );
  return 0;
}
Esempio n. 13
0
void introducere_multi(int n)
{int x,y;
printf("Jucatorul numarul 1!!Introduceti indicele linie si coloanei pe care vreti sa scrieti ");
if(n==1)
    printf("X!\n");
    else
    printf("O!\n");
    scanf("%d%d",&x,&y);
a[x][y]=n;
afisare();
verificare_multi(n);
if (ok==0)
return;
else
printf("Jucatorul numarul 2!!Introduceti indicele linie si coloanei pe care vreti sa scrieti ");
if(!n==1)
    printf("X!\n");
    else
    printf("O!\n");
    scanf("%d%d",&x,&y);
a[x][y]=!n;
}
void gaussjordan(double **a, int n)
{
// CREAREA MATRICEI
    int i, j, k, m= 2*n;
    double **b=(double **) malloc(n * sizeof(double*));
    for (i=0; i<n; i++)
        b[i]=(double *) malloc(m * sizeof(double));
    for (i=0; i<n; i++)
    {
        for (k=0; k<n; k++)
            b[i][k]=a[i][k];
        for (j=n; j<m; j++)
            if (i+n==j)
                b[i][j]=1;
            else
                b[i][j]=0;
    }

    for (i=0; i<n; i++)
        calcul(b, n, i);
    afisare(b, n);
}
Esempio n. 15
0
void afisare(FILE*fis, int recursivitati, radix *prim)
{
	static bool flag = false;
	static bool ok = true;
	if (prim->next == NULL)
	{
		fprintf(fis, "%c", prim->caracter);
		flag = true;
		return;
	}
	else
	{
		for (int i = 0; i < prim->nr_fii; i++)
		{
			if (flag == true)
			{
				fprintf(fis, "\n");
				for (int i = 0; i < recursivitati; i++)
				{
					fprintf(fis, " ");
				}
				flag = false;
				ok = false;
			}
			if (ok == true)
			{
				fprintf(fis, "%c", prim->caracter);
			}
			ok = true;
			afisare(fis, recursivitati + 1, (prim->next)[i]);
		}


	}

}
Esempio n. 16
0
void main()
{
	int n = 0;
	int h_1 = 0, m_1 = 0;
	int h_2 = 0, m_2 = 0;

	int h_3 = 0, m_3 = 0;
	int h_4 = 0, m_4 = 0;
	char x[1024];
	prim = NULL;
	ultim = NULL;
	printf("Dati nr de spectacole ");
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		printf("Dati ora de inceput, sfarsit si numele spectacolului");
		scanf("%d %d %d %d",&h_1,&m_1,&h_2,&m_2);
		gets(x);
		gets(x);
		printf("%s", x);
		adaugare(h_1,m_1,h_2,m_2,x);
	}
	/*afisare();
	printf("Dati orele vizionarii\n");
	printf("Ora inceput: ");
	scanf("%d", &h_3);
	printf("\nMinut inceput: ");
	scanf("%d", &m_3);
	printf("\nOra sfarsit: ");
	scanf("%d", &h_4);
	printf("Minut sfarsit: ");
	scanf("%d", &m_4);*/
	printf("\n\n\n\n\n\n\n\n");
	ordonare_sfarsit();
	afisare();
}
Esempio n. 17
0
void joc_multi()
{
    introducere_multi(n);
    afisare();
    verificare_multi(n);
}
Esempio n. 18
0
void joc()
{
    introducere(n);
    afisare();
    verificare(n);
}
Esempio n. 19
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static int ok = 0;
	static int nr_fis_intrare = 0;
	static int nr_fis_iesire = 0;

	switch (msg)
	{
	case WM_CREATE:
	{


					  //text static 1
					  HWND statik = CreateWindowEx(0,
						  "STATIC",
						  NULL,
						  WS_CHILD | WS_VISIBLE|SS_CENTER,
						  60, 10, 300, 200,
						  hwnd,
						  NULL,
						  NULL,
						  NULL);

					  SetWindowText(
						  statik,
						  "Introduceti textul pentru prelucrare!!"
						  );
					  //
					  //text static nr2
					  HWND statik2 = CreateWindowEx(0,
						  "STATIC",
						  NULL,
						  WS_CHILD | WS_VISIBLE|SS_CENTER,
						  60, 260, 300, 200,
						  hwnd,
						  NULL,
						  NULL,
						  NULL);

					  SetWindowText(
						  statik2,
						  "Arborele radix corespunzator este:"
						  );

					  //caseta text nr 1
					  HFONT hfDefault;
					  	  hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
						  WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
						  0, 40, 400, 200, hwnd, NULL, GetModuleHandle(NULL), NULL);
					  if (hEdit == NULL)
						  MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);

					  //caseta text nr 2
					  HFONT hfDefault2;
					  hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
						  WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
						  0, 280, 400, 200, hwnd, NULL, GetModuleHandle(NULL), NULL);
					  if (hEdit == NULL)
						  MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
					  //caseta taext 3
					  HFONT hfDefault3;
					  hEdit3 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
						  WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
						  410, 350, 200, 100, hwnd, NULL, GetModuleHandle(NULL), NULL);
					  if (hEdit == NULL)
						  MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);


					  //buton 1
					  CreateWindow("BUTTON",
						  "Afisare arbore",
						  WS_BORDER | WS_CHILD | WS_VISIBLE,
						  410, 300, 250, 50,
						  hwnd, (HMENU)Buton_Afisare, NULL, NULL);
					  //
					  //buton 2
					  CreateWindow("BUTTON",
						  "Apasati pentru a prelucra textul!",
						  WS_BORDER | WS_CHILD | WS_VISIBLE,
						  410, 50, 250, 50,
						  hwnd, (HMENU)Buton_prelucrare, NULL, NULL);
					  LoadTextFileToEdit(hEdit,"f.txt");
	}
		break;




	case WM_COMMAND:

		switch (LOWORD(wParam))
		{

		case ID_FILE_OPEN:
		{
							 OPENFILENAME ofn;
							 char szFileName[MAX_PATH] = "";

							 ZeroMemory(&ofn, sizeof(ofn));

							 ofn.lStructSize = sizeof(ofn); 
							 ofn.hwndOwner = hwnd;
							 ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
							 ofn.lpstrFile = szFileName;
							 ofn.nMaxFile = MAX_PATH;
							 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
							 ofn.lpstrDefExt = "txt";

							 if (GetOpenFileName(&ofn))
							 {
								 // Do something usefull with the filename stored in szFileName
								 MessageBox(hwnd, szFileName, "Ati ales",
									 MB_OK | MB_ICONEXCLAMATION);
								static char text[100];

								LoadTextFileToEdit(hEdit, szFileName);
							 }

		}
			break;
		case ID_FILE_SAVE:
		{
							 int val=0;
							 val = GetWindowText(hEdit, &textSaved[0], 20000);
							 MessageBox(hwnd, textSaved, "Salvati urmatorul text:",
								 MB_OK | MB_ICONEXCLAMATION);

							 OPENFILENAME ofn;
							 char szFileName[MAX_PATH] = "";

							 ZeroMemory(&ofn, sizeof(ofn));

							 ofn.lStructSize = sizeof(ofn);
							 ofn.hwndOwner = hwnd;
							 ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
							 ofn.lpstrFile = szFileName;
							 ofn.nMaxFile = MAX_PATH;
							 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
							 ofn.lpstrDefExt = "txt";

							 if (GetOpenFileName(&ofn))
							 {
								 // Do something usefull with the filename stored in szFileName
								 MessageBox(hwnd, szFileName, "Text Salvat in:",
									 MB_OK | MB_ICONEXCLAMATION);
								
							 }
							 SaveTextFileFromEdit(hEdit, szFileName);

		}
			break;

		case ID_START:
		{	
		
		}
			break;
		case Buton_prelucrare:
		{
								 int k = 1;
								 SetWindowText(hEdit2, "");
								 if (SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0) == 0) // then field is empty
								 {
									 MessageBox(hwnd, "Nu ati introdus text!", "Atentionare!",
										 MB_OK | MB_ICONERROR);
									 SetWindowText(hEdit3, "");   //golire textbox3
									 FILE*f = fopen("f.txt", "wt");

									 fputs("Introduceti text!", f);
									 LoadTextFileToEdit(hEdit, "fis.txt");
									 fclose(f);
								 }
								 else
								 {
									 SaveTextFileFromEdit(hEdit, "fis.txt");
									 char cuv[100];
									 inserare(rad, '*');
									 FILE*fis = fopen("fis.txt", "rt");
									 FILE*fis2;
									 while (!feof(fis))
									 {
										 fscanf(fis, "%s", cuv);
										 functie(cuv, rad);
									 }
									 fseek(fis, 0, 0);

									 nr_fis_intrare = nr_caractere(fis);

									 fclose(fis);
									 fis2 = fopen("f.txt", "wt");
									 afisare(fis2, 0, rad);
									 fclose(fis2);
									 fis2 = fopen("f.txt", "rt");
									 fseek(fis, 0, 0);
									 nr_fis_iesire = nr_caractere(fis2); 
									 fclose(fis2);
									 stergere(rad);

									 rad = NULL;
									 ok = 1;
									 MessageBox(hwnd, "Textul a fost prelucrat cu succes!", "Atentionare!",
										 MB_OK | MB_ICONINFORMATION);
								 }
		}
			break;
		case Buton_Afisare:
		{
							  if (ok == 1)
							  {
								  ok = 0;
								  MessageBox(hwnd, "Textul a fost transformat cu succes!!", "Atentionare!",
									  MB_OK | MB_ICONINFORMATION);
								  LoadTextFileToEdit(hEdit2, "f.txt");   //
								
								  FILE*fis = fopen("f.txt", "wt");
								  fprintf(fis, "Numar initial:%d\n", nr_fis_intrare);
								  fprintf(fis, "Numar comprimat:%d\n", nr_fis_iesire);
								  int x = 100 - ((nr_fis_iesire*100/nr_fis_intrare));
								  fprintf(fis, "Procentul de eficienta: %d", x);
								  fprintf(fis,"%c", '%');

								  fclose(fis);
								 LoadTextFileToEdit(hEdit3,"f.txt");

								 fis = fopen("f.txt", "wt");
								 fclose(fis);
								
							  }
							  else
							  {
								  MessageBox(hwnd, "Textul nu a fost prelucrat anterior!!", "Atentionare!",
									  MB_OK | MB_ICONSTOP);
								  SetWindowText(hEdit3, "");
							  }
							  FILE*fis = fopen("f.txt", "wt");
							  fputs("Introduceti text!", fis);
							  LoadTextFileToEdit(hEdit, "fis.txt");
							  fclose(fis);

							  fis = fopen("fis.txt", "wt");
							  fclose(fis);
		}
			break;
		case ID_CLEAR:
		{
						 SetWindowText(hEdit,"");
						 SetWindowText(hEdit2, "");
						 SetWindowText(hEdit3, "");
		}
			break;
		}
		break;
	
	case WM_SIZE:
	{
					HWND hEdit;
					RECT rcClient;
					GetClientRect(hwnd, &rcClient);
					hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
					SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
	}
		break;


	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}
Esempio n. 20
0
int main(int argc, char *argv[])
{

	char c,inf;
	cap=NULL;

	do
	{
		printf("1. Introducere caracter in coada.\n");
		printf("2. Scoatere caracter din coada.\n");
		printf("3. Afisare coada.\n");
		printf("4. Golire coada.\n");
		printf("Esc - Parasirea programului\n");
		spati();

		c=getch();
		switch(c)
		{
		case '1':
			printf("Dati un caracter: ");
			inf=getche();
			if(!inserare(inf))
				printf("\nMemorie insuficienta!");
			else
				printf("\nAm introdus: %c",inf);
			spati();
			printf("Apasati orice tasta...\n\n\n");
			break;
		case '2':
			if(!scoatere(&inf))
				printf("Stiva goala!");
			else
				printf("Am scos: %c",inf);
			spati();
			printf("Apasati orice tasta...\n\n\n");
			break;
		case '3':
			printf("Stiva contine: ");
			afisare();
			spati();
			printf("Apasati orice tasta...\n\n\n");
			break;
		case '4':
			golirecoada();
			printf("Am golit stiva!");
			spati();
			printf("Apasati orice tasta...\n\n\n");
			break;
		case 27:
			printf("Apasati o tasta pt. a iesi!");
			break;
		default:
			printf("Apasati 1,2,3,4 sau Escape");
			spati();
		}

		getch();
	}
	while (c!=27);
	golirecoada();


	return 0;
}
Esempio n. 21
0
void afisare(long *pret, long *prev, long sf, FILE *f) {
	if(sf > -1) {	//parcurg secventa de cadouri incepand de la ultimul
		afisare(pret,prev,prev[sf],f);
		fprintf(f,"%ld ",sf+1);	//afisarea indicilor din vectorul de preturi
	}
}