SlideShare une entreprise Scribd logo
1  sur  25
Computer -- Hardware

                 Input                              Output
Key board       Storage      Program Storage Area
                                                    Storage    Monitor
                 Area                                Area
 Mouse                       Working Storage Area              Printer
Input Devices                                                 Output Devices

                  Primary or Main Memory (RAM)

                Register 1
                Register 2
                  ……
                  ……
                                        Arithmetic
                Register N                 and
                                        Logic Unit


                Secondary Storage Devices
                     Micro Processor
Algorithm: Step by step procedure of solving a particular problem.
Pseudo code: Artificial informal language used to develop algorithms.
Flow chart: Graphical representation of an algorithm.
Algorithm to find whether a number even or odd:
Step1: Begin                                         Step1: START
Step2: Take a number                                 Step2: Read num
Step3: if the number is divisible by2 then           Step3: if(num%2=0) then
            print that number is even                           print num is even
        otherwise print that number is odd                   otherwise
                                                                print num is odd
Step4: End                                           Step4: STOP
(Algorithm in natural language)                      (Algorithm by using pseudo code)

#include<stdio.h>                                                  start
#include<conio.h>                              Flow chart:
main()                                                          read num
{
   int num;
   printf(“Enter any number”);                                   If num           No
                                                 Yes
   scanf(“%d”,&num);                                             %2=0
   if(num%2==0)
       printf(“%d is even”,num);
   else                              print num                                   print num
       printf(%d is odd”,num);
                                      is even                                      is odd
}
(Program in C language)                                        stop
Flow chart symbols
Oval                     Terminal

Parallegram              Input/output

Rectangle                Process

Document                 Hard copy

Diamond                  Decision

Circle                   Connector

Double sided Rectangle   Sub program

Hexagon                  Iteration

Trapezoid                Manual Operation

Cylinder                 Magnetic Disk Storage
Machine Language – Assembly Language – High-Level Language
 1              00000000    00000100   0000000000000000       1         entry main,^m<r2>
 2     01011110 00001100    11000010   0000000000000010       2         sub12 #12,sp
 3              11101111    00010110   0000000000000101       3         jsb   C$MAIN_ARGS
 4              11101111    10111110   0000000000001011       4         moveb $CHAR_STRING_CON
 5     11111000 10101101    11011111   0000000000010010       5
 6              01100010    11011111   0000000000010101       6         pusha1   -8(fp)
 7     11101111 00000010    11111011   0000000000010111       7         pusha1   (r2)
 8     11110100 10101101    11011111   0000000000011110       8         calls     #2,SCANF
 9     00000011 10100010    11011111   0000000000100001       9         pusha1   -12(fp)
10     11101111 00000010    11011111   0000000000100100       10        pusha1   3(r2)
11     01111110 11110100    10101101                          11        calls    #2,SCANF
12     11111000 10101110    11000101   0000000000101011       12        mull3    -8(fp),-12(fp),-
13     00000110 10100010    11111011   0000000000110001       13        pusha    6(fp)
14     11101111 00000010    11111011   0000000000110100       14        calls    #2,PRINTF
15              01010000    11010100   0000000000111011       15        clrl     r0
16                          00000100   0000000000111101       16        ret



1    #include<stdio.h>
2    int main(void)                              The only language the computer can understand is machine
3    {                                           language (binary language).
4       int n1, n2,product;
5       printf(“Enter two numbers : “);          A high level language is an English like language where one
6       scanf(“%d %d”,&n1,&n2);
                                                 instruction typically translates into a series of machine-
7       product = n1 * n2;
8       printf(“%d”,product);
                                                 language instructions.
9       return 0;
1    }                                           A low level language corresponds closely to machine code so
0                                                that a single low-level language instruction translates to a
                                                 single machine language instruction.
Structure of C program
/*Program to find
                                        Documentation Section
   area and perimeter of Circle */
#include<stdio.h>                       Linkage Section
#define PI 3.1415                       Definition Section
float radius;
float area();                           Global Declaration Section
float perimeter();
int main()
{
    float a, p;                         Main Function Section
    printf(“Enter radius : “);
    scanf(“%f”,&radius);                       Local Declaration Part
    a = area();                                Executable Code Part
    p = perimeter();
    printf(“Area of Circle : %f”,a);
    printf(“Perimeter : %f”,p);
}
float area()
                                        Sub Program Section
{
   return (PI * radius * radius);
                                           Function1()
}
                                           Function2()
float perimeter()
                                           ……………
{
                                           FunctionN()
    return (2 * PI * radius);
}
Program Development Steps
1)Statement of Problem                                   4.a)Compilation
   a) Working with existing system and using proper      Translate the program into machine code. This
questionnaire, the problem should be explained           process is called as Compilation. Syntactic errors are
clearly.                                                 found quickly at the time of compiling the program.
  b) What inputs are available, outputs are required     These errors occur due to the usage of wrong
and what is needed for creating workable solution        syntaxes for the statements.
should be understood clearly.                                        Eg: x=a*y+b
2)Analysis                                               There is a syntax error in this statement, since, each
  a) The method of solutions to solve the problem can    and every statement in C language ends with a
be identified.                                           semicolon (;).
  b) We also judge that which method gives best
results among different methods of solution.             4.b)Execution
3)Designing                                              The next step is Program execution. In this phase, we
  a) Algorithms and flow charts will be prepared.        may encounter two types of errors.
  b) Keep focus on data, architecture, user interfaces   Runtime Errors: these errors occur during the
and program components.                                  execution of the program and terminates the program
                                                         abnormally.
4)Implementation
  The algorithms and flow charts developed in the        Logical Errors: these errors occur due to incorrect
                                                         usage of the instructions in the program. These errors
previous steps are converted into actual programs in
                                                         are neither detected during compilation or execution
the high level languages like C.
                                                         nor cause any stoppage to the program execution but
                                                         produces incorrect ouz
Executing a C program
                      #include<stdio.h>
     Text             int main()
                      {                                      Translators are system software
    Editor               …….                 prog1.c              used to convert high-level
                                                                  language program into
    C-compiler                  compiles
                                                                  machine-language code.
                                                             Compiler : Coverts the entire
         010110 100              Syntax            Yes            source program at a time
         …………….
          01011 101
                                 Errors?                          into object code file, and
                                   No                             saves it in secondary storage
                        Object machine code                       permanently. The same
                       adds                   prog1.obj           object machine code file will
      Linker
                                                                  be executed several times,
  00101010
                               Executable                         whenever needed.
  ………….
  01010101                    machine code                   Interpreter : Each statement of
                                             prog1.exe            source program is translated
machine code of
  library file                                                    into machine code and
                        Executes                                  executed immediately.
    C-Runtime
                                                                  Translation and execution of
                          Feeds
                                                                  each and every statement is
                                 Runtime               Yes
             Input               or Logic                         repeated till the end of the
                                 Errors ?                         program. No object code is
                                                                  saved. Translation is
                                                                  repeated for every execution
                                Output                            of the source program.
Character Set of C-Language
Alphabets : A-Z and a-z
Digits : 0-9
Special Symbols : ~ ! @ # $ % ^ & ( ) _ - + = |  { } [ ] : ; “ ‘
                  <>,.?/
White Spaces : space , Horizontal tab, Vertical tab, New Line
               Form Feed.
                C-Language Keywords(C99)
 auto           double         int            struct
 break          else           long           switch
 case           enum           register       typedef
 char           extern         return         union
 const          float          short          unsigned
 continue       for            signed         void
 default        goto           sizeof         volatile
 do             if             static         while
 _Bool          _Imaginary     restrict       _Complex
 inline
C-Tokens
Tokens : The smallest individual units of a C- program are called Tokens.
   Key words, Identifiers, Constants, Operators, Delimiters.
Key words : have a predefined meaning and these meanings cannot be
   changed. All keywords must be written in small letters (except additional
   c99 keywords).
Identifiers : names of variables, functions, structures, unions, macros, labels,
   arrays etc.,
     Rules for define identifiers :
       a) First character must be alphabetic character or under score
       b) Second character onwards alphabetic character of digit or under
   score.
       c) First 63 characters of an identifier are significant.
       d) Cannot duplicate a key word.
       e) May not have a space or any other special symbol except under
   score.
       f) C – language is Case-sensitive.
C-Tokens
Constants : fixed values that do not change during execution of a program.
     Boolean constants : 0 ( false) and 1 (true)
     Character constants :
        only one character enclosed between two single quotes
         ( except escape characters ).
        wide character type - wchar_t - for Unicode characters.
     Integer constants : +123, -3454 , 0235 (octal value),
                          0x43d98 ( hexa - decimal value)
                          54764U, 124356578L, 124567856UL
     Float constants : 0.2 , 876.345, .345623 , 23.4E+8, 47.45e+6
     String Constants : “Hello world” , “Have a nice day!”
     Complex Constants : real part + imaginary part * I ex : 12.3 + 3.45 * I
Operators : a symbol, which indicates an operation to be performed.
    Operators are used to manipulate data in program.
Delimiters : Language Pattern of c-language uses special kind of symbols
: (colon, used for labels) ; (semicolon terminates statement ) ( ) parameter list
       [ ] ( array declaration and subscript ),    { } ( block statement )
   # ( hash for preprocessor directive )     , (comma variable separator )
Data Types ( pre defined )
Type                 Typical Size in Bits    Minimal Range
char                           8             –127 to 127
unsigned char                  8             0 to 255
signed char                    8             –127 to 127
int                            16 or 32      –32,767 to 32,767
unsigned int                   16 or 32      0 to 65,535
signed int                     16 or 32      Same as int
short int                      16            –32,767 to 32,767
unsigned short int             16            0 to 65,535
signed short int               16            Same as short int
long int                       32            –2,147,483,647 to 2,147,483,647
long long int                  64            –(263) to 263 – 1 (Added by C99)
signed long int                32            Same as long int
unsigned long int              32            0 to 4,294,967,295
unsigned long long int         64            264 – 1 (Added by C99)
float                          32            3.4e-38 to 3.4e+38
double                         64            1.7e-308 to 1.7e+308
long double                    80            3.4e-4932 to 1.1e+4932
void                           --            data type that not return any value
Conversion Specifiers
Code   Format
%a     Hexa decimal output in the form of 0xh.hhhhp+d(C99 only)
%s     String of characters (until null zero is reached )
%c     Character
%d     Decimal integer
%f     Floating-point numbers
%e     Exponential notation floating-point numbers
%g     Use the shorter of %f or %e
%u     Unsigned integer
%o     Octal integer
%x     Hexadecimal integer
%i     Signed decimal integer
%p     Display a pointer
%n     The associated argument must be a pointer to integer, This sepecifier causes
       the number of characters written in to be stored in that integer.
%hd    short integer
%ld    long integer
%lf    long double
%%     Prints a percent sign (%)
Back Slash ( Escape Sequence) Characters

Code        Meaning
 b         Backspace
 f         Form feed
 n         New line
 r         Carriage return
 t         Horizontal tab
 "         Double quote
 '         Single quote
          Backslash
 v         Vertical tab
 a         Alert
 ?         Question mark
 N         Octal constant (N is an octal constant)
 xN        Hexadecimal constant (N is a hexadecimal constant)
Increment and Decrement Operators
prefix increment (++a) postfix increment (a++) prefix decrement(- -a) postfix decrement (a- -)


       Executes all Prefix Operations         Before evaluation of expression

           Evaluation of expression

       Executes all Postfix Operations        After evaluation of expression
                                             and before leaving the statement


