Post your C/C++ Programs Here

Status
Not open for further replies.

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Are you kidding me? If you'd said Windows I'd have understood the pain. But ... your linux has no compiler? :)) I wouldn't even use it then :p

And we definitely need some sort of a syntax highlighter plugin if a new Programming section is being proposed.
 
Last edited:

zegulas

Traceur
Re: Post ur C/C++ Programs Here

can u ppl plz give me the code to convert any decimal no into a binary no??
in C
 

mehulved

18 Till I Die............
Re: Post ur C/C++ Programs Here

Quiz_Master said:
Couldn't test it as I am on Linux right now and Have no Compiler installed here.
That's a weird statement. gcc is one of the foremost things that is needed to install my distro.
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

Projjwal said:
@aditya.shevade It's very cool ans.Gr8 job ...I was just looking for this ans.
Now do the same thing without using "()" .

I tried to do it using bitwise operators, as per your hint. But could not :-(..... Maybe I am too tired today. Will try it later tonight and see. You please don't post the answer.

(To others, I just told Projjwal , not to post answer. Not to rest of you..... Just in case...)

Aditya
 

Zeeshan Quireshi

C# Be Sharp !
Re: Post ur C/C++ Programs Here

GCC is not included in the default install of Ubuntu btw :p

Batistabomb said:
does anybody had c++ code for converting text to speech
you mean someting like this ?
Code:
using System;
using System.Speech.Synthesis;

namespace HelloSpeechSynthesis
{
    class Program
    {
        static void Main(string[] args)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.SpeakText("Hello, world!");
        }
    }
}

It's in C# though :)
 
Last edited:

quan chi

mortal kombat
Re: Post ur C/C++ Programs Here

well is it possible to program the matrix(the falling numbers in the movie) type programming using c++.
 

Nav11aug

In the zone
Re: Post ur C/C++ Programs Here

@The Binary Search program

doesn't wrk and note tht binary search is only fr sorted arrays
 

Yamaraj

The Lord of Death
Re: Post ur C/C++ Programs Here

aditya.shevade said:
I tried to do it using bitwise operators, as per your hint. But could not :-(..... Maybe I am too tired today. Will try it later tonight and see. You please don't post the answer.

(To others, I just told Projjwal , not to post answer. Not to rest of you..... Just in case...)

Aditya
Temptation. It's here :- a^=b^=a^=b ;)
 
OP
Gigacore

Gigacore

Dreamweaver
Re: Post ur C/C++ Programs Here

@ qwerty, cool programs, and actually the program executes but it, think u enter some values to perform the given task. it does but that dos window will close before showing the output. but when i run it again, i can see the output. help
 

Quiz_Master

* Teh Flirt King *
Re: Post ur C/C++ Programs Here

aditya.shevade said:
^^ I wonder... Which distro do you use Ashwin?

Dyne;bolic, custom edition..... [I am not into linux though... My studies require me to stick with Windows.]

Just found a module for programming though...
Now going to use it.

Intel_Gigacore said:
@ qwerty, cool programs, and actually the program executes but it, think u enter some values to perform the given task. it does but that dos window will close before showing the output. but when i run it again, i can see the output. help

Arre yaar.. read what I previously written...
You will need to press Alt+F5 to view result...
Alternatevly use getch() function just before the end of program (just before "}" , you will need to include 'stdio.h' file in C++ program for this.)

Hope you get me this time.
 
Last edited:

Nav11aug

In the zone
Re: Post ur C/C++ Programs Here

Quiz_Master said:
Alternatevly use getch() function just before the end of program (just before "}" , you will need to include 'stdio.h' file in C++ program for this.)

getch() needs conio.h ,getchar() needs stdio.h
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

Yamaraj said:
Temptation. It's here :- a^=b^=a^=b ;)

I had given up. So I checked....

By the way, can you please explain the working of this? I have no experience whatsoever in bitwise operators :-( And I have a laptop, and the viewing angle was such that I was able to look at the answer without selecting it. :-D

But, digital logic.... I have quite some. So, at lest explain in a logical, if not precedence level manner.

I had no idea that you can use a^=b in C/C++ program.... :-(:-(:-(

Aditya
 

Zeeshan Quireshi

C# Be Sharp !
Re: Post ur C/C++ Programs Here

aditya.shevade said:
I had given up. So I checked....

By the way, can you please explain the working of this? I have no experience whatsoever in bitwise operators :-( And I have a laptop, and the viewing angle was such that I was able to look at the answer without selecting it. :-D

But, digital logic.... I have quite some. So, at lest explain in a logical, if not precedence level manner.

I had no idea that you can use a^=b in C/C++ program.... :-(:-(:-(

Aditya
you should read "The Annotated C++ Reference Manual" by Stroustrup , it gives you really handy tips n tricks and advises you on Efficient Programming styles .
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

^^ Alright. Currently I just finished through that Balagurusamy book, skipping the template programming. The book is OK. Not too good.

So, I am reading professional C++ by Solter and Klepper. And I really like that book. It's upright professional as the title says. The way it explained classes when compared with Balagurusamy's explanation... Balagurusamy is not at all very good.
 

Projjwal

free world from money
Re: Post ur C/C++ Programs Here

@Yamaraj gr8 job 10out of 10

-----------
a^=b^=a^=b is the answare
here ^= means bitwise XOR operation
I am describing it through an example .
Suppose a=12 ; b=32
Now,for bit wise operation convert it to binary
So,
a=001100
b=100000
now,
in ' C' operation done on right to left direction
So, start it from the right most side.
a^=b it's mean a=a^b so, a=001100 XOR 100000 =101100 but the value of b unchanged b=100000
next part
b^=a it's mean b=b^a so, b=100000 XOR 101100 =001100 now the value of a =101100
last part
a^=b it's mean a=a^b so, a=101100 XOR 001100=100000 now the value of b=1100
Now the new value of a & b is
a = 100000 = 32 in decimal
b = 1100 =12 in decimal
--------------------The Full C code is---------------
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
a=12;
b=32;
a^=b^=a^=b ;
printf("\na=%d",a,);
printf("\nb=%d",b);
getch();
}
--------------------------------------------------
@Nav11aug
Not the look of program/algo says this program/algo is good this bad.
the complexity (time,space) of the program/algo decide which one is good & which one is bad.
:)
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

^^ Ow.... those were the shorthand syntaxes..... Alright.... Fine. Understood.

I did not know that bitwise XOR will work bit to bit for every bit.

One last question. What steps did you use to arrive at this logic? I mean, the method used to find out the exact sequence of operations for the change? Did you use any simplification method, like we use k-map or what?

Aditya
 

Projjwal

free world from money
Re: Post ur C/C++ Programs Here

no not k map.XOR is exclusive or means for odd numbers of 1 out put is 1 & for even numbers of 1 output is 0.
now the logic is
1 xor 1=0 xor 1 =1
1 xor 0 =1 xor 1 = 0
0 xor 1 =1 xor 0 = 1
now
0 xor 1=1
1 xor 0 =1
1 xor 1 = 0
sum up formula: a xor b =answer xor a = b
and answer xor b = a
from the ^^ lines u will get a logic that answer of xor between two numbers & xor between answer & any one of the number gives the other one . It's the main logic. so, if u define it in bitwise it will create the algo .

**Here I describe for 1 bit only this operation is happed for all the bit of the number .thats way swap done.
 
Status
Not open for further replies.
Top Bottom