SlideShare una empresa de Scribd logo
1 de 32
DATA INPUT AND OUTPUT
• As we know that any c program is made up of 1 or
  more then 1 function.

• Likewise it use some functions for input output
  process. The most common function
      1) printf()
      2) scanf().
printf() Function
• printf() function is use to display something on the
  console or to display the value of some variable on
  the console.
• The general syntax for printf() function is as
  follows
      printf(<”format string”>,<list of variables>);

• To print some message on the screen
            printf(“God is great”);
  This will print message “God is great” on the
  screen or console.
printf() Function



• To print the value of some variable on the screen
  Integer Variable :
                     int a=10;
                     printf(“%d”,a);
  Here %d is format string to print some integer value and a
  is the integer variable whose value will be printed by
  printf() function.
  This will print value of a “10” on the screen.
printf() function
• To print multiple variable’s value one can use
  printf() function in following way.

     int p=1000,n=5;
     float r=10.5;
     printf(“amount=%d rate=%f year=%d”,p,r,n);

• This will print “amount=1000 rate=10.5 year=5”
  on the screen
scanf() Function
• scanf() function is use to read data from
  keyboard and to store that data in the variables.
• The general syntax for scanf() function is as
  follows.
           scanf(“Format String”,&variable);

  Here format string is used to define which type
  of data it is taking as input.

  this format string can be %c for character, %d
  for integer variable and %f for float variable.
scanf() Function

    scanf(“Format String”,&variable);

• Where as variable the name of memory
  location or name of the variable

• and & sign is an operator that tells the
  compiler the address of the variable where
  we want to store the value.
scanf() Function
• For Integer Variable :
     int rollno;
     printf(“Enter rollno=”);
     scanf(“%d”,&rollno);

  Here in scanf() function %d is a format string for
  integer variable

  and &rollno will give the address of variable
  rollno to store the value at variable rollno
  location.
scanf() Function
• For Float Variable :
     float per;
     printf(“Enter Percentage=”);
     scanf(“%f”,&per);

• For Character Variable :
     char ans;
     printf(“Enter answer=”);
     scanf(“%c”,&ans);
Single character input – the getchar
                function :
• Single characters can be entered into the computer
  using the “C” library function getchar.

• In general terms, a reference to the getchar function
  is written as.
      character variable=getchar();

For example
      char c;
      c=getchar();
Single character output – The putchar
               function
• Single character can be displayed (i.e. written out
  of the computer) using the C library function
  putchar.
• In general a reference to the putchar function is
  written as
           putchar (character variable);
For Example
           char c=’a’;
           putchar(c);
Control Flow In C
• Objectives of the module is

  1) How to direct the sequence of execution
  using Decision control Structure

  2) Have an understanding of the iterative
  process using Loop Control Structure
Decision Control Structure
  The if-else statement:
• The if-else statement is used to carry out a logical
  test and then take one of two possible actions
  depending on the outcome of the test

• Thus, in its simplest general form, the statement
  can be written.
     if(expression)
     {
           statement;
     }
Decision Control Structure
• The general form of an if statement which include the
  else clause is
       if(expression)
       {
              statement 1;
       }
       else
       {
              statement 2;
       }
  If the expression is true then statement 1 will be
  executed. Otherwise, statement 2 will be executed.