/* prefix operators */          /* prefix and postfix operators */   /* postfix operators */
#include<stdio.h>               #include<stdio.h>                    #include<stdio.h>
int main() {                    int main() {                         int main() {
   int a = 7, b = 12, c;           int a = 7, b = 12, c;                int a = 7, b = 12, c;
   c = b * (++a) + 5 * (++a);      c = b * (a++) + 5 * (++a);           c = b * (a++) + 5 * (a++);
   printf(“ a = %d”, a);           printf(“ a = %d”, a);                printf(“ a = %d”, a);
   printf(“n b = %d”,b);          printf(“n b = %d”,b);               printf(“n b = %d”,b);
   printf(“n c = %d”,c);          printf(“n c = %d”,c);               printf(“n c = %d”,c);
}                               }                                    }
Output:                         Output:                              Output:
   a=9                             a=9                                  a=9
   b = 12                          b = 12                               b = 12
   c = 153 ( 12 * 9 + 5 * 9)       c = 136 ( 12 * 8 + 5 * 8)            c = 119 ( 12 * 7 + 5 * 7)
Bitwise Logical Operators
& -- Bitwise AND                A           B   A&B         A|B            A^B              ~A
                                 1          1    1            1               0             0
| -- Bitwise OR
                                 1          0    0            1               1             0
^ -- Bitwise XOR                 0          1    0            1               1             1

~ -- Bitwise NOT                 0          0    0            0               0             1

               Bitwise AND                                      Bitwise OR

      A (42) : 00000000 00101010                      A (42) : 00000000 00101010
      B (15) : 00000000 00001111                      B (15) : 00000000 00001111
      -----------------------------------             -----------------------------------
      & (10) : 00000000 00001010                      | (47) : 00000000 00101111
      -----------------------------------             -----------------------------------

               Bitwise XOR                                     Bitwise NOT

      A (42) : 00000000 00101010                      A (42) : 00000000 00101010
      B (15) : 00000000 00001111                      -----------------------------------
      -----------------------------------             ~ (-43) : 11111111 11010101
      & (37) : 00000000 00100101                      -----------------------------------
      -----------------------------------
BITWISE SHIFT OPERATORS
  Bitwise Left Shift ( << )          Bitwise Right Shift ( >> )            Bitwise Right Shift ( >> )
                                           (positive values)                     (negetive values)
A (43) : 00000000 00101011          A (43) : 00000000 00101011           A (-44) : 11111111 11010100
----------------------------------- -----------------------------------   -----------------------------------
A << 2 : 00000000 10101100          A >> 2 : 00000000 00001010           A >> 2 : 11111111 11110101
----------------------------------- -----------------------------------   -----------------------------------
       Note : Right shift operator fills the left vacant fields with ‘zeros’ for positive numbers,
       with ‘ones’ for negative numbers.

Opposite                            TYPE CONVERSION                                 Explicit Type Conversion
  To
                                                                                             (casting)
Gravity
                1.bool
                              2.char                                                                   (forcible)
        (forcible)
                                           3.short int
    .
                                           4.int                                                   .
                                           5.long int                                              .
    .
                                           6.long long int                                         .
    .

                                                               7.float
        (natural)                                                                                      (automatic)
                                                               8.double
                                                               9.long double
Gravity                                                                             Implicit Type Conversion
                                                                                           (automatic)
Precedence and Associativity of Operators
Precdence Group           Operators                          Associativity
(Highest to Lowest )
(param) subscript etc.,     ( ) [ ] –>.                      L R
Unary operators           - + ! ~ ++ – – (type) * & sizeof   R L
Multiplicative            */%                                L R
Additive                  +–                                 L R
Bitwise shift             << >>                              L R
Relational                < <= > >=                          L R
Equality                  = = !=                             L R
Bitwise AND               &                                  L R
Bitwise exclusive OR      ^                                  L R
Bitwise OR                |                                  L R
Logical AND               &&                                 L R
Logical OR                ||                                 L R
Conditional               ?:                                 R L
Assignment                = += –= *= /= %= &= ^=             R L
                          |= <<= >>=
Comma                     ,                                  L R
simple if:         Entry                          if-else:                 Entry

                                                                True       Test           False
                   Test           True                                   Expression
                 Expression                                                  ?
                     ?
              False        True Statement-block
                                                       True-block                     False-block
                                                       Statements                     Statements
              Next statement
                                                                       Next statement


 /* check a citizen is eligible for voting */     /* print a number is even or odd */
 #include<stdio.h>                                #include<stdio.h>
 int main()                                       int main()
 {                                                {
    int age;                                         int number;
    printf(“Enter the age : ”);                      printf(“Enter a number : “);
    scanf(“%d”,&age);                                scanf(“%d”, &number);
    if(age >= 18)                                    if((number %2) == 0)
      printf(“Eligible for voting…”);                   printf(“%d is even number.”,number);
    getch();                                         else
 }                                                      printf(“%d is odd number.”,number);
                                                  }
nested if…else:                      /* check whether a year is leap year or not */
                                                      #include<stdio.h>
                      Entry                           int main() {
                                                         int year;
                       Test                              printf("Enter the year ?");
         False                     True
                     condition1                          scanf("%d",&year);
                         ?                               if((year %100) == 0)
                                      Test               {
                           False                 True         if((year % 400) == 0)
                                    condition2
                                        ?                        printf("%d is leap year.",year);
                                                              else
Statement-3      Statement-2            Statement-1              printf("%d is not leap year.",year);
                                                          } else {
                                                              if((year % 4) == 0)
                                                                 printf("%d is leap year.",year);
                                                              else
              Next statement
                                                                 printf("%d is not leap year.",year);
                                                         }
                                                         getch();
                                                      }
