Skip to main content

Swapping two numbers without using third variable

#include<stdio.h> 
int main(){
      int a,b;
      printf("\n Enter value for A=");
      scanf("%d",&a);
      printf("\n Enter value for B=");
      scanf("%d",&b);
      a=b-a;
      b=b-a;
      a=a+b;
      printf("New values ....");
      printf("A=%d\n",a);
      printf("B=%d\n",b);
      return 0;
} 

Comments

Popular posts from this blog

Program to check whether a number is prime or not.

#include<stdio.h> void main(){     int num,counter,countf=0;     printf("Enter a Number.\n");     scanf("%d",&num);     counter=1;     while(counter<=num){         if(num%counter==0)         countf=countf+1;         counter++;         }    if(countf==2)     printf("Prime.\n");    else      printf("Not Prime.");   } 

Program to check a number is Palindrome or not

#include<stdio.h> int palindrome(int num){ int num1 = num,id,rev; while(num>0){ id = num%10; rev = rev*10+id; num = num/10; } if(rev==num1){ printf("palindrome\n"); } else{ printf("not palindrome\n"); } return 0; } int main(){ int x; printf("Enter the number  to check palindrome\n"); scanf("%d",&x); palindrome(x); }