Performing arithmetic operations using pointers.

#include<stdio.h>
#include<string.h>
main()
{
int y,x;
printf("Enter x and y to perform arithmetic operations on it.\n");
scanf("%d",&x);
scanf("%d",&y);
int *p,*q;
p=&x;
q=&y;
int a,b,c,d;
a=(*p+*q);
b=(*p)-(*q);
c=(*q)*(*p);
d=(*p)/(*q);
printf("Addition=%d Subtraction=%d Multipication=%d Divide=%d",a,b,c,d);

}

 

 

Output [Click to enlarge]:

Arithmetic

 

 

Sorting strings.

Program:

#include<stdio.h>
main()
{
    int i,j,n;
    char str[20][20],temp[20];
    puts("Enter the no. of string to be sorted");
    scanf("%d",&n);
    printf("Enter the %d strings\n",n);
    for(i=0;i<=n;i++)
    {
        gets(str[i]);
    }
    for(i=0;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            if(strcmp(str[i],str[j])>0)
            {
                strcpy(temp,str[i]);
                strcpy(str[i],str[j]);
                strcpy(str[j],temp);
            }
        }
    }
    printf("The sorted string is:");

    for(i=0;i<=n;i++)
    {
        puts(str[i]);
    }

}

 

 

Output: [Click to enlarge.]:

Sort