Dear learners,
Following is the list of special C programs. These are programs where some special function or logic is used.
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
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 |
No comments:
Post a Comment