473,326 Members | 2,815 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,326 software developers and data experts.

how to write a program to get next odd number memory (limit 400 bytes)

4
i tried this code but it is more than 400 bytes

#include<stdio.h>
int main()
{
int x[4],i;
for(i=0;i<4;i++)
{
scanf("%d",&x[i]);//to get all numbers from user
}
for(i=0;i<4;i++)
{
if(x[i]%2==0)//to get the next odd number
x[i]++;
}
for(i=0;i<4;i++)
{
printf("%d\n",x[i]);//to print odd numbers
}
return 0;
}
Aug 26 '10 #1
10 2775
newb16
687 512MB
It's 280 bytes even with comments.
Aug 26 '10 #2
aaasss
4
and if the memory limit (100 bytes) how can i solve this problem???
please help me!!!
Aug 26 '10 #3
newb16
687 512MB
Can you describe the problem somewhat more detailed than "get next odd number memory" ? At least what user is expected to enter and what is supposed to be output.
Aug 27 '10 #4
aaasss
4
Given an integer 1 <= N <= 10000,you have to print the next odd number.



Input
The input file consists of series of numbers one in each line.The input is terminated by EOF.

Output
The next odd number.

Example
Input:
5
2
6
17

Output:
7
3
7
19



Take care about your fingers, do not use more than 100 bytes of code
Aug 27 '10 #5
aaasss
4
this is the problem and i hope that you help me solve it
Aug 27 '10 #6
Nepomuk
3,112 Expert 2GB
OK, well here are some tips about saving space:
1. The 3 loops could be merged, doing all of the task in just one loop.
2. Instead of that if-clause, you could use shorter syntax. Let me give you an example:
Expand|Select|Wrap|Line Numbers
  1. int a = 3;
  2. int b = a<10 ? 1 : 2; // this means: if a<10 is true, then the expression in brackets will result in 1, otherwise in 2
So, if you adapt that, you can save some space.

Oh, and the tasks tells you that the series of numbers is terminated by EOF, not that you have exactly 4 numbers. So read them in one by one and operate on them or take them as arguments for the program.

One more thing: If I enter 3, should it give me 3 (which is an odd number) or 5 (which is the next highest odd number)?

Greetings,
Nepomuk
Aug 27 '10 #7
weaknessforcats
9,208 Expert Mod 8TB
Maybe I'm missing something, but printing out the odd numbers is:

Expand|Select|Wrap|Line Numbers
  1. printf("%d", x[i]);
where (x[i] % 2) != 0.

Put this in a loop controlled by i and you are done.
Aug 27 '10 #8
donbock
2,426 Expert 2GB
Are negative numbers allowed in the input file?
What is the next odd number for -5 (is it -3 or -7)?
Aug 30 '10 #9
johny10151981
1,059 1GB
try this
Expand|Select|Wrap|Line Numbers
  1. next_odd=current_numb+(current_numb%2)+1;
  2.  
It will always give you the next odd number.....
Aug 30 '10 #10
donbock
2,426 Expert 2GB
Prior to C99, the behavior of the "%" operator was implementation-dependent when either operand was negative. A portable solution ought to work around this limitation (or negative values ought to be trapped).
Aug 30 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kenton Smith | last post by:
I am using a shared server and the max PHP memory limit is set at 10MB. I can not change this. I would like to resize uploaded JPG images. I have tried many different scripts using the GD libs,...
0
by: Dave 2 | last post by:
Yes, another memory limit question. Our PHP application is running with PHP 4.3.9 running in CGI mode under Windows IIS 5. When a user tries to download a file that is 'too large', the...
1
by: 1944USA | last post by:
I have a C# application written as a Windows Service. It spawns a number of threads, each thread has very large memory intensive processes running on it. I can keep adding threads as long as the...
0
by: Tomas | last post by:
I have two questions: (1) How (if possible) can you, with ASP.NET (and with the IIS 5 included with win2000) specify an maximum limit of the memory that a web application may consume, as an...
10
by: Vic Spainhower | last post by:
Hello, I have a php program that is building a grid (HTML table) from a MySQL database. The problems started when I added a dropdown menu to the grid and when I did the form buttons would not...
3
by: sadanjan | last post by:
Hi , Appreciate if someone can clarify if database Share Memory Limit (2 GB ) in Unix 32 bit boxes is the top limit for all the databases put together in a database or is it for each of the...
6
by: =?Utf-8?B?U3RlZmFuIEJhcmxvdw==?= | last post by:
Unable to get the private bytes memory limit for the W3WP process. The ASP.NET cache will be unable to limit its memory use, which may lead to a process restart. Error: 0x80070005 ...
8
by: Nehil | last post by:
When a process is started three segments are created : 1) Text. 2) Stack. 3) Data. The size of First two is fixed and their upperlimit is fixed by the compiler. (Plz correct if i'm wrong) Now...
6
by: howa | last post by:
Suppose the file is stored in "upload_tmp_dir ", so why I need to increase the memory limit? If I want to upload 100 MB, how large should I set? Thanks.
4
by: =?Utf-8?B?U3ZlbiBXLg==?= | last post by:
Hi Newsgroup, I am developing a C# Windows Forms application that launches processes within a background worker.. The processes seem to have a memory limit of about 278mb. Some proccesses...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.