if…else…if :                             /* program to print the grade of student */
                                             #include<stdio.h>
        Entry                                int main() {
                True
                                                int marks;
   Test
 condition1            Statement-1              printf("Enter marks ? ");
     ?                                          scanf("%d", &marks);
False                                           if(marks >= 75)
  Test          True                               printf("Distinction");
condition2             Statement-2              else if(marks >= 60)
    ?                                              printf("First class");
False                                           else if(marks >= 50)
   Test         True                               printf("Second class");
conditionN             Statement-N
                                                else if(marks >= 35)
    ?
                                                   printf("Third class");
                            Next statement      else
                                                   printf("Failed");
                                             }
switch statement :                  /* program to simulate a simple calculator */
                                                #include<stdio.h>
                         Entry                  int main() {
                                                   float a,b;
                   switch                          char opr;
                 expression                        printf("Enter number1 operator number2 : ");
                     ?                             scanf("%f %c %f",&a,&opr,&b);
                                                   switch(opr)
value1      value2           valueN    default     {
                     ……...                            case '+':
                                                         printf("Sum : %f",(a + b));
associate   associate    associate    associate          break;
statement   statement    statement    statement       case '-':
                                                         printf("Difference : %f",(a - b));
                                                         break;
                                                      case '*':
                                                         printf("Product : %f",(a * b));
                                                         break;
                                                      case '/':
                              Exit                       printf("Quotient : %f",(a / b));
                                                         break;
                                                      default:
                Next statement                           printf("Invalid Operation!");
                                                   }
                                                }
Loop Statements
while – (Entry controlled )                     do-while – (Exit controlled )
            Entry
                                                                    Entry


      Test           False
    Condition                                            Body of The loop
       ?
         true                                                 Test          False
  Body of The loop                                         Condition
                                                               ?
                Following Statement                       True          Following Statement
                                                 /* average of 5 numbers */
/* sum of 1 to 10 numbers */
                                                 #include<stdio.h>
#include<stdio.h>
                                                 int main() {
int main() {
                                                    int count = 1;
   int i = 1,sum = 0;
                                                    float x, sum = 0;
   while(i<=10){
                                                    do {
      sum = sum + i;
                                                       printf(“x = “);
      i = i + 1;
                                                       scanf(“%f”,&x);
   }
                                                       sum += x;
   printf(“Total : %d “,sum);
                                                       ++ count;
}
                                                    } while(count <= 5);
                                                    printf(“Average = %f “, (sum/5))
                                                 }
for --                          Entry
Statement
            Initialization Statement
                                                               Increment Statement

                                 False         Test
                                            Condition
                                                ?
                                           True
                                         Body of The loop
       Following Statement

                /* check whether a number is prime or not */
                #include<stdio.h>
                int main() {
                   int n,i,factors = 0;
                   printf("Enter a number : ");
                   scanf("%d",&n);
                   for(i = 1; i <= n; i++) {
                      if((n % i)==0) ++factors;
                   }
                   if (factors == 2)
                      printf("%d is prime number.",n);
                   else
                      printf("%d is not prime number.",n);
                }
Important Functions in math.h
abs(x)       absolute value of integer x
ceil(x)      rounds up and returns the smallest integer greater than or
                      equal to x
floor(x)     rounds down and returns the largest integer less than or
   equal              to x
log(x)       returns natural logarithm
pow(x,y)     returns the value of xy
sqrt(x)      returns square root of x
exp(x)       returns natural anti logarithm
sin(x)       returns sine value where x in radians
cos(x)       returns cosine value where x in radians
tan(x)       returns tangent values where x in radians
fmod(x,y)    calculate x modulo y, where x and y are double
hypot(x,y)   calculate hypotenuse of right angle where x,y are sides.
log10(x)     returns logarithm base 10
www.jntuworld.com
• For More Materials, Text Books, Previous
  Papers & Mobile updates of B.TECH,
  B.PHARMACY, MBA, MCA of JNTU-
  HYD,JNTU-KAKINADA & JNTU-
  ANANTAPUR visit www.jntuworld.com

Contenu connexe

Tendances

Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manualAnil Bishnoi
 
C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo dattaApurbo Datta
 
Chapter Seven(1)
Chapter Seven(1)Chapter Seven(1)
Chapter Seven(1)bolovv
 
C programming session 02
C programming session 02C programming session 02
C programming session 02AjayBahoriya
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLE2MATRIX
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14IIUM
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14IIUM
 
Lecture 2 verilog
Lecture 2   verilogLecture 2   verilog
Lecture 2 verilogvenravi10
 
Verilog overview
Verilog overviewVerilog overview
Verilog overviewposdege
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language samt7
 

Tendances (20)

Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo datta
 
C programming
C programmingC programming
C programming
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
Chapter Seven(1)
Chapter Seven(1)Chapter Seven(1)
Chapter Seven(1)
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
C++ rajan
C++ rajanC++ rajan
C++ rajan
 
System Verilog Tutorial - VHDL
System Verilog Tutorial - VHDLSystem Verilog Tutorial - VHDL
System Verilog Tutorial - VHDL
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14
 
Programming in C
Programming in CProgramming in C
Programming in C
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
 
Lecture 2 verilog
Lecture 2   verilogLecture 2   verilog
Lecture 2 verilog
 
Deep C
Deep CDeep C
Deep C
 
C Programming
C ProgrammingC Programming
C Programming
 
C Programming
C ProgrammingC Programming
C Programming
 
Verilog overview
Verilog overviewVerilog overview
Verilog overview
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
Mp &mc programs
Mp &mc programsMp &mc programs
Mp &mc programs
 

Similaire à Unit1 jwfiles

Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topicsveningstonk
 
