Skip to main content

Posts

Showing posts from July, 2016

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); }

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; } 

Factorial of a number using recursion

#include<stdio.h> int factorial(int n){     if(n>=1){            return factorial(n-1)*n;            }    else{           return 1;           }   } int main(){     int n=0,x;     printf("Enter the number to find factorial\n");     scanf("%d",&n);     x=factorial(n);     printf("factorial of the number is %d",x);     return 0;  }