#include<stdio.h>
main()
{
int a,b;
printf("enter the value for a and b\n");
scanf("%d %d",&a,&b);
display(a,b);
}
display(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("%d %d",x,y);
}
void swap(int *a, int *b)
{
// *a ^= *b means *a = *a XOR *b
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
An example: a = 1101, b = 1010 a ^= b ---> a = 0111 b ^= a ---> b = 1101 a ^= b ---> a = 1010
#include <stdio.h>
#include <conio.h>
void swap(int *d1 , int *d2)
{
int temp;
temp=*d1;
*d1=*d2;
*d2=temp;
}
void main()
{
int a,b;
clrscr();
printf("Enter number a:");
scanf("%d", &a);
printf("\nEnter number b:");
scanf("%d", &b);
swap(&a,&b);
printf("\na contain %d",a);
printf("\nb contain %d",b);
getch();
}
#include
void swap( int *a, int *b){
int temp = *a;
*a = *b;
*b = temp;
}
int main(){
int a,b;
printf("Enter the two numbers : ");
scanf("%d%d", &a, &b);
swap(&a, &b);
printf("After swapping; a=%d , b=%d\n", a, b);
return 0;
}
void main()
{
int a,b,c;
printf("\n enter variables");
scanf("\%d,%d",&a&b);
c=a;
a=b;
b=c;
printf("%d%d",a,b);
}
Here's a function that'll swap any two integers:
void swap(int & x, int & y)
{
if( x y ) return;
x ^= y ^= x ^= y;
}
Why don't you write it and post it here and someone will tell you if it is good or offer good advice.
To write a C++ program to display the student details using class and array of object.
12
The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }
If you had an array int numbers[10]; you would do it like this: CODE: int lowestnumber = numbers[0]; for(int i = 0; i < 10; i++){ if(numbers[i] < lowestnumber) lowestnumber = numbers[i]; } END CODE I think this should work, and in the end the variable lowestnumber will hold the lowest value in the ten. Hope this helps.
pointer is a derived datatype which contains memory addresses as their values. program:- #include<stdio.h> #include<conio.h> void main() { int m=5,*p; clrscr(); p=&m; printf("address of variable m is %p",(void *)p); }
choosing a variable to represent one of the unspecified numbers in a problem and using it to write expressions for the other unspecified numbers in the problem.
program to find maximum of two numbers using pointers
write an assembly language program to find sum of N numbers
To write a C++ program to display the student details using class and array of object.
see : Write_a_shell_program_using_the_if-the-else_to_test_whether_a_variable_name_is_a_directory_or_a_file
i need this answer
Yes. int a, b; a= 2; b= 3; a= a+b;
12
The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }
If you had an array int numbers[10]; you would do it like this: CODE: int lowestnumber = numbers[0]; for(int i = 0; i < 10; i++){ if(numbers[i] < lowestnumber) lowestnumber = numbers[i]; } END CODE I think this should work, and in the end the variable lowestnumber will hold the lowest value in the ten. Hope this helps.
swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; }
Please visit http://talentsealed.blogspot.com/2009/10/to-find-sqaure-of-numbers-using-c.htmlfor the answer.