473,413 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

A C-Program Question

Write a function of type void fn (void)
so that the o/p of the program should be anything other than 20.
(Dont use #define fn()..... )

main() {
int i=20;
fn();
printf("%d \n",i);
}
Nov 13 '05 #1
7 1431
In article <67************************@posting.google.com>, Kotni wrote:
Write a function of type void fn (void)
so that the o/p of the program should be anything other than 20.
(Dont use #define fn()..... )

main() {
That's "int main(void)"
int i=20;
fn();
printf("%d \n",i);
return 0;
}

#include <stdlib.h>

void fn(void)
{
abort();
}
--
Andreas Kähäri
Nov 13 '05 #2
Kotni <mr*****@surffast.com> scribbled the following:
Write a function of type void fn (void)
so that the o/p of the program should be anything other than 20.
(Dont use #define fn()..... ) main() {
int i=20;
fn();
printf("%d \n",i);
}


void fn(void) {
}

The output of the program will be "20 ", i.e. 20 followed by two
spaces.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Nothing lasts forever - so why not destroy it now?"
- Quake
Nov 13 '05 #3


Kotni wrote:
Write a function of type void fn (void)
so that the o/p of the program should be anything other than 20.
(Dont use #define fn()..... )

main() {
int i=20;
fn();
printf("%d \n",i);
}


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void fn(void)
{
int i;

srand((unsigned)time(NULL));
while((i = rand()) == 20);
printf("%d \n",i);
exit(EXIT_SUCCESS);
}

int main() {
int i=20;
fn();
printf("%d \n",i);
return 0;
}

--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 13 '05 #4
Kotni wrote:
Write a function of type void fn (void)
so that the o/p of the program should be anything other than 20.
(Dont use #define fn()..... )

main() {
int i=20;
fn();
printf("%d \n",i);
}


#include <stdio.h>
#include <stdlib.h>

void fn (void)
{
puts("This program recurses too much.\n");
return fn();
}

int main(void)
{
int i = 20;
fn();
printf("%d \n", i);
return EXIT_SUCCESS;
}
Nobody said it had to end successfully.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Nov 13 '05 #5
Thomas Matthews wrote:

Kotni wrote:
Write a function of type void fn (void)
so that the o/p of the program should be anything other than 20.
(Dont use #define fn()..... )

main() {
int i=20;
fn();
printf("%d \n",i);
}


#include <stdio.h>
#include <stdlib.h>

void fn (void)
{
puts("This program recurses too much.\n");
return fn();
}

int main(void)
{
int i = 20;
fn();
printf("%d \n", i);
return EXIT_SUCCESS;
}

Nobody said it had to end successfully.


Nobody said it had to compile successfully, either.

(Hint: What is the type of the expression in the
`return' statement?)

--
Er*********@sun.com
Nov 13 '05 #6
Kotni wrote:
Write a function of type void fn (void)
so that the o/p of the program should be anything other than 20.
(Dont use #define fn()..... )

main() {
int i=20;
fn();
printf("%d \n",i);
}


#include <stdio.h>

void fn()
{
putchar('1');
}

int main(void)
{
int i=20;
fn();
printf("%d \n",i);
return 0;
}

/* Q E D */
--
Lew Pitcher

Master Codewright and JOAT-in-training
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.

Nov 13 '05 #7
Groovy hepcat Kotni was jivin' on 31 Oct 2003 02:09:20 -0800 in
comp.lang.c.
A C-Program Question's a cool scene! Dig it!
Write a function of type void fn (void)
so that the o/p of the program should be anything other than 20.
(Dont use #define fn()..... )

main() {
int i=20;
fn();
printf("%d \n",i);
}


Why repost? We saw this problem the first time you posted it.
Anyhow, how 'bout this?

void fn(void)
{
printf("anything other than ");
}

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
1
by: BCAL | last post by:
Hi, In my perl program i am calling a c_program. This c_program is waiting for input which I generate in my perlscript. How do I pass the perlvariable to my c_program and let the perlscript...
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
6
by: news.tkdsoftware.com | last post by:
I have the following test code. What I have a question about is in Func2Ref. In the pointer example, the last called method is actually the one whom allocated memory for the object and returns...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
6
semanticnotion
by: semanticnotion | last post by:
Hi sir i want to transform the data of one table into another through foreign key but the following error come to my browser Here is my code and data base structure. CREATE TABLE IF NOT...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.