funny challange

Pages: 12
my school teacher asked me to write a program to enter two number swap their values and display on the screen. Can someone help me in the program but the condition is that i have to make it only with two variables and using void satement
What is the "void statement"?
main void ()
she said that some mathematical will be used.
Last edited on
What is "main void () "?
closed account (Dy7SLyTq)
i could do it with one. (i think he means void main (which should be int main()) although you could use std::swap and not right your own function
When we write a programe after including header file we write this statement like:
#include <iostream.h>
#include <conio.h>

void main ()
{
cout << " understood @vlad from moscow " ;
}
closed account (Dy7SLyTq)
god your compiler must be old
closed account (Dy7SLyTq)
you could go a and b the c of d and write a whole container
/**********************************
With three variable this is the programe
**********************************/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# include <iostream.h>
# include <conio.h>

void main ()
    { 
       float a , b , c ;
       clrscr () ;
       cout << " Enter the value of a = " ;
       cin << a ;
       c = a ;
       a = b ;
       b = c :
       cout << " Swapped results is " << a << " and " << b ;
      getch () ;
    } 


/*************************************
And this is working correctly
************************************/
closed account (Dy7SLyTq)
yeah but that uses three
i want a programe code which uses two variables only.
The code you posted will never work too many errors :(
THERE IS ERROR IN 12TH LINE ONLY
> i want a programe code which uses two variables only.

See: http://en.wikipedia.org/wiki/XOR_swap_algorithm

And pay attention to: http://en.wikipedia.org/wiki/XOR_swap_algorithm#Reasons_for_avoidance_in_practice
closed account (Dy7SLyTq)
line 11, 12, and 9
and line 9
This program can not work correctly. First of all this statement does not do what you think it should do

cin << a ;

and you did not enter values for a and b.:)
Last edited on
and btw how do you swap one value?
i got solution/.... thanx JLBorges
closed account (Dy7SLyTq)
i said i could it with one variable not one value.
Pages: 12