Nested If Else
if<exp1>
{
    statement1;
}
else
{
    if<exp2>
    {
          statement2;
    }
}
Nested If Else
/* Demonstration of if statement */
#include<stdio.h>
void main( )
{
    int num ;
    printf ( "Enter a number :" ) ;
    scanf ( "%d", &num ) ;
    if ( num <= 10 )
           printf ( “Number is less than 10" ) ;
    else
           printf(“Number is greater than 10”);
}
Else if ladder
           if( expression1 )
                   statement1;
           else if( expression2 )
                   statement2;
           else
                   statement3;
• For Example
            if( age < 18 )
                     printf("Minor");
            else if( age < 65 )
                     printf("Adult");
            else
                     printf( "Senior Citizen");
Decision Control Structure
• The switch statement:
  causes a particular group of statements to
  be chosen from several available groups.

• The selection is based upon the current
  value of an expression that is included
  within a switch statement.
The general form of switch-case
      switch(expression)
      {
          case expression1:
                statements;
                break;
          case expression2:
                statements;
                break;
          case expression3:
                statements;
                break;
      }
• When switch statement is executed the expression is evaluated
  and control is transferred directly to the group of statements
  whose case labels value matches the value of the expression.
      switch(choice)
      {
             case ‘r’ :
                     printf(“RED”);
                     break;
             case ‘b’ :
                     printf(“BLUE”);
                     break;
             default :
                     printf(“ERROR”);
                     break;
      }
LOOP CONTROL STRUCTURE
• If we want to perform certain action for no of
  times or we want to execute same statement or a
  group of statement repeatedly then we can use
  different type of loop structure available in C.

• Basically there are 3 types of loop structure
  available in C
     (1) While loop
     (2) Do..while
     (3) For loop
While Loop
• The while statement is used to carry out
  looping operations.
• The general form of the statements
           initialization;
           while(exp)
           {
                  statement 1;
                  statement 2;
                  increment/ decrement;
           }
While loop example
#include<stdio.h>
void main ()
{
   int digit = 0;
   while(digit<=9)
   {
         printf(“%d n”,digit);
         ++digit ;
   }
}
Do-While Loop
• Sometimes, however, it is desirable to have a loop
  with the test for continuation at the end or each
  pass.
• This can be accomplished by means of the do-while
  statement.
• The general form of do-while statement is
            do
            {
                  statement1;
                  statement2;
                  increment/decrement operator;
            } while(expression);
Do-While Loop Example
#include <stdio.h>
void main()
{
   int digit = 0;
   do
   {
         printf(“%d”, digit++);
   }while(digit<=9);
}
For Loop
• The for statement is another entry controller
  that provides a more concise loop control
  structure.

• The general form of the for loop is :

  for(initialization; test condition; inc/decrement)
  {
      statement 1;
      statement 2;
  }
For loop example
#include<stdio.h>
void main()
{
   for(x=0; x<9; x++)
   {
        printf(“%d”, x);
        printf(“n”);
   }
}
Reverse For loop
• The for statement allows for negative
  increments.
• For example, the loop discussed above can be
  written as follows:

 for(x=9; x>=0; x--)
 {
     printf(“%d”,x);
     printf(“/n”);
 }
BREAK STATEMENT
• The break statement is used to terminate
  loops or to exit a switch.

  for(i=1; i<=10; i++)
  {
      if(i==5)
            break;
      printf(“nI=%d”,i);
  }
CONTINUE STATEMENT
• The continue statement is used to skip or to bypass
  some step or iteration of looping structure.

  for(i=1; i<=10; i++)
  {
      if(i<5)
             continue;
      printf(“ni=%d”,i);
  }

  The output of the above program will be
  6,7,8,9,10.
THE GOTO STATEMENT
• The goto statement is used to alter the normal
  sequence of program execution by transferring
  control to some other part of the program.

• In its general form the goto statement is written
  as
                  goto label;
• Where label is an identifier used to label the
  target statement to which control will be
  transferred.
goto example
void main()
{
    for(i=0;i<5;i++)
    {
          printf(“i =%d”,i);
          if(i==4)
                goto stop;
    }
 stop:
 printf_s( "Jumped to stop”);
}

Más contenido relacionado

La actualidad más candente (19)

Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
C if else
C if elseC if else
C if else
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Control statement
Control statementControl statement
Control statement
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Chapter 13.1.5
Chapter 13.1.5Chapter 13.1.5
Chapter 13.1.5
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
Control structure
Control structureControl structure
Control structure
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
 
Branching in C
Branching in CBranching in C
Branching in C
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 

Destacado

Bideo-Jolasak
Bideo-JolasakBideo-Jolasak
Bideo-Jolasakolatzucin
 
New Products Or New Markets
New Products Or New MarketsNew Products Or New Markets
New Products Or New MarketsPico Lantini
 
UG_20090206_Merci
UG_20090206_MerciUG_20090206_Merci
UG_20090206_MerciBart Merci
 
Los Colores.
Los Colores.Los Colores.
Los Colores.beki2009
 
CarParkFireSafety_UG_20091208
CarParkFireSafety_UG_20091208CarParkFireSafety_UG_20091208
CarParkFireSafety_UG_20091208Bart Merci
 
UG_20090206_Vantomme
UG_20090206_VantommeUG_20090206_Vantomme
UG_20090206_VantommeBart Merci
 
The Product Manager Should Be CEO
The Product Manager Should Be CEOThe Product Manager Should Be CEO
The Product Manager Should Be CEOPico Lantini
 
UG_20090206_vanBeeck
UG_20090206_vanBeeckUG_20090206_vanBeeck
UG_20090206_vanBeeckBart Merci
 
UG_20090206_Taerwe
UG_20090206_TaerweUG_20090206_Taerwe
UG_20090206_TaerweBart Merci
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For LoopSukrit Gupta
 
Power Facts from the Tesla roadster
Power Facts from the Tesla roadsterPower Facts from the Tesla roadster
Power Facts from the Tesla roadsterPico Lantini
 
Introduction to c
Introduction to cIntroduction to c
Introduction to cSayed Ahmed
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
 
UG_20090206_Tilley
UG_20090206_TilleyUG_20090206_Tilley
UG_20090206_TilleyBart Merci
 
UG_20090206_VandenSchoor
UG_20090206_VandenSchoorUG_20090206_VandenSchoor
UG_20090206_VandenSchoorBart Merci
 

Destacado (20)

Session 4
Session 4Session 4
Session 4
 
Structure in c
Structure in cStructure in c
Structure in c
 
Bideo-Jolasak
Bideo-JolasakBideo-Jolasak
Bideo-Jolasak
 
New Products Or New Markets
New Products Or New MarketsNew Products Or New Markets
New Products Or New Markets
 
Session 5
Session 5Session 5
Session 5
 
UG_20090206_Merci
UG_20090206_MerciUG_20090206_Merci
UG_20090206_Merci
 
Los Colores.
Los Colores.Los Colores.
Los Colores.
 
CarParkFireSafety_UG_20091208
CarParkFireSafety_UG_20091208CarParkFireSafety_UG_20091208
CarParkFireSafety_UG_20091208
 
UG_20090206_Vantomme
UG_20090206_VantommeUG_20090206_Vantomme
UG_20090206_Vantomme
 
The Product Manager Should Be CEO
The Product Manager Should Be CEOThe Product Manager Should Be CEO
The Product Manager Should Be CEO
 
UG_20090206_vanBeeck
UG_20090206_vanBeeckUG_20090206_vanBeeck
UG_20090206_vanBeeck
 
UG_20090206_Taerwe
UG_20090206_TaerweUG_20090206_Taerwe
UG_20090206_Taerwe
 
Session 6
Session 6Session 6
Session 6
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
 
Power Facts from the Tesla roadster
Power Facts from the Tesla roadsterPower Facts from the Tesla roadster
Power Facts from the Tesla roadster
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
UG_20090206_Tilley
UG_20090206_TilleyUG_20090206_Tilley
UG_20090206_Tilley
 
UG_20090206_VandenSchoor
UG_20090206_VandenSchoorUG_20090206_VandenSchoor
UG_20090206_VandenSchoor
 
C++ programming
C++ programmingC++ programming
C++ programming
 

Similar a Session 3

Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxLikhil181
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxSmitaAparadh
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Shipra Swati
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptxSKUP1
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptxLECO9
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptxeaglesniper008
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops Hemantha Kulathilake
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languageTanmay Modi
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop kapil078
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)jakejakejake2
 
Unit 5 Control Structures.pptx
Unit 5 Control Structures.pptxUnit 5 Control Structures.pptx
Unit 5 Control Structures.pptxPrecise Mya
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 

Similar a Session 3 (20)

Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptx
 
Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)
 
