Special C Programs



Dear learners,

Following is the list of special C programs. These are programs where some special function or logic is used.


Program related to Security



Observe the following interesting C program.



Printing formatted output using ASCII value.

#include<stdio.h>
int main()
{
  int i;

  for(i=0; i<10; i++)
            printf("%c",174);
  printf(" HELLO STUDENTS ");
  for(i=0; i<10; i++)
            printf("%c",175);
           
  printf("\n\n");
           
  for(i=0; i<10; i++)
            printf("%c",176);
  printf(" HELLO STUDENTS ");
  for(i=0; i<10; i++)
            printf("%c",176);
           
  printf("\n\n");
           
  for(i=0; i<10; i++)
            printf("%c",257);
  printf(" HELLO STUDENTS ");
  for(i=0; i<10; i++)
            printf("%c",258);
  return 0;          
}

Output of the Program:




C program to print memory occupied by int, float and char variables.

#include<stdio.h>

int main()
{
  int i;
  float f;
  char ch;

  printf("Size of int variable: %d \n",sizeof(i));
  printf("Size of float variable: %d \n",sizeof(f));
  printf("Size of char variable: %d \n",sizeof(ch));
  return 0;
}

Output of the Program:

Size of int variable: 4
Size of float variable: 4
Size of char variable: 1

Note: Output of the program may be different on your computer...




C program to use Arrow keys.

#include<stdio.h>
int   main() 
 int chr1, chr2; 
 printf("Press any arrow key...\n"); 
 chr1 = getch(); 
 if (chr1 == 0xE0) //to check scroll key interrupt
 { 
  chr2 = getch();  //to read arrow key
  switch(chr2) 
  { 
   case 72: printf("UP ARROW KEY PRESSED\n"); 
            break; 
   case 80: printf("DOWN ARROW KEY PRESSED\n"); 
            break; 
   case 75: printf("LEFT ARROW KEY PRESSED\n"); 
            break; 
   case 77: printf("RIGHT ARROW KEY PRESSED\n"); 
            break;
   default: printf("OTHER KEY PRESSED: %d %d\n", chr1, chr2);   
            break; 
  }; 
 } 
 return 0;
}

Output of the Program:

Press any arrow key...
UP ARROW KEY PRESSED



20 comments:

  1. Good collection of special C programs.

    ReplyDelete
  2. Replies
    1. Enjoy the power of self learning...Jeetendra...

      Delete
  3. nice programs very useful for reference

    ReplyDelete
  4. Nice Programs Sirrr....Good For reference

    ReplyDelete
    Replies
    1. Good...keep exploring this site for more interesting C language programs

      Delete
  5. Nice blog for self-learning...

    ReplyDelete
  6. Great special C Programs....Do post more programs related to graphics..

    ReplyDelete
  7. It is really useful for preparation...

    ReplyDelete
  8. Awesome blog for c programming.........
    It is Really help for Developing my logic Rearing programming languages
    Please put some mini projects regarding this...

    Thank You Sir

    ReplyDelete
  9. for c programming interview questions click here https://youtu.be/Uu8AcuJF5FE

    ReplyDelete
  10. Really Useful Contents

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete