C

Monday, 26 June 2017

Program to access an array using a pointer

#include<stdio.h>
main()
{        
          int a[]={10,20,30,40,50};
          int i,* j;
           j=a;
           clrscr();
          for(i=0;i<5;++i)
          {
                   printf("\nElement no. is %d and address is                                 %u",*j,j);
                   j++;
          }

}

Program to demonstrate use of pointer to pointer


#include<stdio.h>
#include<conio.h>
main()
{
          int a=5,*b,**c;
          clrscr();
          b=&a;
          c=&b;
          printf("address of a= %d\n",a);
          printf("address of a= %d\n",*b);
          printf("adrress of a= %d\n",**c);
          printf("adrress of b= %u\n",b);
          printf("adrress of b= %u\n",c);
          printf("address of c= %u\n",&c);

}

Program to demonstrate use of union


#include<stdio.h>
main()
{
          union a

          {
                 short int i;
                   char ch[2];

          };

          union a key;

          key.i=512;
          clrscr();
          printf("key.i=%d\n",key.i);
          printf("key.ch[0]=%d\n",key.ch[0]);
          printf("key.ch[1]=%d\n",key.ch[1]);
          return 0;

}

Program showing Whether given String Is Palindrome Or Not

#include<stdio.h>
#include<string.h>
main()
{
          char  s1[20],s2[20];
          clrscr();
          printf("Enter a string");
          gets(s1);
          strcpy(s2,s1);
          strrev(s2);
          if((strcmp(s1,s2))==0)
                   printf("String is a palindrome");
          else
                   printf("String is not a palindrome");

}

Monday, 19 June 2017

Simple 'C' language programming

The C programming language is a structure oriented programming language, developed at Bell Laboratories in 1972 by Dennis Ritchie. C programming language features were derived from an earlier language called “B” (Basic Combined Programming Language – BCPL). C language was invented for implementing UNIX operating system. In 1978, Dennis Ritchie and Brian Kernighan published the first edition “The C Programming Language” and commonly known as K&R C. In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C. The resulting definition, the ANSI standard, or “ANSI C”, was completed late 1988.



Write a program to draw a circle using mid-point circle drawing algorithm.

#include<iostream.h> #include<graphics.h> #include<conio.h> void drawcircle(int x0, int y0, int r) {         ...