0% found this document useful (0 votes)
11 views

Module-1 PPS Notes

Introduction to C Programming.

Uploaded by

rohanks2703
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Module-1 PPS Notes

Introduction to C Programming.

Uploaded by

rohanks2703
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Module – 1: Introduction to C-Programming

ALGORITHMS: Algorithm is a step-by-step procedure of solving the given problem, which


defines a set of instructions to be executed in a certain order to get the desired output. Algorithms
are generally created independent of underlying languages, i.e. an algorithm can be implemented
in more than one programming language.

An algorithm should have the following characteristics:

• Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases),
and their inputs/outputs should be clear and must lead to only one meaning.
• Input − an algorithm should have 0 or more well-defined inputs.
• Output − an algorithm should have 1 or more well-defined outputs, and should match the
desired output.
• Finiteness − Algorithms must terminate after a finite number of steps.
• Feasibility − should be feasible with the available resources.
• Independent − an algorithm should have step-by-step directions, which should be
independent of any programming code.

Example-1: Algorithm to find area of circle


Input: radius of circle
Output: Area of circle based on given radius
• Step-1: read the radius “r”
• Step-2: Compute the area of circle
Area = 3.14*r*r
• Step-3: print the computed area of circle
Example-2: Algorithm to add two numbers
Input: Two numbers “a” and “b”
Output: Result after addition of two given numbers
• Step-1: read two numbers “a” and “b”
• Step-2: Computation
Result = a+b
• Step-3: print the computed result

FLOWCHART: A flowchart is a type of diagram that represents a workflow or process. A


flowchart can also be defined as a diagrammatic representation of an algorithm, a step-by-step
approach to solving a task.
• The flowchart shows the steps as boxes of various kinds, and their order by connecting the
boxes with arrows. This diagrammatic representation illustrates a solution model to a given
problem.

Basic Flowchart Symbols are as follows:

Example-1: Flowchart to find area of circle


Example-2: Flowchart to add two numbers

PSEUDO-CODE: The pseudo code in C consists of words and phrases that make pseudo
code looks similar to the program but not a program. Pseudo codes are written with respect to a
programming language, but programming language syntax or grammar is not strictly followed.

• Pseudocode is made up of two words, ‘pseudo’ and ‘code’. Pseudo means imitation and code
refer to instructions, written in a programming language.

• The pseudo-code is neither an algorithm nor a program. pseudo-code is a semi-formal


description of the steps to be carried out by the computer, including Steps that are to be
repeated and decisions that are to be made but it constructs/models and maybe even look like
programming code.

Example:

IF (Age >18) THEN


Eligible to Vote
ELSE
Not Eligible to Vote
ENDIF
Advantage of Pseudo Code in C is easier and simpler to understand by the programmers of all
types.
BASIC STRUCTURE OF C-PROGRAM

• Documentation section - The documentation section consists of a set of comment lines


giving the name of the program, the author and other details, which the programmer
would like to use later.

• Link section - The link section provides instructions to the compiler to link functions
from the system library.

• Definition section - The definition section defines all symbolic constants.

• Global declaration section - There are some variables that are used in more than one
function. Such variables are called global variables and are declared in the global
declaration section that is outside of all the functions. This section also declares all the
user-defined functions.

• main () function section - Every C program must have one main function section. This
section contains two parts; declaration part and executable part. The declaration part
declares all the variables used in the executable part. There must be at least one
statement in the executable part. These two parts must appear between the opening and
closing braces. The program execution begins at the opening brace and ends at the
closing brace. The closing brace of the main function is the logical end of the program.
All statements in the declaration and executable part end with a semicolon.

Example-1: C Program to compute area of circle


#include<stdio.h>
void main()
{
float radius, area;
printf("Enter the radius of Circle : \n");
scanf("%d", &radius);
area = 3.14 * radius * radius;
printf("Area of Circle : %f", area);
}

Example-2: C Program to compute simple interest


