Sunday 23 February 2014

pointer programms

check given string palindrom number or not

#include<stdio.h>
#include<string.h>
int main()
{
    char*str,*rev;
char i,j;
printf("\nEntr  a string");
scanf("%s",str);
for(i=strlen(str)-1,j=0;j>=0;i--,j++)
rev[j]=str[i];
rev[j]='\0';
if(strcmp(rev,str))
printf("\nThe  string is not a palindrme");
else
printf("\nthe string is palindrom");
return 0;


}
//Hexdecimal Equivalent using pointer

#include<stdio.h>
#include<conio.h>
//#include<alloc.h>
int main()
{
    int num,rem[20],*ptr;
    printf("Enter number:\n");
    scanf("%d",&num);
    ptr=rem;
    while(num!=0)
    {
        *ptr=num%16;
        num=num/16;
        ptr++;
    }
    ptr--;
    while(ptr>=rem){
        if(*ptr<10)
        printf("%d",*ptr);
    else
        printf("%c",*ptr+55);
    ptr--;
    }
}







#include<stdio.h>
#include<conio.h>

int main()
{
    long *n,*n1,*n2,*m1,*m2,r;
    printf("this code by ameer hamza if u want more programm plesse vist my blog\n");
    n=(long*)malloc(sizeof(long));
    n1=(long*)malloc(sizeof(long));
    n2=(long*)malloc(sizeof(long));
    m1=(long*)malloc(sizeof(long));
    m2=(long*)malloc(sizeof(long));
    printf("\nEnter  n ");
    scanf("%ld",n);
    *n1=*n2=0;
    *m1=*m2=1;
    while(*n!=0)
    {
        r=*n%10;
        *n=*n/10;
        if(r%2==0)//even
        {
            r=r * *m2;
            *n2=*n2 + r;
            *m2=*m2 * 10;
        }//if
        else
        {
            r=r* *m1;
            *n1=*n1 + r;
            *m1=*m1 * 10;

        }//else
    }//while
    printf("http//letsdoprogramminginc.blogspot.com\n");
    printf("\n n1=%ld n2=%ld",*n1,*n2);
}

//reverse the content of array using pointer at variable loacation
#include<stdio.h>
#include<conio.h>
int main()
{
    int a[20],*ptr1,*ptr2,n,t;
    printf("\nEnter n ");
    scanf("%d",&n);
    //read n number
    printf("Enter %d number\n",n);
    for(ptr1=a;ptr1<=a+n;ptr1++)
    {
        scanf("%d",ptr1);
    }
    //reverse the odder of n numbers
    ptr1=a;
    ptr2=a+n-1;
    while(ptr1<ptr2)
    {
        t=*ptr1;
        *ptr1=*ptr2;
        ptr1++;
        ptr2--;

    }
    printf("\n the resultant array is \n");
    for(ptr1=a;ptr1<=a+n-1;ptr1++)
    {
        printf("%4d",*ptr1);
    }
    printf("for more programms vist my blog\n");
    printf("letsdoprogramminginc.blogspot.com");
   
}

//reverse the content of array using pointer at fixed loacation
#include<stdio.h>
#include<conio.h>
int main()
{
   int *ptr,n,i,j,t,a[100];
   printf("Enter n");
   scanf("%d",&n);
   ptr=a;
   printf("\nEnter %d number \n",n);
   for(i=0;i<n;i++)
   {
       scanf("%d",ptr+i);
   }
   i=0;
   j=n-1;
   while(i<j)
   {
       t=*(ptr+1);
       *(ptr+i)=*(ptr+j);
       *(ptr+j)=t;
       i++;
       j++;
     
   }
   printf("the resultant array is \n");
   for(i=0;i<n;i++)
   {
       printf("%4d",*(ptr+1));
   }
}
         
         
         
         
         
         




No comments:

Post a Comment