C and its errors
C and its errorsC and its errors
C and its errorsJunaid Raja
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and typesimtiazalijoono
 
What is turbo c and how it works
What is turbo c and how it worksWhat is turbo c and how it works
What is turbo c and how it worksMark John Lado, MIT
 
INTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNINTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNBenjaminAnilema
 
Chapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxChapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxAbdalla536859
 
PROGRAMMING IN C.pptx
PROGRAMMING IN C.pptxPROGRAMMING IN C.pptx
PROGRAMMING IN C.pptxSONU KUMAR
 
complete data structure
complete data structurecomplete data structure
complete data structureAnuj Arora
 
Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Getachew Ganfur
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C LanguageAdnan Khan
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxCOMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxdonnajames55
 

Similaire à Unit1 jwfiles (20)

Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
C and its errors
C and its errorsC and its errors
C and its errors
 
C basics
C   basicsC   basics
C basics
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
What is turbo c and how it works
What is turbo c and how it worksWhat is turbo c and how it works
What is turbo c and how it works
 
INTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓNINTRODUCCIÓN A LA PROGRAMACIÓN
INTRODUCCIÓN A LA PROGRAMACIÓN
 
Cinfo
CinfoCinfo
Cinfo
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
First c program
First c programFirst c program
First c program
 
Chapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxChapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptx
 
PROGRAMMING IN C.pptx
PROGRAMMING IN C.pptxPROGRAMMING IN C.pptx
PROGRAMMING IN C.pptx
 
complete data structure
complete data structurecomplete data structure
complete data structure
 
Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxCOMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
 

Plus de mrecedu

Brochure final
Brochure finalBrochure final
Brochure finalmrecedu
 
Filters unit iii
Filters unit iiiFilters unit iii
Filters unit iiimrecedu
 
Attenuator unit iv
Attenuator unit ivAttenuator unit iv
Attenuator unit ivmrecedu
 
Two port networks unit ii
Two port networks unit iiTwo port networks unit ii
Two port networks unit iimrecedu
 
Unit4 (2)
Unit4 (2)Unit4 (2)
Unit4 (2)mrecedu
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)mrecedu
 
Unit6 jwfiles
Unit6 jwfilesUnit6 jwfiles
Unit6 jwfilesmrecedu
 
Unit3 jwfiles
Unit3 jwfilesUnit3 jwfiles
Unit3 jwfilesmrecedu
 
Unit2 jwfiles
Unit2 jwfilesUnit2 jwfiles
Unit2 jwfilesmrecedu
 
Unit7 jwfiles
Unit7 jwfilesUnit7 jwfiles
Unit7 jwfilesmrecedu
 
M1 unit vi-jntuworld
M1 unit vi-jntuworldM1 unit vi-jntuworld
M1 unit vi-jntuworldmrecedu
 
M1 unit v-jntuworld
M1 unit v-jntuworldM1 unit v-jntuworld
M1 unit v-jntuworldmrecedu
 
M1 unit iv-jntuworld
M1 unit iv-jntuworldM1 unit iv-jntuworld
M1 unit iv-jntuworldmrecedu
 
M1 unit iii-jntuworld
M1 unit iii-jntuworldM1 unit iii-jntuworld
M1 unit iii-jntuworldmrecedu
 
M1 unit ii-jntuworld
M1 unit ii-jntuworldM1 unit ii-jntuworld
M1 unit ii-jntuworldmrecedu
 
M1 unit i-jntuworld
M1 unit i-jntuworldM1 unit i-jntuworld
M1 unit i-jntuworldmrecedu
 

Plus de mrecedu (20)

Brochure final
Brochure finalBrochure final
Brochure final
 
Unit i
Unit iUnit i
Unit i
 
Filters unit iii
Filters unit iiiFilters unit iii
Filters unit iii
 
Attenuator unit iv
Attenuator unit ivAttenuator unit iv
Attenuator unit iv
 
Two port networks unit ii
Two port networks unit iiTwo port networks unit ii
Two port networks unit ii
 
Unit 8
Unit 8Unit 8
Unit 8
 
Unit4 (2)
Unit4 (2)Unit4 (2)
Unit4 (2)
 
Unit5
Unit5Unit5
Unit5
 
Unit4
Unit4Unit4
Unit4
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)
 
Unit6 jwfiles
Unit6 jwfilesUnit6 jwfiles
Unit6 jwfiles
 
Unit3 jwfiles
Unit3 jwfilesUnit3 jwfiles
Unit3 jwfiles
 
Unit2 jwfiles
Unit2 jwfilesUnit2 jwfiles
Unit2 jwfiles
 
Unit7 jwfiles
Unit7 jwfilesUnit7 jwfiles
Unit7 jwfiles
 
M1 unit vi-jntuworld
M1 unit vi-jntuworldM1 unit vi-jntuworld
M1 unit vi-jntuworld
 
M1 unit v-jntuworld
M1 unit v-jntuworldM1 unit v-jntuworld
M1 unit v-jntuworld
 
M1 unit iv-jntuworld
M1 unit iv-jntuworldM1 unit iv-jntuworld
M1 unit iv-jntuworld
 
M1 unit iii-jntuworld
M1 unit iii-jntuworldM1 unit iii-jntuworld
M1 unit iii-jntuworld
 
M1 unit ii-jntuworld
M1 unit ii-jntuworldM1 unit ii-jntuworld
M1 unit ii-jntuworld
 
M1 unit i-jntuworld
M1 unit i-jntuworldM1 unit i-jntuworld
M1 unit i-jntuworld
 