#include<stdio.h>
void main()
{
int p,n,r,si;
printf("Enter Principle, Rate of interest & Time :\n");
scanf("%d %d %d",&p,&r,&n);
si=(p*n*r)/100;
printf("Simple Interest is :%d",si);
}
C-TOKENS: The characters that can be used to form words, numbers & expressions
depend upon the computer on which the program is run. The characters are grouped into the
following categories: Letters(A…Z, a….z), Digits (0…9), Special
characters(%,&,:,;,*,!,#,<,>,?,=,”,/,\) & Whitespaces.

The smallest individual units in C program are known as “C Tokens”.


• Keywords - Every word used in a C program is classified as either a keyword or as an
identifier. A keyword in C is a reserved word which has a specific meaning. Keywords
in C cannot be used as identifiers. Keywords serve as the basic building blocks for
program statements
Keywords in C are always in lowercase. ANSI C supports 32 keywords which are
listed below:

• Identifiers - refer to the names of variables, functions and arrays. These are user-
defined names and consist of sequence of letters and digits, with a letter as a first
character. Both uppercase and lowercase letters can be used, although lowercase letters
are generally used. The underscore character is also permitted in identifiers.
There certain rules while writing identifiers. They are as follows:
1) First character must be an alphabet or underscore.
2) Must consist of only letters, digits or underscore.
3) Only first 31 characters are significant.
4) Cannot use a keyword.
5) Must not contain white space.

• Constants in C- Constants are fixed values, which do not change during the execution
of a program. C supports several types of constants, which are as shown below:
“Integer Constant” refers to a sequence of digits. Generally in programs, the number
systems used are: decimal, octal and hexadecimal. “Real Constants” integer numbers are
not sufficient to represent quantities that vary continuously, such as distances, height,
prices etc. These quantities are represented by numbers containing fractional parts like
25.234. Such numbers are called as real or floating point constants.

• Strings – “Single Character Constants” or character constant contains a single character


enclosed in between single quotes. Some valid examples of character constants are: ‘f’, ‘A’,
‘/’, ’;’, ‘ ‘, ‘4’. The character constant ‘4’ is not equal to the number 4. “String Literals or
String Constants” A sequence of characters that are enclosed between double quotes is
known as a string literal or string constant. The characters in a string literal can be either
letters, digits or special symbols or white spaces. Some valid examples of string constants
are: “hai”, “hEllO”, “hi5”, “Wel come” etc.

VARIABLES IN C: A variable is a placeholder for holding a value in the main memory


(RAM). As the name implies, the value in the variable can change at any point of execution of
the program.

For using variables in our programs, there are essentially two steps:

1) Declare the variable

2) Initialize the variable

• Before using a variable in the program, we have to declare the variable. The syntax for
declaring a variable in a program is as shown below:

datatype variable-name;

• The “type” in the above syntax represents the data type. The “variable-name” is the
identifier. There are certain rules that must be followed while writing the variable name.
• Rules for Variables Name –
➢ A variable name must always start with an alphabet (letter) or an underscore ( _ ).
➢ The variable name must not be more than 31 characters. The suggested length of a
variable name is 8 characters.
➢ C is case sensitive. So, the variable name “average” is different from
“AVERAGE”.
➢ Keywords must not be used for declaring variables.
➢ White spaces are not allowed within the variable name.
• Initializing a Variable – After declaring the variable, we can assign a value to the variable.
This process of assigning a value to the variable is known as initialization. Syntax for
initializing a variable is as shown below:
variable-name = value;
The value we assign to the variable depends on the data type of the variable.
int a;
a=10;
The declaration and initialization can be combined into a single line as shown below:
int a=10;

DATA TYPES IN C: A data type specifies the type of value that we use in our programs. A
data type is generally specified when declaring variables, arrays, functions etc.

In ANSI C, the data types are divided into three categories. They are:

1) Primitive or Fundamental data types

2) User-defined data types

3) Derived data types

• Primitive or Fundamental data types - The primitive data types in ANSI C are as shown in
the below diagram:
• User-Defined data types - ANSI C allows the users to define identifiers as their own data
types, based on the already existing primitive or fundamental data types. This concept is
known as “type definition” and the data types thus created are known as user-defined data
types.
We can create user-defined data types in two ways:

1) By using the “typedef” keyword

typedef int rollno;

rollno r1, r2;

2) By using the “enum” keyword

enum identifier{value1, value2… valuen};

enum days{sun,mon,….sat}

• Derived data types - The data types which are created using the already existing primitive or
fundamental types are known as derived data types. Examples of derived data types in C are:
Arrays, Functions, Structures, Unions & Pointers.

CONSTANTS IN C: As the name suggests the name constants is given to such variables or
values in C programming language which cannot be modified once they are defined.

There can be any types of constants like integer, float, octal, hexadecimal, character constants
etc. In C program we can define constants in two ways as shown below:

1) Using #define preprocessor directive

2) Using a const keyword

• #define preprocessor directive - This directive is used to declare constant variable or any
value. We can use this to declare a constant as shown below:

#define identifierName value

identifierName: It is the name given to constant.

value: This refers to any value assigned to identifierName.

Example: #define PI 3.14 #define CLASS_SIZE 62 #define charVal ‘G’

• const keyword - Using const keyword to define constants is as simple as defining variables,
the difference is you will have to precede the definition with a const keyword.

const datatype identifierName=value;


datatype: type of data stored in place of value.

identifierName: It is the name given to constant.

value: This refers to any value assigned to identifierName.

Example: const int intVal = 10; const float floatVal = 4.14;

Declaring a variable as volatile: By declaring a variable as volatile, its value may be


changed at any time by some external source.

ex: volatile int date;

The value of data may be altered by some external factors. When we declare a variable as
volatile, the compiler will examine the value of the variable each time it is encountered to see
any external alteration has changed the value.

Overflow and Underflow: Problem of data overflow and underflow occurs when the value
of a variable is either too big or too small for the type to hold. The largest value that a variable
can hold also depends on the machine. An overflow normally results in the largest value,
whereas an underflow results in zero. C does not provide any warning or indication of integer
overflow. It simply gives incorrect results.

OPERATORS & EXPRESSIONS: An operator is a symbol that tells a computer to


perform certain mathematical or logical operations. Operators are used in programs to
manipulate data and variables. Generally the usage of an operator is as shown below:

Operand1 Op Operand2

Operand1 and operand2 can be either data or variables or expressions. Op is the operator. In C,
based on the number of operands on which an operator can operate, the operators are divided
into three types namely:

1) Unary

2) Binary

3) Ternary

Different Types of Operators: In C, based on the functionality, operators are classified into
8 categories. They are:

1) Arithmetic Operators (+,-,*,/,%)

2) Relational Operators(<,>,==,!=,>=,<=)
3 )Logical Operators(&&,||,!)

4) Assignment Operators(=,+=,-=,*=,/=,%=)

5) Increment and Decrement Operators (++,--)

6) Conditional Operators(?)

7) Bitwise Operators(&,|,^,~,<<,>>)

8) Special Operators(, & sizeof)

• Arithmetic Operators - C provides all the basic arithmetic operators as shown below. The
arithmetic operators can operate on any built-in data type in C.

• Relational Operators - In C, whenever there is a need to compare two values and make a
decision based on the outcome of the comparison, we use relational operators. The relational
operators are generally used in decision making statements like if, else if and in looping
statements like for, while, do while etc. Relational operators always evaluates to 0 (false) or 1
(true).

• Logical Operators - The relational operators are used to compare at most two values i.e.
testing one condition. To test more than one condition, we use logical operators along with
relational operators. The logical operators always evaluates to either 0 or 1 like relational
operators.

• Assignment Operators - The assignment operators are used to assign value of an expression
to a variable. The general assignment operator is = (equal). In C, there are some special
assignment operators known as shorthand operators. The syntax of shorthand operators is as
shown below:
var op=exp;

• Increment/Decrement Operators - The increment and decrement operators provided by C


are used to increment or decrement the operand by a value of one. Both the increment and
decrement operators are unary operators. There are two variations in increment/decrement
operators

1) pre-increment/decrement(++var/--var)

2) post-increment/decrement(var++/var--)

When pre increment is applied, the value of the variable is incremented by one first and then
that value is used for evaluation of the expression. When post increment is applied, the value of
the variable is used in the evaluation of the expression and after the expression is evaluated, the
value of the variable is incremented by a value of one.

• Conditional Operator - The conditional operator “? :” in C, is a ternary operator, which


operates on three operands. This operator is used to construct conditional expressions of the
form:

exp1?exp2:exp3;
In the above syntax, exp1, exp2 and exp3 refer to expressions.It evaluates the exp1 first and then
based on the result of the exp1 it evaluates either exp2 or exp3. If the result of exp1 is true or
non-zero, then exp2 is executed or if the result of exp1 is false or zero, then exp3 is executed.

• Bitwise Operator’s - C supports a set of operators which operate at bit-level. These operators
are known as bitwise operators. The bitwise operators are used for testing a bit, setting a bit,
complementing a bit or for shifting the bits to left or right. The bitwise operators available in
C are as shown below:

• Special Operator’s - C supports some special operators such as comma “,” operator, sizeof
operator, address “&” operator, pointer operator “*” and some others. The comma “,”
operator is used to combine multiple related expressions together. A comma separated list of
expressions is evaluated from left to right and the value of the right most expression is the
value of the combined expression. The sizeof operator computes the size of an expression or
variable or constant or a data type.

The general syntax of sizeof operator is as shown below:

sizeof(operand);

The operand can be either a value or variable or data type or an expression.

EXPRESSION EVALUATION IN C: Expressions are evaluated based on operator


precedence and associativity rules when an expression contains more than one operator. Every C
operator has a precedence (priority) associated with it. This precedence is used to determine how
an expression involving more than one operator is evaluated.

The operators at the higher level of precedence are evaluated first. The operators in the same
level of precedence are evaluated from left to right or from right to left, based on
the associativity property of an operator.

In the below table we can look at the precedence levels of operators and also the associativity of
the operators within the same level. Rank 0 indicates the lowest precedence and Rank 14
indicates highest precedence.
TYPE CASTING/ CONVERSION: Typecasting is converting one data type into another
one. It is also called as data conversion or type conversion.

'C' programming provides two types of Data conversion operations:

1) Type Conversion

2) Type Casting

• Type Conversion – C automatically converts any intermediate values to the proper type so
that the expression can be evaluated without losing any significance.
• Type casting - There are some scenarios in which we may have to force type conversion.
Suppose we have a variable div that stores the division of two operands which are declared as
an int data type.

(Type_name) expression;

Examples: x = (int)7.5 a = (int)21.3/(int)4.5 b = (double)sum/n y = (int)(a+b)

z = (int)a + b
Type casting or conversion hierarchy:

MATHEMATICAL FUNCTIONS:
INPUT-OUTPUT FUNCTIONS: There are two types of a console I/O functions:
1) Formatted input-output function

2) Unformatted input-output function

The major difference is that formatted function allows us to format the input from the keyboard
and the output to be displayed on the screen.

1) Unformatted Input-Output Functions: Unformatted input and output functions are


only work with character data type. Unformatted input and output functions do not require
any format specifiers. Because they only work with character data type.

• getchar() function is used to get/read a character from keyboard input.


var_name = getchar();

• putchar() function is used to write a character on standard output/screen.


putchar(var_name);
Example: char x;
x = getchar();
putchar(x);

• gets() function can read a full string even blank spaces presents in a string. But, the scanf()
function leave a string after blank space space is detected. The gets() function is used to get
any string from the user.
gets(var_name);
• puts() function prints the charater array or string on the console. The puts() function is
similar to printf() function, but we cannot print other than characters using puts() function.
puts(var_name);
Example:
char c[25];
printf("Enter your Name : ");
gets(c);
puts(c);

2) Formatted Input-Output Functions: In C programming language the output is


printed using printf() statement.

There are two simple forms of printf() statement:

• That has a literal string, a sequence of characters within quotation marks.

Syntax: printf(“string”);

Example: printf(“GOD”);

• That has literal string, conversion specifier and any or all of the following: variables,
constant and expressions values to be printed.

Syntax: printf (“format specifier / format string”,list of variables);

Example: printf(“%d%f”,x,y);

C provides scanf function in the stdio.h header file. Using this function we can read values from
the keyboard and assign the values to variables. The syntax of scanf function is as shown below:

scanf(“control string”,&var1,&var2……)

The control string specifies the type of value to read from the keyboard and the ampersand
symbol & is an operator to specify the address the variable(s).

Example: scanf(“%d %f %d”, &a, &b, &c);

scanf(“%c”,&h);

scanf(“%s”, name);

scanf(“%d”,&a[i]);
SELECTION OR BRANCHING STATEMENTS: The C statements that transfer the
control from one place to other place in the program with or without any condition are called
branching or selection statements.

The selection / branching statements can be classified into two categories:

1] Conditional Control /Branch Statements: Conditional branching statements that alter the
sequence of execution of the program based on some condition are called Conditional branching
statements/ selection statements /decision statements.

Conditional Control /Branch Statements are as follows: simple if (single selection), if-else (two
way selection), Nested if (multiple if statements), else –if ladder (multi-way selection), switch (
multi-way selection).

2] Unconditional Control /Branch Statement: The statements that alter the sequence of
execution of the program based on some uncondition are called Unconditional branching
statement.

Unconditional Control /Branch Statements are as follows: Goto Statement, break Statement,
continue Statement and return Statement.

CONDITIONAL BRANCHING STATEMENTS:

a) If Statement(Simple If): : It is basically a two way decision statement it is used in


conjunction with an expression. It is used to execute a set of statements if the condition is
true. If the condition is false it skips executing those set of statements.

The syntax and flow chart of if statement is as illustrated below:

Example: Program to determine whether a person is eligible to vote using if.


#include<stdio.h>

void main()

int age;

printf(“ Enter the age :”);

scanf(“%d”,&age);

if(age>=18)

printf(“You are eligible to vote”);

b) If-else Statement: : It is an extension of if statement .It is used to execute any one set of
two set of statements at a time. If condition is true it executes one set of statements otherwise
it executes another set of statements.

The syntax and flow chart of if-else statement is as illustrated below:

Example: Program to determine whether a person is eligible to vote using if-else statement.
#include<stdio.h>

void main()

{
int age;

printf("Enter the age");

scanf("%d",&age);

if(age>=18)

printf("You are eligible to vote");

else

printf("not eligible");

c) Nested If-else Statement: : When a series of decisions are involved we may have to use
more than one if else statement in nested form. The nested if else statements are multi
decision statements which consist of if else control statement within another if or else control
statement.

The syntax and flow chart of nested if-else statement is as illustrated below:

Example: Program to find the largest of three numbers using Nested if else statement
#include<stdio.h>

void main()

int a,b,c ;

printf("Enter the values of a,b and c\n");

scanf("%d %d %d",&a,&b,&c);

if (a>b)

if (a>c)

printf(" %d is largest \n", a);

else

printf("%d is largest \n",c);

else

if(b>c)

printf(" %d is largest \n",b);

else

printf("%d is largest \n",c);

d) If-else ladder (Multi-way Selection): In addition to two-way selection, most


programming languages provide another selection concept known as multi way selection.
Multi-way selection chooses among several alternatives.

When an action has to be performed based on many decisions, then this Statement is used when
more than one if-else statements are used in a sequence, it is called as if-else ladder.

• Syntax of if-else ladder:

if( condition-1)

statement-1;
else if( condition-2)

statement-2;

else if( Condition-3)

statement-3;

else if( condition n)

statement-n;

else

default-statement;

Statement-x;

• Disadvantage: difficult to understand and modify when problem is big, which can be
overcome by using switch Statement.
Example: Program to print the grade obtained by the student based on the given table using else-
if ladder.

#include<stdio.h>

void main()

int marks;

printf("Enter the marks \n");

scanf("%d",&marks);

if(marks>=0 && marks<=39)

printf("Grade F\n");

else if (marks>=40 && marks<=49)

printf("Grade E\n");
else if (marks>=50 && marks<=59)

printf("Grade D\n");

else if (marks>=60 && marks<=69)

printf(" Grade C\n");

else if(marks>=70 && marks<=79)

printf("Grade B\n");

else if (marks>=80 && marks<=89)

printf("Grade A\n");

else if (marks>=90 && marks<=100)

printf("Outstanding\n");

else

printf("Invalid Entry \n");

e) Switch Statement (Multi-way Selection): It is a multi-way decision making control


statement used to make a selection between many alternatives. It is also known as switch
case break and default statement.
• Syntax of Switch Statement:

switch (choice/expression)

case value1:block1;

break;

case value2: block2;

break;

case value n: blockn;

break;

default : default_block ;

next Statement;
The value of choice or expression is always an integer value/Character. If the value of choice or
expression is 1 then block1 statements will get executed. After executing the respective block the
control comes outside the switch statement because of the break statement. If no case values
matches with the value of the choice, then the default block will get executed before exiting
switch statement.