Unit 5 Control Structures.pptx
Unit 5 Control Structures.pptxUnit 5 Control Structures.pptx
Unit 5 Control Structures.pptx
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 

Último

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Último (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Session 3

  • 1. DATA INPUT AND OUTPUT • As we know that any c program is made up of 1 or more then 1 function. • Likewise it use some functions for input output process. The most common function 1) printf() 2) scanf().
  • 2. printf() Function • printf() function is use to display something on the console or to display the value of some variable on the console. • The general syntax for printf() function is as follows printf(<”format string”>,<list of variables>); • To print some message on the screen printf(“God is great”); This will print message “God is great” on the screen or console.
  • 3. printf() Function • To print the value of some variable on the screen Integer Variable : int a=10; printf(“%d”,a); Here %d is format string to print some integer value and a is the integer variable whose value will be printed by printf() function. This will print value of a “10” on the screen.
  • 4. printf() function • To print multiple variable’s value one can use printf() function in following way. int p=1000,n=5; float r=10.5; printf(“amount=%d rate=%f year=%d”,p,r,n); • This will print “amount=1000 rate=10.5 year=5” on the screen
  • 5. scanf() Function • scanf() function is use to read data from keyboard and to store that data in the variables. • The general syntax for scanf() function is as follows. scanf(“Format String”,&variable); Here format string is used to define which type of data it is taking as input. this format string can be %c for character, %d for integer variable and %f for float variable.
  • 6. scanf() Function scanf(“Format String”,&variable); • Where as variable the name of memory location or name of the variable • and & sign is an operator that tells the compiler the address of the variable where we want to store the value.
  • 7. scanf() Function • For Integer Variable : int rollno; printf(“Enter rollno=”); scanf(“%d”,&rollno); Here in scanf() function %d is a format string for integer variable and &rollno will give the address of variable rollno to store the value at variable rollno location.
  • 8. scanf() Function • For Float Variable : float per; printf(“Enter Percentage=”); scanf(“%f”,&per); • For Character Variable : char ans; printf(“Enter answer=”); scanf(“%c”,&ans);
  • 9. Single character input – the getchar function : • Single characters can be entered into the computer using the “C” library function getchar. • In general terms, a reference to the getchar function is written as. character variable=getchar(); For example char c; c=getchar();
  • 10. Single character output – The putchar function • Single character can be displayed (i.e. written out of the computer) using the C library function putchar. • In general a reference to the putchar function is written as putchar (character variable); For Example char c=’a’; putchar(c);
  • 11. Control Flow In C • Objectives of the module is 1) How to direct the sequence of execution using Decision control Structure 2) Have an understanding of the iterative process using Loop Control Structure
  • 12. Decision Control Structure The if-else statement: • The if-else statement is used to carry out a logical test and then take one of two possible actions depending on the outcome of the test • Thus, in its simplest general form, the statement can be written. if(expression) { statement; }
  • 13. Decision Control Structure • The general form of an if statement which include the else clause is if(expression) { statement 1; } else { statement 2; } If the expression is true then statement 1 will be executed. Otherwise, statement 2 will be executed.
  • 14. Nested If Else if<exp1> { statement1; } else { if<exp2> { statement2; } }
  • 16. /* Demonstration of if statement */ #include<stdio.h> void main( ) { int num ; printf ( "Enter a number :" ) ; scanf ( "%d", &num ) ; if ( num <= 10 ) printf ( “Number is less than 10" ) ; else printf(“Number is greater than 10”); }
  • 17. Else if ladder if( expression1 ) statement1; else if( expression2 ) statement2; else statement3; • For Example if( age < 18 ) printf("Minor"); else if( age < 65 ) printf("Adult"); else printf( "Senior Citizen");
  • 18. Decision Control Structure • The switch statement: causes a particular group of statements to be chosen from several available groups. • The selection is based upon the current value of an expression that is included within a switch statement.
  • 19. The general form of switch-case switch(expression) { case expression1: statements; break; case expression2: statements; break; case expression3: statements; break; }
  • 20. • When switch statement is executed the expression is evaluated and control is transferred directly to the group of statements whose case labels value matches the value of the expression. switch(choice) { case ‘r’ : printf(“RED”); break; case ‘b’ : printf(“BLUE”); break; default : printf(“ERROR”); break; }
  • 21. LOOP CONTROL STRUCTURE • If we want to perform certain action for no of times or we want to execute same statement or a group of statement repeatedly then we can use different type of loop structure available in C. • Basically there are 3 types of loop structure available in C (1) While loop (2) Do..while (3) For loop
  • 22. While Loop • The while statement is used to carry out looping operations. • The general form of the statements initialization; while(exp) { statement 1; statement 2; increment/ decrement; }
  • 23. While loop example #include<stdio.h> void main () { int digit = 0; while(digit<=9) { printf(“%d n”,digit); ++digit ; } }
  • 24. Do-While Loop • Sometimes, however, it is desirable to have a loop with the test for continuation at the end or each pass. • This can be accomplished by means of the do-while statement. • The general form of do-while statement is do { statement1; statement2; increment/decrement operator; } while(expression);
  • 25. Do-While Loop Example #include <stdio.h> void main() { int digit = 0; do { printf(“%d”, digit++); }while(digit<=9); }
  • 26. For Loop • The for statement is another entry controller that provides a more concise loop control structure. • The general form of the for loop is : for(initialization; test condition; inc/decrement) { statement 1; statement 2; }
  • 27. For loop example #include<stdio.h> void main() { for(x=0; x<9; x++) { printf(“%d”, x); printf(“n”); } }
  • 28. Reverse For loop • The for statement allows for negative increments. • For example, the loop discussed above can be written as follows: for(x=9; x>=0; x--) { printf(“%d”,x); printf(“/n”); }
  • 29. BREAK STATEMENT • The break statement is used to terminate loops or to exit a switch. for(i=1; i<=10; i++) { if(i==5) break; printf(“nI=%d”,i); }
  • 30. CONTINUE STATEMENT • The continue statement is used to skip or to bypass some step or iteration of looping structure. for(i=1; i<=10; i++) { if(i<5) continue; printf(“ni=%d”,i); } The output of the above program will be 6,7,8,9,10.
  • 31. THE GOTO STATEMENT • The goto statement is used to alter the normal sequence of program execution by transferring control to some other part of the program. • In its general form the goto statement is written as goto label; • Where label is an identifier used to label the target statement to which control will be transferred.
  • 32. goto example void main() { for(i=0;i<5;i++) { printf(“i =%d”,i); if(i==4) goto stop; } stop: printf_s( "Jumped to stop”); }