Shortest C++ code to print odd numbers between 1 and 100
write the shortest code you can write to print all the odd no from 1 to 100?
Note:- Don't use google please
Note:- Don't use google please
Replies
-
gaurav.bhorkarmain( )
{
for (int i = 1; i <= 100; i+=2)
cout << i;
}
I didn't execute it, by the way. -
Manish Goyalcan you think something different
i mean not using this and any modulus operator? -
Reyamain()
{
for(int i=1;i<=100;i++)
{
if(i%2!=0)
cout< }} -
Hussanal Farokemain()
{
pirntf("13579111315........99");
} -
Manish GoyalInteresting
Any other way friends -
gaurav.bhorkar
Haha... but that will hurt your fingers ๐Hussanal Farokemain()
{
pirntf("13579111315........99");
} -
rajesh_smain()
{
for(i=1;i<100;i++)
{
for(j=2;j {
if(i%j!=0)
cout< }
}
} -
PraveenKumar PurushothamanHeard of Structures? Using that we can do in this way... ๐
struct ZeroEven { unsigned num : 1; } int main(){ ZeroEven ze; for (i=0; i<100; i++) { ze.num = i; if (ze.num != 0) cout<Guys, do try this and say! ๐
-
Manish GoyalThis is what i was looking for Nice logic buddy
Any other way -
PraveenKumar Purushothaman
Thanx... ๐goyal420This is what i was looking for Nice logic buddy
Any other way -
rajesh_sis my logic not correct
-
gaurav.bhorkar
Nice solution. I never thought of using bit fields.praveenscienceHeard of Structures? Using that we can do in this way... ๐
struct ZeroEven { unsigned num : 1; } int main(){ ZeroEven ze; for (i=0; i<100; i++) { ze.num = i; if (ze.num != 0) cout<Guys, do try this and say! ๐
-
PraveenKumar Purushothaman
He he ๐ Thanx... ๐gaurav.bhorkarNice solution. I never thought of using bit fields. -
Sreekar B Vmain()
{
int i=1;
while((i<100)&&(i+=2))
printf("%d",i);
} -
simplycoder
#include
//simplycoder int main(int argc,char**argv) { int n=1; while(n<100) { if(n & 1 && printf("%d",n)); n++; } return 0; } -
Kaustubh KatdareWithout wanting to distract this discussion; I think the guys who used print got it all right. Someone gotta beat that!
Or we need to rephrase the problem statement? -
Tim Rossiter
int main(int n) //init n=-1 { (n<99)?(printf("%d\n",main(n+2))):(n=n); //emote is colon left paren return(n); }
-
Kaustubh Katdare#-Link-Snipped-# - You may use [code] .... [/code] tags to enter code without having to deal with emoticons.
-
Tim RossiterThanks
-
Anoop KumarI don't know C++ but here is java logic
void printOddNumbers(int maxLimit) { for(int i=1; i <= maxLimit; i+=2){ System.out.println("Odd : " +i); } }
Number of iterations: maxLimit / 2 ; -
aviiwell here's in Go, if that interests anyone:
package main import "fmt" func main() { for i := 1; i < 100; i+=2 { fmt.Println(i) } }
You are reading an archived discussion.
Related Posts
NPO SvyazProekt (NPO SP) has signed a landmark deal with Newtec to become its first, third party, repair centre for Russia, Ukraine and other CIS countries. The agreement will cover...
came across with this interesting post which surely will get your head thinking of what you really want out of your career and if your career path is IT, will...
๐ ๐
Happy Birthday Kunal! ๐ Have fun!
๐
Guys can anyone help me in finding some automation testing tool through which i can test working of my website?
Note:-Testing tool should be able to insert variety of values
Beyond Boundaries - an online conference for women on 'women leadership' is going to happen on Thursdays.
An online conference especially organized for women to meet inspiring women professionals around...