SlideServe
Menu
Préférences
© SlideServe · v2026

Structured Program Development Asim Iqbal

koren avatar
15 diapositives · 317 Views · Oct 09, 2014

Structured Program Development Asim Iqbal. Outline Introduction Algorithms Pseudocode Control Structures The If Selection Statement The If…Else Selection Statement. Decision Making: Equality and Relational Operators. if control statement

Structured Program Development Asim Iqbal - slide 1
01 / 15Structured Program Development Asim Iqbal
1 / 17

Télécharger la présentation

Structured Program Development Asim Iqbal
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Structured Program DevelopmentAsimIqbal Outline Introduction Algorithms Pseudocode Control Structures The If Selection Statement The If…Else Selection Statement

  2. Decision Making: Equality and Relational Operators • if control statement • If a condition is true, then the body of the if statement executed • 0 is false, non-zero is true • Control always resumes after the if structure • Keywords • Special words reserved for C • Cannot be used as identifiers or variable names

  3. Equality and Relational Operators Example //90 - 100 int grade; printf("Please enter your grade => "); scanf("%d",&grade); if(grade>=90){ printf("You got A grade = %d \n ",grade); } if(grade<90){ printf("Better luck next time = %d\n ",grade); }

  4. Decision Making: Equality and Relational Operators

  5. Using if statements, relational operators, and equality operators /* Using if statements, relational operators, and equality operators */ #include <stdio.h> /* function main begins program execution */ main() { int num1; /* first number to be read from user */ int num2; /* second number to be read from user */ printf( "Enter two integers, and I will tell you\n" ); printf( "the relationships they satisfy: " ); scanf( "%d%d", &num1, &num2 ); /* read two integers */ if ( num1 == num2 ) { printf( "%d is equal to %d\n", num1, num2 ); } /* end if */ if ( num1 != num2 ) { printf( "%d is not equal to %d\n", num1, num2 ); } /* end if */ system("pause"); return 0; /* indicate that program ended successfully */ } /* end function main */ Output Enter two integers, and I will tell you the relationships they satisfy: 3 73 is not equal to 7

  6. Precedence and associativity of the operators

  7. C’s reserved keywords

  8. Introduction • Before writing a program: • Have a thorough understanding of the problem • Carefully plan an approach for solving it • While writing a program: • Know what “building blocks” are available • Use good programming principles

  9. Algorithms • Computing problems • All can be solved by executing a series of actions in a specific order • Algorithm: procedure in terms of • Actions to be executed • The order in which these actions are to be executed • Program control • Specify order in which statements are to be executed

  10. Pseudocode • Pseudocode • Artificial, informal language that helps us develop algorithms • Similar to everyday English • Not actually executed on computers • Helps us “think out” a program before writing it • Easy to convert into a corresponding C program • Consists only of executable statements

  11. Control Structures • Flowcharting C’s sequence structure.

  12. The if Selection Statement • Selection structure: • Used to choose among alternative courses of action • Pseudocode: If student’s grade is greater than or equal to 60Print “Passed” • If condition true • Print statement executed and program goes on to next statement • If false, print statement is ignored and the program goes onto the next statement • Indenting makes programs easier to read • C ignores whitespace characters

  13. The ifSelection Statement… • Pseudocode statement in C: if ( grade >= 60 ) printf( "Passed\n" ); • C code corresponds closely to the pseudocode

  14. The if…else Selection Statement • if • Only performs an action if the condition is true • if…else • Specifies an action to be performed both when the condition is true and when it is false • Psuedocode: If student’s grade is greater than or equal to 60Print “Passed” elsePrint “Failed” • Note spacing/indentation conventions

  15. The if…else Selection Statement • C code: if ( grade >= 60 ) printf( "Passed\n"); else printf( "Failed\n");