Wednesday, 11 February 2015

Palindrome In c using strcpy

#include
#include

void main()
{
char a[100], b[100];
d:
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");
}

}

C Program to Access Elements of an Array Using Pointer in Ascending Order

#include
#include
void main()
{

int x[size], *p, *q, *r, temp,size;
clrscr();
        printf("Number of elements to be entered:");
        scanf("%d",&size);
p=x;
for(q=p; q
{
printf("\nEnter value:");
scanf("%d", q);
}
printf("\n\nkush\n");
printf("\n\nPrinting the elements in asceding order.......\n");
for(q=p; q
{
for(r=q+1; r
{
if(*q>*r)
{
temp=*q;
*q=*r;
*r=temp;
}
}
}
for(q=p; q
{
printf("%d ", *q);
}
getch();
}

Access Elements of an Array Using Pointer Using C

#include
#include
int main()
{

int i, n;
int *a;

printf("Number of elements to be entered:");
scanf("%d",&n);

a = (int*)calloc(n, sizeof(int));
printf("Enter %d numbers:\n",n);
for( i=0 ; i < n ; i++ )
{
scanf("%d",&a[i]);
}

printf("The numbers entered are: ");
for( i=0 ; i < n ; i++ )
    {
printf("%d ",a[i]);
}
return(0);
}