Breaking News

Programs in C (in Turbo C) - Snippets-1

Programs in C (in Turbo C)
Snippets-1

Programs in C (in Turbo C) - Snippets-1


Program 1: Program to print Hello

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
/*Header file section*/
#include <stdio.h>
#include <conio.h>
/*Starting of the function main*/
main()
{
/*Function To Clear Screen*/
clrscr();
/*Application Part*/
printf("\n\n Hello);
getch();
}
/*Ending of the program*/


Program 2Program to use Escape Sequences like \n, \t, \a, \b, \v

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <stdio.h>
#include <conio.h>
/*Starting of the function main()*/
main()
{
/*Function To Clear Screen*/
clrscr();
/*Application Part*/
printf("\n The use of \\n is \n B ");
printf("\n The use of \\v is \v B ");
printf("\n The use of \\t is \r B ");
printf("\n The use of \\r is \r B ");
printf("\n The use of \\a is \a B ");
printf("\n The use of \\b is \b B ");
getch();
}


Program 3Program that accept a character in UPPER CASE and then convert it into LOWER CASE character using the ASCII value



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<stdio.h>
#include<conio.h>
/* main*/
main()
{
/*Local Variable Declaration*/
char ch;
/*Clear the Screen */
clrscr();
/*------------- */
printf("Enter the character in UPPER CASE :\t");
scanf("%c",&ch);
printf("\nThe LOWER CASE of %c \t is \t%c",ch, ch+32);
getch();
}


Program 4: Program that accept a character in LOWER CASE and then convert it into UPPER CASE character using the ASCII value

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include <stdio.h>
#include <conio.h>
main()
{
 char ch;
 clrscr();
 printf("Enter the character in LOWER CASE :\t");
 scanf("%c",&ch);
 printf("\nThe UPPER CASE of character %c is \t%c",ch,ch-32);
 getch();
}


Program 5: Program that accept a character in UPPER CASE and then convert it into LOWER CASE character by using tolower( )

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
main()
{
 char ch;
 clrscr();
 printf("Enter any UPPER CASE character : \t");
 scanf("%c",&ch);
 printf("\n\nThe LOWER CASE of character %c is\t %c",ch,tolower(ch));
 getch();
}



Program 6: Program that accept a character in LOWER CASE and then convert into UPPER CASE by using toupper( )

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include <stdio.h>
#include <conio.h>
#include <ctype.h>

main()
{
char ch;
clrscr();

printf("Enter Any LOWER CASE character : \t");
scanf("%c",&ch);
printf("\n\nthe UPPER CASE of %c\t is \t%c",ch,toupper(ch));
getch();
}


Program 7: Program to get a number from user in integer& print the SQUARE OF NUMBER

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include <stdio.h>
#include <conio.h>
main()
{
 int num;
 clrscr();
 printf("Enter the number : \t");
 scanf("%d",&num);
 printf("\n\nThe SQUARE of %d is \t%d",num, num * num);
 getch();
}