How to swap two variables, without using third variable ?
Answers were Sorted based on User's Feedback
Answer / yogendra
a=5
a=5,b=10
a=a+b
a=10+5=15
a=15
b=a-b
b=15-10
b=5
a=a-b
a=15-5
a=10 and b=5
a=10 and b=5
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / praveen kumar kesani
x=10,y=20;
x=x*y;
y=x/y;
x=x/y;
after swapping : x=20,y=10
| Is This Answer Correct ? | 2 Yes | 5 No |
Answer / ruchi
let the two numbers are a & b
a=a+b
b=a-b
a=a-b
let a=5 & b=10
a=a+b=15
b=a-b=15-10=5
b=5
a=a-b=15-5=10
hence a & b become 10 & 5
| Is This Answer Correct ? | 0 Yes | 3 No |
Answer / balusamy
Try this answer for reverse a string
#include<stdio.h>
void main()
{
char array[50] = "thgir si rewsna ym";
int len,i,j,temp;
len = strlen(array);
for(i = 0, j = len - 1; i < j; i++, j--)
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
printf("%s\n",array);
}
| Is This Answer Correct ? | 0 Yes | 4 No |
Answer / smita
suppose a=5 and b=10
a=a*b ==>a=50
b=a/b ==>b=5;
a=a/b ==>a=10;
| Is This Answer Correct ? | 1 Yes | 5 No |
Answer / ashok
The first two answers are correct. Third will FAIL in the
case the second num is 0...Please do not post wrong answer
| Is This Answer Correct ? | 3 Yes | 8 No |
Answer / some guy
declare a fourth variable and use that.
I dont understand why you need to do any of the above ??? if fourth is a problem, declare fifth and so on...
| Is This Answer Correct ? | 2 Yes | 7 No |
Answer / robince kumar
//C++ code..
void main()
{
int number1,number2;
cout<<"Enter 1st number;
cin>>number1;
cout<<"Enter 2nd number;
cin>>number2;
number1=number1*number2;
number2=number1/number2;
number1=number1/number2;
getch();
}
| Is This Answer Correct ? | 0 Yes | 6 No |
char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }
How we print the table of 3 using for loop in c programing?
A program that will create a movie seat reservation. The program will display the summary seats and its status. The user will be ask what seat no. to be reserved, then it will go back again to the summary to display the updated seat status. If the seat no. is already reserved then it will prompt an error message. And also if the input seat no is out of range then it will also prompt an error message. The program is continuously running. Termination of the program will depends on how the programmer will apply. Sample output: Movie Seats Reservation Summary of Seats: Seat 1: Available Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 6 The Seat no. is out of range! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 The Seat no. is already reserved! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 0 GoodBye... Thank You!!!
prog. to produce 1 2 3 4 5 6 7 8 9 10
#ifdef something int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }
Write a program that reads a dynamic array of 40 integers and displays only even integers
what will be the position of the file marker? a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR);
#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }
void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(“%d”,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(“%d”,*cptr); }
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }
void main() { int c; c=printf("Hello world"); printf("\n%d",c); }
Printf can be implemented by using __________ list.