re online c expression to print 1-100 numbers

X

Xavier Serrand

write a online c expression to print 1 -100 numbers with out using
control statements/structures, jumps-conditional/unconditional.given
the program dont modify and solve

You can do it with recursion and ... stop when exception ... glups ...

void prn100(int n)
{
double t;
printf("%i\n", n);
t = 1 / (100 - n);
prn100(n+1);
}

With my poor english i don't exaclty know what "program solve" means ... if
it is required the program stop well ... my way is not a correct one ...

Xavier
 
S

santosh

Xavier said:
You can do it with recursion and ... stop when exception ... glups ...

void prn100(int n)
{
double t;
printf("%i\n", n);
t = 1 / (100 - n);
prn100(n+1);
}

With my poor english i don't exaclty know what "program solve" means ... if
it is required the program stop well ... my way is not a correct one ...

What exactly do you do with t? What will be the value of n upon first
entering prn100 - 1 or 100? And there's no termination condition for
the recursive calls.
 
X

Xavier Serrand

santosh said:
What exactly do you do with t? What will be the value of n upon first
entering prn100 - 1 or 100? And there's no termination condition for
the recursive calls.



void prn100(int n)
{
double t;
printf("%i\n", n);
t = 1 / (100 - n);
prn100(n+1);
}


void main (int argc, char ** argv)
{
prn100(1);
}

when reaching 100 ... there will be a divid by zero fault... ending the
program (a crash issue)... ok it's horrible ...

xavier
 
S

santosh

Xavier said:
void prn100(int n)
{
double t;
printf("%i\n", n);
t = 1 / (100 - n);
prn100(n+1);
}


void main (int argc, char ** argv)

As per the C Standard main needs to return an int, unless your
implementation happens to define and document other forms.
{
prn100(1);
}

when reaching 100 ... there will be a divid by zero fault... ending the
program (a crash issue)... ok it's horrible ...

A divide by zero causes undefined behaviour. Under most conditions it
results in program termination, but it need not necessarily be so.
It's possible to set up the system to allow your program to continue
running.
 
R

Richard Heathfield

santosh said:
Xavier Serrand wrote:


As per the C Standard main needs to return an int, unless your
implementation happens to define and document other forms.

Since people in comp.lang.c are not constrained to using implementations
that document void main (of which there are very few, if any), code
posted here as advice to others should not rely on those others having
a particular implementation characteristic that is not only not
guaranteed but not even particularly common.

Despite the weasel words of the Standard, void main programs are not
clc-conforming.
 
B

bobby

You can do it with recursion and ... stop when exception ... glups ...

void prn100(int n)
{
double t;
printf("%i\n", n);
t = 1 / (100 - n);
prn100(n+1);

}

With my poor english i don't exaclty know what "program solve" means ... if
it is required the program stop well ... my way is not a correct one ...

Xavier

i wiil explain clear
given problem is
int 1=1;
int main()
{
/*your expresssion here*/
printf("%d",i);
return 0;
}
this is tha actuall code with modifying this u have to write a online
expression that gives output 1 -100 num that too with out using
control structures,control statements,conditional jumps
altough way of solving problem is wright but i want a online
expression,fun calling is not a epression
 
S

santosh

bobby said:
i wiil explain clear
given problem is
int 1=1;
int main()
{
/*your expresssion here*/
printf("%d",i);
return 0;
}
this is tha actuall code with modifying this u have to write a online
expression that gives output 1 -100 num that too with out using
control structures,control statements,conditional jumps
altough way of solving problem is wright but i want a online
expression,fun calling is not a epression

If this is an exercise given to you as part of a course, I suggest you
discontinue it immediately. I also suggest that you take some time to
improve your English. I'm not saying this to be insulting. Your post
hardly makes sense.
 
R

Richard

santosh said:
If this is an exercise given to you as part of a course, I suggest you
discontinue it immediately.

What? And he will magically pass his course because "Santosh from c.l.c
told me not to bother doing it". I'm sure as he sits, jobless, in years
to come he will thank you for making him realise his tutor is not top
flight. But meanwhile back in the real world .....
 
A

Army1987

i wiil explain clear
given problem is
int 1=1;
int main()
{
/*your expresssion here*/
printf("%d",i);
return 0;
}
this is tha actuall code with modifying this u have to write a online
expression that gives output 1 -100 num that too with out using
control structures,control statements,conditional jumps
altough way of solving problem is wright but i want a online
expression,fun calling is not a epression
Yes, a function call is an expression. And there is no way to
produce output without calling any function.
 
S

santosh

Richard said:
What? And he will magically pass his course because "Santosh from c.l.c
told me not to bother doing it". I'm sure as he sits, jobless, in years
to come he will thank you for making him realise his tutor is not top
flight. But meanwhile back in the real world .....

I didn't tell him to sit jobless. The exercise is terrible and is
likely an indicator of the overall quality of the course. I'm sure the
OP can enroll with better courses. Even a self-taught approach with a
good book like K&R2 is likely to be better.
 
R

Richard

santosh said:
I didn't tell him to sit jobless. The exercise is terrible and is
likely an indicator of the overall quality of the course. I'm sure the
OP can enroll with better courses. Even a self-taught approach with a
good book like K&R2 is likely to be better.

Look, for goodness sake, at the VERY most you should advise him to
*possibly* mention the weakness of the example with his tutor. He might
even get extra points if the tutor is open minded enough to realise his
error. What you advise is ridiculous - he will end up getting kicked off
his course. Bad examples can and do happen. And since he is not a C
programmer yet, I somehow feel he is not equipped to select a better
course. And, unfortunately, in the real world, "self taught from K&R2"
doesn't hold much sway in that first vetting of CVs in newbie grad land.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top