• Switch Statement Rules:


1) A switch statement begins with the switch keyword that followed by a value expression
in the parenthesis( ).
2) It is a combination of multiple case labels that must be separated by the break statement.
3) Every case label contains a constant value that is matched against the value, which is
specified in the switch expression.
4) If the value is matched, the statements of that case label are executed.
5) In addition, we can specify the default label, which is executed when the value specified
in the switch expression, does not match with the given case labels.

Example: Program to simulate simple calculator using switch statement


#include<stdio.h>
void main()
{
float a,b,res;
char op;
printf("Enter an Expression\n");
scanf("%f %c %f",&a,&op,&b);
switch(op)
{
case '+' : res=a+b;
printf(“result=%f”,res);
break;
case '-' : res=a-b;
printf(“result=%f”,res);
break;
case '*' : res=a*b;
printf(“result=%f”,res);
break;
case '/' : res=a/b;
printf(“result=%f”,res);
break;
case '%' : res= (int)a % (int)b;
printf(“result=%d”,res);
break;
default : printf("Invaild operator\n");
break;
}
}
Additional Programs on Branching Statements:
1) C Program to find the largest of 2 numbers.
#include<stdio.h>
void main( )
{
int a, b;
printf(“Enter two numbers: ”);
scanf(“%d %d”, &a, &b);
if(a>b)
{
printf(“A is largest”);
}
else
{
printf(“B is largest”);
}
}

2) C Program to check whether a given number is Odd or Even.

#include<stdio.h>
void main( )
{
int num;
printf(“Enter number: ”);
scanf(“%d”, &num);
if(num%2==0)
{
printf(“Even Number”);
}
else
{
printf(“Odd Number”);
}
}

3) C Program to check whether a given student is pass/fail.


#include<stdio.h>
void main( )
{
int marks;
printf(“Enter the marks: ”);
scanf(“%d”, &marks);
if(marks>=35)
{
printf(“Pass”);
}
else
{
printf(“Fail”);
}
}

4) C Program to find the roots of quadratic equation.


#include<stdio.h>
#include<math.h>
void main( )
{
float a, b, c, disc, root1, root2, real, imag;
printf("Enter a,b,c values \n");
scanf("%f %f %f",&a, &b, &c);
disc=(b*b)-(4*a*c);
if((a==0) && (b==0))
{
printf("Invalid co-efficients \n");
}
else if(a==0)
{
printf("Linear equation \n");
}
else if(disc==0)
{
printf("The roots are Real and Equal \n");
root1=-b/(2*a);
root2=-b/(2*a);
printf("Root1=%f \t Root2=%f",root1,root2);
}
else if(disc>0)
{
printf("The roots are Real and distinct \n");
root1=(-b+sqrt(disc))/(2*a);
root2=(-b-sqrt(disc))/(2*a);
printf("Root1=%f\t Root2=%f",root1,root2);
}
else
{
printf ("The roots are Real and Imaginary \n");
real=-b/(2*a);
imag=sqrt(fabs(disc))/(2*a);
printf ("Root1=%f + i %f \n”, real, imag);
printf ("Root2=%f - i %f \n”, real, imag);
}
}

5) C Program to check whether a given alphabet is vowel or consonant using switch


statement.
#include<stdio.h>
void main( )
{
char alph;
printf(“Enter the alphabet: ”);
scanf(“%c”, &alph);
switch(alph)
{
case ‘a’: printf(“Vowel”);
break;
case ‘e’: printf(“Vowel”);
break;
case ‘i’: printf(“Vowel”);
break;
case ‘o’: printf(“Vowel”);
break;
case ‘u’: printf(“Vowel”);
break;
default: printf(“consonant”);
break;
}
}

6) C Program to print the name of the day using switch statement.


#include<stdio.h>
void main( )
{
int day;
printf(“Enter the day: ”);
scanf(“%d”, &day);
switch(day)
{
case 1: printf(“Monday”);
break;
case 2: printf(“Tuesday”);
break;
case 3: printf(“Wednesday”);
break;
case 4: printf(“Thrusday”);
break;
case 5: printf(“Friday”);
break;
case 6: printf(“saturday”);
break;
case 7: printf(“sunday”);
break;
default: printf(“invalid entry”);
break;
}
}

You might also like