[code:1]#include<stdio.h>
#include<stdlib.h>
typedef struct _razlomak{
int br,naz;
struct _razlomak *next;
} razlomak;
razlomak *delate( razlomak *first, int x, int y){
razlomak *t,*pom;
if (!first) return NULL;
if (first->br*y==first->naz*x){
t=first->next;
free(first);
return t;}
else
{ t=first;
while (t->next->br*y!=t->next->naz*x && t->next)
t=t->next;
if (t->next)
{ pom=t->next;
t->next=pom->next;
free(pom);
return first;}
if (t->next==NULL)
return first;}
}
int main(){
razlomak *first=NULL,*novi,*t,*pom;
while (1){
novi=(razlomak*)malloc(sizeof(razlomak));
scanf("%d", &novi->br);
scanf("%d", &novi->naz);
if (novi->naz==0)
break;
if (first==NULL)
pom=first=novi;
if (first)
pom=pom->next=novi;}
pom->next=NULL;
first=delate(first,3,2);
for( t=first; t!=NULL; t=t->next)
printf("%d/%d\n", t->br, t->naz);
system("pause");
return 0;}
[/code:1]
Ako netko ima volje i zelje nac gresku,bila bi zahvalna.. vec se 2 sata mucin i ne vidin vise sta je dobro sta nije.Hvala
Kod: | #include<stdio.h>
#include<stdlib.h>
typedef struct _razlomak{
int br,naz;
struct _razlomak *next;
} razlomak;
razlomak *delate( razlomak *first, int x, int y){
razlomak *t,*pom;
if (!first) return NULL;
if (first->br*y==first->naz*x){
t=first->next;
free(first);
return t;}
else
{ t=first;
while (t->next->br*y!=t->next->naz*x && t->next)
t=t->next;
if (t->next)
{ pom=t->next;
t->next=pom->next;
free(pom);
return first;}
if (t->next==NULL)
return first;}
}
int main(){
razlomak *first=NULL,*novi,*t,*pom;
while (1){
novi=(razlomak*)malloc(sizeof(razlomak));
scanf("%d", &novi->br);
scanf("%d", &novi->naz);
if (novi->naz==0)
break;
if (first==NULL)
pom=first=novi;
if (first)
pom=pom->next=novi;}
pom->next=NULL;
first=delate(first,3,2);
for( t=first; t!=NULL; t=t->next)
printf("%d/%d\n", t->br, t->naz);
system("pause");
return 0;}
|
Ako netko ima volje i zelje nac gresku,bila bi zahvalna.. vec se 2 sata mucin i ne vidin vise sta je dobro sta nije.Hvala
|