Factorial

#include<stdio.h>
void main(){
	int num,i,fact=1;
	printf("Enter any number:\n");
	scanf("%d",&num);
	for(i=num;i>1;i--){
		fact=fact*i;
	}
	printf("The factorial is %d\n",fact);
}
Advertisements

Prime Number

#include<stdio.h>
#include<math.h>
void main(){
	int num,limit,i,flag=1;
	printf("Enter any number:\n");
	scanf("%d",&num);
	if(num<2){
		flag=0;
	}else if(num==2){
		flag=1;
	}else if(num%2==0){
		flag=0;
	}else{
		limit=sqrt(num);
		for(i=3;i<=limit;i+=2){
			if(num%i==0){
				flag=0;
				break;
			}
		}
	}
	if(flag){
		printf("The number is Prime.\n");
	}else{
		printf("The number is not Prime.\n");
	}
}

Palindrome Number

#include<stdio.h>
void main(){
	int num,temp,rev=0;
	printf("Enter any number:\n");
	scanf("%d",&num);
	for(temp=num;temp>0;temp/=10){
		rev=(rev*10)+(temp%10);
	}
	if(rev==num){
		printf("The number is Palindrome.\n");
	}else{
		printf("The number is not Palindrome.\n");
	}
}