Unit 1
Unit 1
Writing an algorithm-
• An algorithm can be written in English, like sentences and
using mathematical formulas. Sometimes algorithm
written in English like language is Pseudo code.
Pseudocode
An end-to-end description of an
A step-by-step procedure for
algorithm in formally English (or in
Definition performing the task or solving the
natural language) to convey the logic
problem.
of an algorithm.
Formality Highly formal and very precise. Less formal and more flexible.
• Alphabets a to z, A to Z
• Numeric 0,1 to 9
• Special Symbols {,},[,],?,+,-,*,/,%,!,;,and more
Tokens of ‘C’
Types of C Constants
Ex.: 426
+782
-8000
-7605
Rules for Constructing Real Constants
Real constants are often called Floating Point constants. The real
constants could be written in two forms—Fractional form and
Exponential form.
Following rules must be observed while constructing real
constants expressed in fractional form:
(a) A real constant must have at least one digit.
(b) It must have a decimal point.
(c) It could be either positive or negative.
(d) Default sign is positive.
(e) No commas or blanks are allowed within a real constant.
Rules for Constructing Real Constants
Cont--
Hungarian Notation For Declaring Variable Names
2) Type Indicator: The prefix often denotes the data type of the
variable. For example:
i for integer (int)
f for float (float)
c for character (char)
b for boolean (bool)
ptr for pointer (*)
Cont--
Hungarian Notation For Declaring Variable Names
3) Purpose Indicator: Sometimes, the prefix indicates the purpose
or usage of the variable:
– n for a count or number
– sz for a zero-terminated string (char*)
– p for a pointer
Examples of Hungarian Notation:
• int iCount; (where i indicates integer)
• float fTemperature; (where f indicates float)
• char *pszName; (where psz indicates a pointer to a zero-terminated string)
• BOOL bIsReady; (where b indicates a boolean)
Datatypes in c
Datatypes in c
What is Endianness?
Ex.
deta = alpha * beta / gamma + 3.2 * 2 / 5 ;
C Instructions-Arithmetic Instruction
A C arithmetic statement could be of three types. These
are as follows:
// Documentation
/* description: program to find sum. */
// Link or Preprocessor Section
#include <stdio.h>
// Definition
#define X 20
// Global Declaration
int sum;
Structure of C Program
// Main() Function
int main(void)
{
statement 1;
statement n;
}
// Subprogram
return type fun_name(argument list)
{ statements }
C Input Output
• The general form of printf( ) function is,
printf ( "<format string>", <list of variables> ) ;
Ex:-
printf ( "%f", si ) ;
printf ( "%d %d %f %f", p, n, r, si ) ;
printf ( "Simple interest = Rs. %f", si ) ;
• The general form of scanf( ) function is,
scanf ( "<format string>",&<list of variables> ) ;
Ex:
scanf ( "%d", &p ) ; or scanf ( "%d %d %f", &p, &n, &r ) ;