Dernier

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Dernier (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Unit1 jwfiles

  • 1. Computer -- Hardware Input Output Key board Storage Program Storage Area Storage Monitor Area Area Mouse Working Storage Area Printer Input Devices Output Devices Primary or Main Memory (RAM) Register 1 Register 2 …… …… Arithmetic Register N and Logic Unit Secondary Storage Devices Micro Processor
  • 2. Algorithm: Step by step procedure of solving a particular problem. Pseudo code: Artificial informal language used to develop algorithms. Flow chart: Graphical representation of an algorithm. Algorithm to find whether a number even or odd: Step1: Begin Step1: START Step2: Take a number Step2: Read num Step3: if the number is divisible by2 then Step3: if(num%2=0) then print that number is even print num is even otherwise print that number is odd otherwise print num is odd Step4: End Step4: STOP (Algorithm in natural language) (Algorithm by using pseudo code) #include<stdio.h> start #include<conio.h> Flow chart: main() read num { int num; printf(“Enter any number”); If num No Yes scanf(“%d”,&num); %2=0 if(num%2==0) printf(“%d is even”,num); else print num print num printf(%d is odd”,num); is even is odd } (Program in C language) stop
  • 3. Flow chart symbols Oval Terminal Parallegram Input/output Rectangle Process Document Hard copy Diamond Decision Circle Connector Double sided Rectangle Sub program Hexagon Iteration Trapezoid Manual Operation Cylinder Magnetic Disk Storage
  • 4. Machine Language – Assembly Language – High-Level Language 1 00000000 00000100 0000000000000000 1 entry main,^m<r2> 2 01011110 00001100 11000010 0000000000000010 2 sub12 #12,sp 3 11101111 00010110 0000000000000101 3 jsb C$MAIN_ARGS 4 11101111 10111110 0000000000001011 4 moveb $CHAR_STRING_CON 5 11111000 10101101 11011111 0000000000010010 5 6 01100010 11011111 0000000000010101 6 pusha1 -8(fp) 7 11101111 00000010 11111011 0000000000010111 7 pusha1 (r2) 8 11110100 10101101 11011111 0000000000011110 8 calls #2,SCANF 9 00000011 10100010 11011111 0000000000100001 9 pusha1 -12(fp) 10 11101111 00000010 11011111 0000000000100100 10 pusha1 3(r2) 11 01111110 11110100 10101101 11 calls #2,SCANF 12 11111000 10101110 11000101 0000000000101011 12 mull3 -8(fp),-12(fp),- 13 00000110 10100010 11111011 0000000000110001 13 pusha 6(fp) 14 11101111 00000010 11111011 0000000000110100 14 calls #2,PRINTF 15 01010000 11010100 0000000000111011 15 clrl r0 16 00000100 0000000000111101 16 ret 1 #include<stdio.h> 2 int main(void) The only language the computer can understand is machine 3 { language (binary language). 4 int n1, n2,product; 5 printf(“Enter two numbers : “); A high level language is an English like language where one 6 scanf(“%d %d”,&n1,&n2); instruction typically translates into a series of machine- 7 product = n1 * n2; 8 printf(“%d”,product); language instructions. 9 return 0; 1 } A low level language corresponds closely to machine code so 0 that a single low-level language instruction translates to a single machine language instruction.
  • 5. Structure of C program /*Program to find Documentation Section area and perimeter of Circle */ #include<stdio.h> Linkage Section #define PI 3.1415 Definition Section float radius; float area(); Global Declaration Section float perimeter(); int main() { float a, p; Main Function Section printf(“Enter radius : “); scanf(“%f”,&radius); Local Declaration Part a = area(); Executable Code Part p = perimeter(); printf(“Area of Circle : %f”,a); printf(“Perimeter : %f”,p); } float area() Sub Program Section { return (PI * radius * radius); Function1() } Function2() float perimeter() …………… { FunctionN() return (2 * PI * radius); }
  • 6. Program Development Steps 1)Statement of Problem 4.a)Compilation a) Working with existing system and using proper Translate the program into machine code. This questionnaire, the problem should be explained process is called as Compilation. Syntactic errors are clearly. found quickly at the time of compiling the program. b) What inputs are available, outputs are required These errors occur due to the usage of wrong and what is needed for creating workable solution syntaxes for the statements. should be understood clearly. Eg: x=a*y+b 2)Analysis There is a syntax error in this statement, since, each a) The method of solutions to solve the problem can and every statement in C language ends with a be identified. semicolon (;). b) We also judge that which method gives best results among different methods of solution. 4.b)Execution 3)Designing The next step is Program execution. In this phase, we a) Algorithms and flow charts will be prepared. may encounter two types of errors. b) Keep focus on data, architecture, user interfaces Runtime Errors: these errors occur during the and program components. execution of the program and terminates the program abnormally. 4)Implementation The algorithms and flow charts developed in the Logical Errors: these errors occur due to incorrect usage of the instructions in the program. These errors previous steps are converted into actual programs in are neither detected during compilation or execution the high level languages like C. nor cause any stoppage to the program execution but produces incorrect ouz
  • 7. Executing a C program #include<stdio.h> Text int main() { Translators are system software Editor ……. prog1.c used to convert high-level language program into C-compiler compiles machine-language code. Compiler : Coverts the entire 010110 100 Syntax Yes source program at a time ……………. 01011 101 Errors? into object code file, and No saves it in secondary storage Object machine code permanently. The same adds prog1.obj object machine code file will Linker be executed several times, 00101010 Executable whenever needed. …………. 01010101 machine code Interpreter : Each statement of prog1.exe source program is translated machine code of library file into machine code and Executes executed immediately. C-Runtime Translation and execution of Feeds each and every statement is Runtime Yes Input or Logic repeated till the end of the Errors ? program. No object code is saved. Translation is repeated for every execution Output of the source program.
  • 8. Character Set of C-Language Alphabets : A-Z and a-z Digits : 0-9 Special Symbols : ~ ! @ # $ % ^ & ( ) _ - + = | { } [ ] : ; “ ‘ <>,.?/ White Spaces : space , Horizontal tab, Vertical tab, New Line Form Feed. C-Language Keywords(C99) auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while _Bool _Imaginary restrict _Complex inline
  • 9. C-Tokens Tokens : The smallest individual units of a C- program are called Tokens. Key words, Identifiers, Constants, Operators, Delimiters. Key words : have a predefined meaning and these meanings cannot be changed. All keywords must be written in small letters (except additional c99 keywords). Identifiers : names of variables, functions, structures, unions, macros, labels, arrays etc., Rules for define identifiers : a) First character must be alphabetic character or under score b) Second character onwards alphabetic character of digit or under score. c) First 63 characters of an identifier are significant. d) Cannot duplicate a key word. e) May not have a space or any other special symbol except under score. f) C – language is Case-sensitive.
  • 10. C-Tokens Constants : fixed values that do not change during execution of a program. Boolean constants : 0 ( false) and 1 (true) Character constants : only one character enclosed between two single quotes ( except escape characters ). wide character type - wchar_t - for Unicode characters. Integer constants : +123, -3454 , 0235 (octal value), 0x43d98 ( hexa - decimal value) 54764U, 124356578L, 124567856UL Float constants : 0.2 , 876.345, .345623 , 23.4E+8, 47.45e+6 String Constants : “Hello world” , “Have a nice day!” Complex Constants : real part + imaginary part * I ex : 12.3 + 3.45 * I Operators : a symbol, which indicates an operation to be performed. Operators are used to manipulate data in program. Delimiters : Language Pattern of c-language uses special kind of symbols : (colon, used for labels) ; (semicolon terminates statement ) ( ) parameter list [ ] ( array declaration and subscript ), { } ( block statement ) # ( hash for preprocessor directive ) , (comma variable separator )
  • 11. Data Types ( pre defined ) Type Typical Size in Bits Minimal Range char 8 –127 to 127 unsigned char 8 0 to 255 signed char 8 –127 to 127 int 16 or 32 –32,767 to 32,767 unsigned int 16 or 32 0 to 65,535 signed int 16 or 32 Same as int short int 16 –32,767 to 32,767 unsigned short int 16 0 to 65,535 signed short int 16 Same as short int long int 32 –2,147,483,647 to 2,147,483,647 long long int 64 –(263) to 263 – 1 (Added by C99) signed long int 32 Same as long int unsigned long int 32 0 to 4,294,967,295 unsigned long long int 64 264 – 1 (Added by C99) float 32 3.4e-38 to 3.4e+38 double 64 1.7e-308 to 1.7e+308 long double 80 3.4e-4932 to 1.1e+4932 void -- data type that not return any value
  • 12. Conversion Specifiers Code Format %a Hexa decimal output in the form of 0xh.hhhhp+d(C99 only) %s String of characters (until null zero is reached ) %c Character %d Decimal integer %f Floating-point numbers %e Exponential notation floating-point numbers %g Use the shorter of %f or %e %u Unsigned integer %o Octal integer %x Hexadecimal integer %i Signed decimal integer %p Display a pointer %n The associated argument must be a pointer to integer, This sepecifier causes the number of characters written in to be stored in that integer. %hd short integer %ld long integer %lf long double %% Prints a percent sign (%)
  • 13. Back Slash ( Escape Sequence) Characters Code Meaning b Backspace f Form feed n New line r Carriage return t Horizontal tab " Double quote ' Single quote Backslash v Vertical tab a Alert ? Question mark N Octal constant (N is an octal constant) xN Hexadecimal constant (N is a hexadecimal constant)
  • 14. Increment and Decrement Operators prefix increment (++a) postfix increment (a++) prefix decrement(- -a) postfix decrement (a- -) Executes all Prefix Operations Before evaluation of expression Evaluation of expression Executes all Postfix Operations After evaluation of expression and before leaving the statement /* prefix operators */ /* prefix and postfix operators */ /* postfix operators */ #include<stdio.h> #include<stdio.h> #include<stdio.h> int main() { int main() { int main() { int a = 7, b = 12, c; int a = 7, b = 12, c; int a = 7, b = 12, c; c = b * (++a) + 5 * (++a); c = b * (a++) + 5 * (++a); c = b * (a++) + 5 * (a++); printf(“ a = %d”, a); printf(“ a = %d”, a); printf(“ a = %d”, a); printf(“n b = %d”,b); printf(“n b = %d”,b); printf(“n b = %d”,b); printf(“n c = %d”,c); printf(“n c = %d”,c); printf(“n c = %d”,c); } } } Output: Output: Output: a=9 a=9 a=9 b = 12 b = 12 b = 12 c = 153 ( 12 * 9 + 5 * 9) c = 136 ( 12 * 8 + 5 * 8) c = 119 ( 12 * 7 + 5 * 7)
  • 15. Bitwise Logical Operators & -- Bitwise AND A B A&B A|B A^B ~A 1 1 1 1 0 0 | -- Bitwise OR 1 0 0 1 1 0 ^ -- Bitwise XOR 0 1 0 1 1 1 ~ -- Bitwise NOT 0 0 0 0 0 1 Bitwise AND Bitwise OR A (42) : 00000000 00101010 A (42) : 00000000 00101010 B (15) : 00000000 00001111 B (15) : 00000000 00001111 ----------------------------------- ----------------------------------- & (10) : 00000000 00001010 | (47) : 00000000 00101111 ----------------------------------- ----------------------------------- Bitwise XOR Bitwise NOT A (42) : 00000000 00101010 A (42) : 00000000 00101010 B (15) : 00000000 00001111 ----------------------------------- ----------------------------------- ~ (-43) : 11111111 11010101 & (37) : 00000000 00100101 ----------------------------------- -----------------------------------
  • 16. BITWISE SHIFT OPERATORS Bitwise Left Shift ( << ) Bitwise Right Shift ( >> ) Bitwise Right Shift ( >> ) (positive values) (negetive values) A (43) : 00000000 00101011 A (43) : 00000000 00101011 A (-44) : 11111111 11010100 ----------------------------------- ----------------------------------- ----------------------------------- A << 2 : 00000000 10101100 A >> 2 : 00000000 00001010 A >> 2 : 11111111 11110101 ----------------------------------- ----------------------------------- ----------------------------------- Note : Right shift operator fills the left vacant fields with ‘zeros’ for positive numbers, with ‘ones’ for negative numbers. Opposite TYPE CONVERSION Explicit Type Conversion To (casting) Gravity 1.bool 2.char (forcible) (forcible) 3.short int . 4.int . 5.long int . . 6.long long int . . 7.float (natural) (automatic) 8.double 9.long double Gravity Implicit Type Conversion (automatic)
  • 17. Precedence and Associativity of Operators Precdence Group Operators Associativity (Highest to Lowest ) (param) subscript etc., ( ) [ ] –>. L R Unary operators - + ! ~ ++ – – (type) * & sizeof R L Multiplicative */% L R Additive +– L R Bitwise shift << >> L R Relational < <= > >= L R Equality = = != L R Bitwise AND & L R Bitwise exclusive OR ^ L R Bitwise OR | L R Logical AND && L R Logical OR || L R Conditional ?: R L Assignment = += –= *= /= %= &= ^= R L |= <<= >>= Comma , L R
  • 18. simple if: Entry if-else: Entry True Test False Test True Expression Expression ? ? False True Statement-block True-block False-block Statements Statements Next statement Next statement /* check a citizen is eligible for voting */ /* print a number is even or odd */ #include<stdio.h> #include<stdio.h> int main() int main() { { int age; int number; printf(“Enter the age : ”); printf(“Enter a number : “); scanf(“%d”,&age); scanf(“%d”, &number); if(age >= 18) if((number %2) == 0) printf(“Eligible for voting…”); printf(“%d is even number.”,number); getch(); else } printf(“%d is odd number.”,number); }
  • 19. nested if…else: /* check whether a year is leap year or not */ #include<stdio.h> Entry int main() { int year; Test printf("Enter the year ?"); False True condition1 scanf("%d",&year); ? if((year %100) == 0) Test { False True if((year % 400) == 0) condition2 ? printf("%d is leap year.",year); else Statement-3 Statement-2 Statement-1 printf("%d is not leap year.",year); } else { if((year % 4) == 0) printf("%d is leap year.",year); else Next statement printf("%d is not leap year.",year); } getch(); }
  • 20. if…else…if : /* program to print the grade of student */ #include<stdio.h> Entry int main() { True int marks; Test condition1 Statement-1 printf("Enter marks ? "); ? scanf("%d", &marks); False if(marks >= 75) Test True printf("Distinction"); condition2 Statement-2 else if(marks >= 60) ? printf("First class"); False else if(marks >= 50) Test True printf("Second class"); conditionN Statement-N else if(marks >= 35) ? printf("Third class"); Next statement else printf("Failed"); }
  • 21. switch statement : /* program to simulate a simple calculator */ #include<stdio.h> Entry int main() { float a,b; switch char opr; expression printf("Enter number1 operator number2 : "); ? scanf("%f %c %f",&a,&opr,&b); switch(opr) value1 value2 valueN default { ……... case '+': printf("Sum : %f",(a + b)); associate associate associate associate break; statement statement statement statement case '-': printf("Difference : %f",(a - b)); break; case '*': printf("Product : %f",(a * b)); break; case '/': Exit printf("Quotient : %f",(a / b)); break; default: Next statement printf("Invalid Operation!"); } }
  • 22. Loop Statements while – (Entry controlled ) do-while – (Exit controlled ) Entry Entry Test False Condition Body of The loop ? true Test False Body of The loop Condition ? Following Statement True Following Statement /* average of 5 numbers */ /* sum of 1 to 10 numbers */ #include<stdio.h> #include<stdio.h> int main() { int main() { int count = 1; int i = 1,sum = 0; float x, sum = 0; while(i<=10){ do { sum = sum + i; printf(“x = “); i = i + 1; scanf(“%f”,&x); } sum += x; printf(“Total : %d “,sum); ++ count; } } while(count <= 5); printf(“Average = %f “, (sum/5)) }
  • 23. for -- Entry Statement Initialization Statement Increment Statement False Test Condition ? True Body of The loop Following Statement /* check whether a number is prime or not */ #include<stdio.h> int main() { int n,i,factors = 0; printf("Enter a number : "); scanf("%d",&n); for(i = 1; i <= n; i++) { if((n % i)==0) ++factors; } if (factors == 2) printf("%d is prime number.",n); else printf("%d is not prime number.",n); }
  • 24. Important Functions in math.h abs(x) absolute value of integer x ceil(x) rounds up and returns the smallest integer greater than or equal to x floor(x) rounds down and returns the largest integer less than or equal to x log(x) returns natural logarithm pow(x,y) returns the value of xy sqrt(x) returns square root of x exp(x) returns natural anti logarithm sin(x) returns sine value where x in radians cos(x) returns cosine value where x in radians tan(x) returns tangent values where x in radians fmod(x,y) calculate x modulo y, where x and y are double hypot(x,y) calculate hypotenuse of right angle where x,y are sides. log10(x) returns logarithm base 10
  • 25. www.jntuworld.com • For More Materials, Text Books, Previous Papers & Mobile updates of B.TECH, B.PHARMACY, MBA, MCA of JNTU- HYD,JNTU-KAKINADA & JNTU- ANANTAPUR visit www.jntuworld.com

Notes de l'éditeur

  1. CnDS Aditya Engineering College