C Programming.

1. Computer Programming 2. History of Prog.Language 3. Introduction to C 4. Features of C 5. Starting Turbo C 6. C Tokens 7. Basic requirement of C 8. Comments 9. My First Program in C 10. Line Break 11. C Escape Sequence 12. Constants or Literals 13. Variables in C 14. Data Types in C 15. Range of Data Types in C 16. Declare Variables 17. Reserved Key Words 18. printf( ) statement 19. Chained & Embedded state 20. Prog.to print sum of 2 nos 21. scanf( ) stament 22. print sum & average 23. print Area of Rectangle 24. Area & Circumference of Circle 25. Prg.for Simple Calculator 26. Operators in C 27. Ex. Of Operators 28. Swap two numbers 29. Hierarchy of Operators 30. if( ) statement 31. Prg.to check +ve,-ve or zero 32. if..else statement 33. Prg.to check Odd or Even 34. Prg.to print larger of 2 nos 35. Prg.to print largest of 3 nos 36. Prg.to check divisibility 37. Prg.to check print range 38. for. . . loop statement 39. prg.to print series of nos 40. Prg.to check divisibility 41. prg.to print sum of nos 42. Prg.to print Pyramid 43. prg.for Factorial 44. prg.to fill screen 45. prg.for largest/smallest no 46. prg.to print reverse no 47. prg.to add each digit 48. prg.for sum of factorial 49. prg.for fibonacci series 50. prg.to check Prime nos 51. prg. Prime no from 1 to 100 52. prg.Specified Prime nos 53. while( ) statement 54. do. . While statement 55. goto statement 56. break & continue state. 57. switch case statement 58. Array in C 59. Reverse order using array 60. Ascending/Descending order 61. prg.to search no in Array 62. Double Dimension Array 63. String in C 64. String with spaces in C 65. Print string in reverse 66. prg.to count A,E,I,O,U vowel 67. Function( ) in C 68. Function program examples 69. General Purpose Programs 70. Loan & EMI calculation prg. 71. Table print prg. 72. Leap year program 73. lower to UPPER case prg. 74. Frequency Distribution prg. 75. Bank note calculation prg. 76. Simple Interest prg. 77. Compound Interest prg. 78. Simple Depreciation prg. 79. Reducing bal.Depreciation 80. Marksheet prg. 81. Income Tax prg. 82. Time calculator prg. 83. Distance converter prg. 84. Volume Air Calculation 85. Time to fill Water Tank 86. Salary Calculation prg. 87. Total Sale Calculation prg. 88. Male/Female percentage prg. 89. Library Rent prg. 90. Office Expance prg. 91. Total Salary Calculation prg. 92. Profit or Loss prg. 93. Total Profit/Loss prg. 94. Convert Amt to Word. 95. ASCII Table 96. C Operators 97. C & C++ Reserved Keyword 98. C & C++ Pre-Define Function 99. C Interview Part1 100. C Interview Part2 101. C Interview Part3 102. C Interview Part4 103. C Interview Part5 104. C Interview Part6 105. C Interview Part7 106. C Interview Part8 107. C Interview Part9 108. C Interview Part10 109. C Interview Part11
Pr.Pg Next Pg

switch,case,default statement in C tutorials

  • The switch statement is a multi-way decision-making construct that tests wheather an expression matches one of a number of constant values and branches accordingly.

  • The switch statement is a neater alternative to using else-if statements where multi-way decision making is involved.

  • The expression must be enclosed in parentheses, and the body of the switch statement must be enclosed in braces.

  • Statements can be single or multiple statements with or without braces.

  • The values with case should be constants.The expression is evaluted and the resultant value is compared with each of the values given with case.

  • If any of the values match,the statements following the case, till break, are executed.

  • If none of the case values match the result of expression , then the statements following default,which is optional, are executed.

  • The keyword break is used to delimit the scope of the statemants under a particular case.

 

Syntax:

 

switch(expression)

{

case value 1:

statements ;

break ;

case value 2:

statements ;

break ;

default :

statements ;

}


 

C Program example of Switch case Enter month number and print month in character

Sam Sir

// Program name : test060.c

// example of Switch case Enter month number and print month in character

#include <stdio.h>

#include <conio.h>

void main()

{

int mno;

clrscr();

printf( "Enter month number from 1 to 12 : ");

scanf("%d",&mno);

 

switch(mno)

{default:

printf("Month number not within 1 to 12 \n"); break;

case 1:

printf("January\n"); break;

case 2:

printf( "February\n"); break;

case 3:

printf("March\n"); break;

case 4:

printf("April\n"); break;

case 5:

printf("May\n"); break;

case 6:

printf("June\n"); break;

case 7:

printf("July\n"); break;

case 8:

printf("August\n"); break;

case 9:

printf("September\n"); break;

case 10:

printf("October\n"); break;

case 11:

printf("November\n"); break;

case 12:

printf("December\n");

}

getch();

}

Output

Enter month number from 1 to 12 : 8

August

 

Enter month number from 1 to 12 : 3

March

 

Enter month number from 1 to 12 : 15

Month number not within 1 to 12

 

 

C Program to Enter Month in number and Print no of days for that month

Sam Sir

// Program name : test061.c

//WAP to Enter Month in number and Print no of days for that month

#include <stdio.h>

#include <conio.h>

void main()

{

short mno;

printf("Enter month number from 1 to 12: ");

scanf("%d",&mno);

switch(mno)

{default:

printf("Month no is Not within 1 to 12");

break;

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

printf(" 31 Days in month"); break;

case 4:

case 6:

case 9:

case 11:

printf("30 Days in month"); break;

case 2:

int yr;

printf("Input year in 4 digit : ");

scanf("%d",&yr);

if(yr%4==0&&yr%100!=0||yr%400==0)

printf("29 Days as Leap Year");

else

printf("28 Days in Month") ;

}

}

Output

Enter month number from 1 to 12 : 3

31 Days in month

 

Enter month number from 1 to 12 : 6

30 Days in month

 

Enter month number from 1 to 12 : 2

Input year in 4 digit : 2012

29 Days in month

 

Enter month number from 1 to 12 : 2

Input year in 4 digit : 2014

28 Days in month

 


 

C Program to enter character and print enter character is Vovel or not

Sam Sir

// Program name : test062.c

// WAP to enter character and print enter character is Vovel or not

#include <stdio.h>

void main()

{

char ch;

printf("Enter a character : ");

scanf("%c", &ch);

switch(ch)

{

case 'a':

case 'A':

case 'e':

case 'E':

case 'i':

case 'I':

case 'o':

case 'O':

case 'u':

case 'U':

printf("%c is a Vowel.\n", ch);

break;

default:

printf("%c is not a Vowel.\n", ch);

}

}

 

Output

Enter a character : U

U is a vowel

 

Enter a character : C

C is not a vowel

 

  • The program decides if a letter entered as input is a vowel or not.

  • The program starts with defining a character variable called ch. The value of ch is accepted as input

  • The next statement switch(ch) checks that letter entered is vowel or not by checking that letter entered is a,A,e,E,i,I,o,O,u,U or not.

  • If alphabet entered is a vowel then statements, will print it is a vowel message, and break statement will transfer control out of switch block.

  • If user enter any character other than vowel, it will execute default message, enter character is not vowel.

Pr.Pg border                                              Next Pg