Kaprekar Number

#include<stdio.h>
void main(){
	int num;
	printf("Enter any number:\n");
	scanf("%d",&num);
	if(num%9==1){
		printf("The number is Kaprekar.\n");
	}else{
		printf("The number is not Kaprekar.\n");
	}
}
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");
	}
}

Triangle

#include<stdio.h>
void main(){
	int a,b,c;
	printf("Enter the three sides of a triangle as a b & c:\n");
	scanf("%d%d%d",&a,&b,&c);
	if(a+b>c&&b+c>a&&c+a>b){
		printf("Triangle can be formed.\n");
		if(a==b&&b==c){
			printf("Triangle is Equilateral.\n");
		}else if(a!=b&&b!=c&&c!=a){
			printf("Triangle is Scalene.\n");
		}else{
			printf("Triangle is Isoscles.\n");
		}
	}else{
		printf("Triangle cannot be formed.\n");
	}
}