Posted: Mon Jan 28, 2002 5:42 am
What's the way to do such as 1st 2rd 3rd etc.
mine is that if anything mod 100>10 and <20 then print th
else if anything mod 10=1 then print st,=2 then print nd,=3 then print rd,else print th
is that wrong?? here's my code:
#include <stdio.h>
#include <stdlib.h>
class chumble
{
public:
double num;
int flag;
chumble* link;
};
chumble* head;
chumble* ptr;
chumble* uptr;
chumble* temp;
int top=0;
double humblenum[5842];
void create();
void main()
{
long count=0;
int i=0;
head=(chumble *)malloc(sizeof(chumble));
head->num=1;
head->flag=0;
head->link=NULL;
for(i=0;i<5842;i++)
create();
while(scanf("%ld",&count)!=EOF)
{
if(count==0)
break;
printf("The %d",count);
// down is the output part
if(count%100>10&&count%100<20)
printf("th");
else
{
if(count%10==1)
printf("st");
else if(count%10==2)
printf("nd");
else if(count%10==3)
printf("rd");
else
printf("th");
}
printf(" humble number is %.0llf.n",humblenum[count-1]);
}
}
// create humble numbers
void create()
{
double tempnum;
int tempflag=0;
humblenum[top]=head->num;
tempnum=head->num;
tempflag=head->flag;
temp=head;
head=head->link;
free(temp);
switch(tempflag)
{
case 0:
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*2;
temp->flag=0;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*3;
temp->flag=1;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*5;
temp->flag=2;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*7;
temp->flag=3;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
break;
case 1:
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*3;
temp->flag=1;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*5;
temp->flag=2;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*7;
temp->flag=3;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
break;
case 2:
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*5;
temp->flag=2;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*7;
temp->flag=3;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
break;
case 3:
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*7;
temp->flag=3;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
break;
}
top++;
}
mine is that if anything mod 100>10 and <20 then print th
else if anything mod 10=1 then print st,=2 then print nd,=3 then print rd,else print th
is that wrong?? here's my code:
#include <stdio.h>
#include <stdlib.h>
class chumble
{
public:
double num;
int flag;
chumble* link;
};
chumble* head;
chumble* ptr;
chumble* uptr;
chumble* temp;
int top=0;
double humblenum[5842];
void create();
void main()
{
long count=0;
int i=0;
head=(chumble *)malloc(sizeof(chumble));
head->num=1;
head->flag=0;
head->link=NULL;
for(i=0;i<5842;i++)
create();
while(scanf("%ld",&count)!=EOF)
{
if(count==0)
break;
printf("The %d",count);
// down is the output part
if(count%100>10&&count%100<20)
printf("th");
else
{
if(count%10==1)
printf("st");
else if(count%10==2)
printf("nd");
else if(count%10==3)
printf("rd");
else
printf("th");
}
printf(" humble number is %.0llf.n",humblenum[count-1]);
}
}
// create humble numbers
void create()
{
double tempnum;
int tempflag=0;
humblenum[top]=head->num;
tempnum=head->num;
tempflag=head->flag;
temp=head;
head=head->link;
free(temp);
switch(tempflag)
{
case 0:
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*2;
temp->flag=0;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*3;
temp->flag=1;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*5;
temp->flag=2;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*7;
temp->flag=3;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
break;
case 1:
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*3;
temp->flag=1;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*5;
temp->flag=2;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*7;
temp->flag=3;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
break;
case 2:
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*5;
temp->flag=2;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*7;
temp->flag=3;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
break;
case 3:
temp=(chumble *)malloc(sizeof(chumble));
temp->num=tempnum*7;
temp->flag=3;
temp->link=NULL;
ptr=head;
uptr=NULL;
while(1)
{
if(ptr==NULL)
break;
if(ptr->num>temp->num)
break;
uptr=ptr;
ptr=ptr->link;
}
if(ptr==head)
{
temp->link=head;
head=temp;
}
else
{
temp->link=ptr;
uptr->link=temp;
}
break;
}
top++;
}