+ 2

can anyone tell me the right code please

// the code is here// //this is a program to swap the value os two varibles #include <stdio.h> #include <stdlib.h> int main() { int D,con_of_D,con_of_C; printf("PLease enter a numerical value for D?\n"); scanf("%d",&con_of_D); D=con_of_D; printf("PLease enter a numerical value for C?\n"); scanf("%d",&con_of_C); printf("The value for D is %d\n",&con_of_D ) ; printf("The value for C is %d\n",&con_of_C ); con_of_D=con_of_C; con_of_C=D; printf("Now The value for D is %d\n",&con_of_D ) ; printf("Now The value for C is %d\n",&con_of_C ); return 0; }

14th Jan 2018, 3:55 PM
Rahul guha
Rahul guha - avatar
11 Respostas
+ 4
@BlazingMagpie He has already taken a temporary variable "D"
14th Jan 2018, 4:12 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 3
The code is almost correct. You just need to remove "&" from last 4 printf(s) and it will be working fine :)
14th Jan 2018, 4:09 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 3
"&" is "address of" It is not used when printing values in printf();
14th Jan 2018, 4:10 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 1
You need a temporary variable. Set temp. var to var A Set var A to var B Set var B to temp. var
14th Jan 2018, 4:10 PM
BlazingMagpie
BlazingMagpie - avatar
+ 1
Oh, didn't see it in a wall of code.
14th Jan 2018, 4:14 PM
BlazingMagpie
BlazingMagpie - avatar
+ 1
Swap them without using third variable 😉 https://code.sololearn.com/c23d4OiJdole/?ref=app
14th Jan 2018, 5:41 PM
Shubham Dalal
Shubham Dalal - avatar
+ 1
cool man
14th Jan 2018, 6:25 PM
Rahul guha
Rahul guha - avatar
+ 1
thanks
14th Jan 2018, 6:27 PM
Shubham Dalal
Shubham Dalal - avatar
+ 1
hey man i need some suggestions
14th Jan 2018, 6:27 PM
Rahul guha
Rahul guha - avatar
+ 1
is visual basic better to learn than c
14th Jan 2018, 6:28 PM
Rahul guha
Rahul guha - avatar
+ 1
As someone who had to learn and make script in VBA, I recommend C
14th Jan 2018, 8:13 PM
BlazingMagpie
BlazingMagpie - avatar