Saturday, September 15, 2012

Program to check the number for Palindrome using C language

#include<stdio.h>
#include<conio.h>
main()
{
int n,t,s=0,r;
printf("\n Enter any number");
scanf("%d",&n);
t=n;
while(n>0)
{
r=n%10;
s=(s*10)+r;
n=n/10;
}
if(t==s)
printf("%d is a palindrome number",t);
else
printf("%d is a not palindrome number",t);
getch();
}

Sunday, September 2, 2012

Guess The output of program

#include<stdio.h>
main()
{
int a=10;
printf("\n %d %d",++a,a++);
getch();
}

Observation: The printf statement get executed from the right side. so first the a will be printed as it is and then it gets incrimented and then again incrimented and the a value is printed means second a incrimented twice before it gets printed.

#include<stdio.h>
main()
{
int *p;
printf("sizeof(*p)=%d ,sizeof(p)=%d",sizeof(*p),sizeof(p));
getch();
}

Saturday, September 1, 2012

Armstrong number program using C language

Armstrong number: A number is called armstrong number when the sum of quebs of individual digits of a number is equal to the number itself. To write the program we need to seperate the individual digits we can do this by first modular division and division by 10. Consider the example 153 the individual digits are 1,5,3 sum of quebs of individual digits are 153 and the number itself is 153.

Program
#include<stdio.h>
main()
{
int n,r,t,s=0;
printf("\n Enter the number");
scanf("%d",&n);
t=n;
while(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(s==t)
printf("\n %d is armstrong number",t);
else
printf("\n %d is not armstrong number",t);
getch();
}

Asterisks Graph program using C language

#include<stdio.h>
main()
{
int i,j,r;
printf("\n Enter number of rows");
scanf("%d",&r);
for(i=0;i<r;i++)
{
for(j=0;j<i+1;j++)
{
printf("* \t");
}
printf("\n");
}
getch();
}

Perfect number Program using C language


#include<stdio.h>
main()
{
int n,i=1,s=0;
printf("\n Enter the number");
scanf("%d",&n);
do
{
if(n%i==0)
{
s=s+i;
}
i++;
if(s>n)
break;
}while(i<n);
if(s==n)
printf("\n %d is perfect number",n);
else
printf("\n %d is not perfect number",n);
getch();
}

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...