Palindrome

Topics: Prime number, Natural number, Decimal Pages: 21 (1937 words) Published: August 26, 2013
PALINDROME
#include <stdio.h>
#include <string.h>

int main()
{
char a[100], b[100];

printf("Enter the string to check if it is a palindrome\n");
gets(a);

strcpy(b,a);
strrev(b);

if( strcmp(a,b) == 0 )
printf("Entered string is a palindrome.\n");
else
printf("Entered string is not a palindrome.\n");

return 0;
}

PRIME NUMBER OR NOT
#include<stdio.h>

main()
{
int n, c = 2;

printf("Enter a number to check if it is prime\n");
scanf("%d",&n);

for ( c = 2 ; c <= n - 1 ; c++ )
{
if ( n%c == 0 )
{
printf("%d is not prime.\n", n);
break;
}
}
if ( c == n )
printf("%d is prime.\n", n);

return 0;
}

ARMSTRONG OR NOT
#include <stdio.h>

int main()
{
int number, sum = 0, temp, remainder;

printf("Enter an integer\n");
scanf("%d",&number);

temp = number;

while( temp != 0 )
{
remainder = temp%10;
sum = sum + remainder*remainder*remainder;
temp = temp/10;
}

if ( number == sum )
printf("Entered number is an armstrong number.\n");
else
printf("Entered number is not an armstrong number.\n");
return 0;
}
OR
#include<stdio.h>
void main()
{
int num,num1,arms=0,rem;

printf("Enter the number:\n");
scanf("%d",&num);
num1=num;
while(num>0)
{
rem=num%10;
arms=arms+rem*rem*rem;
num=num/10;
}
if(num1==arms)
{
printf(" \n%d is an Armstrong number",num1);
}
else
{
printf("\n%d is NOT an Armstrong number",num1);
}

}

HELLO
#include <stdio.h>
#define TRUE 1

int main()
{
while (TRUE)
{
printf("Hello World\n");
}

return 0;
}

COIN
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main(void) {
int toss = 0;
int call = 0;
srand(time(NULL));

toss = rand() % 2;

printf("Say head or tail! press 0 for head and 1 for tail:\n\n");     scanf("%d", &call);
if(call==0 || call==1)
{
if(toss == call)
{
if(toss==1)
printf("You called it correctly ... it is tail\n");             else
printf("You called it correctly ... it is head\n");         }
else
{
if(toss==1)
printf("No way ...it is head !\n");
else
printf("No way ... it is tail!\n");
}
}
else
printf("Invalid call!!!!!\n\n");
return 0;
}

Circle
#include <graphics.h>

main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");

circle(25, 25, 100);

getch();
closegraph();
return 0;
}

PERFECT NUM OR NOT
#include<stdio.h>
int main(){
int num,i=1,sum=0;

printf("Enter a number: ");
scanf("%d",&num);

while(i<num){
if(num%i==0)
sum=sum+i;
i++;
}
if(sum==num)
printf("%d is a perfect number",i);
else
printf("%d is not a perfect number",i);

return 0;
}

TRIANGLE
#include"stdio.h"
int main()
{
int r, i, j, b, num;
printf("How many lines do you want?");
scanf("%d", &r);
b = r;
for(i=0;i<r;i++)
{
num = 1;
for(j=0;j<=i;j++)
{
printf("%d", num);
num = (num * (i-j)/(j+1));
}
printf("\n");
}
}

C Program to...