[PDF] [PDF] Control Statements - CSE IIT Kgp





Previous PDF Next PDF



Defense Technical Information Center 8725 John J. Kingman Rd

Distribution Statements and Their Corresponding Reasons for Use DISTRIBUTION STATEMENT C. Distribution authorized to U.S. Government agencies and their ...



Forming an Opinion and Reporting on Financial Statements

The amendments are effective for audits of financial statements for periods ending on or after December 15 2022



Special Considerations — Audits of Financial

Financial statements pre- pared in accordance with a special purpose framework. Special purpose framework. A financial reporting framework other than generally 



Preparation of Financial Statements

A16). ©2021 AICPA. AR-C §70.14. Page 4. 4480. Statements on Standards for Accounting and Review Services. [As amended



Review of Financial Statements

[Paragraph added effective for reviews of financial statements for periods ending on or after December 15



Compilation Engagements

c. identify the entity whose financial statements have been sub- jected to the compilation engagement. d. specify the date or 



AICPA

understand that financial statements are prepared presented



Special Considerations — Audits of Group Financial Statements

of an Audit in Accordance With Generally Accepted Auditing Standards. AU-C §600.06. ©2021 AICPA. Page 3. Special Considerations 



PACAOS-Appendix-C: Nondiscrimination Statement Student

APPENDIX C: NONDISCRIMINATION POLICY STATEMENT FOR. UNIVERSITY OF CALIFORNIA PUBLICATIONS REGARDING. STUDENT-RELATED MATTERS. Page 1 of 4.



Consideration of Laws and Regulations in an Audit of Financial

AU-C Section 250. Consideration of Laws and Regulations in an. Audit of Financial Statements. Source: SAS No. 122. Effective for audits of financial 



[PDF] Control statements in C

Control statements control the flow of execution of the statements of a program The various types of control statements in C language are as under:-



[PDF] Unit –II Concepts: Control statements in C Programming Language:

A statement is a syntactic unit of an imperative programming language that Selectional statement are used to make one-time decisions in C Programming 



[PDF] Loop Control Structures in C

What the different loop control statements used in C? Give the syntax of each Solution: Looping meant directs a program to perform a set of operations



[PDF] Control Statements - CSE IIT Kgp

The for statement is the most commonly used looping structure in C • General syntax: for (expression1; expression2; expression3) statement-to-repeat;



[PDF] Control Statements in C GATE Notes PDF - BYJUS Exam Prep

Control statements in C enable the user to execute a particular code block conditionally C supports decision control statements that can alter the flow of 



[PDF] Lesson 02 Iteration/Looping in C Programming - University of Calcutta

The syntax of while loop in c language is given below: initialisation; while(condition) { block of statements to be executed ; increment; }



[PDF] Chapter 6 Iteration Statements

In C every loop has a controlling expression • Each time the loop body is executed (an iteration of the loop) the controlling expression is evaluated



[PDF] C - Decision Making - CMP Degree College

Decision making statements in programming languages decides the direction of flow of program execution Decision making statements available in C or C++ are 



[PDF] C Programming Tutorial - UNF

In C program the semicolon is a statement terminator That is each individual statement must be ended with a semicolon It indicates the end of one 

  • What are statements in C?

    C statements consist of tokens, expressions, and other statements. A statement that forms a component of another statement is called the "body" of the enclosing statement. Each statement type given by the following syntax is discussed in this section.
  • What is control statements in C PDF?

    Control statements in C enable the user to execute a particular code block conditionally. C supports decision control statements that can alter the flow of a sequence of instructions. The control flow statements allow the user to execute the code as per the requirements without executing it in sequential order.
  • How many statements are there in C?

    There are four types of control statements in C: Decision making statements (if, if-else) Selection statements (switch-case) Iteration statements (for, while, do-while)
  • There are three different classes of statements in C: expression statements, compound statements, and control statements. An expression statement consists of an expression followed by a semicolon.

2CNCUJ&G[&GRCTVOGPVQH%QORWVGT5EKGPEG'PII+PFKCP+PUVKVWVGQH6GEJPQNQI[-JCTCIRWT5NKFGUETGFKV2TQH+PFTCPKN5GP)WRVCControl Statements1

Programming and Data Structurew"MMPXEJGGFSFOUTFUTPGJOTUSVDUJPOTUPCFFYFDVUFEEFQFOEJOHPOUIFPVUDPNFPGBMPHJDBMUFTUr8IFUIFS536&PS'"-4&r5IJTJTDBMMFEbranchingw4PNFBQQMJDBUJPOTNBZBMTPSFRVJSFUIBUBTFUPGJOTUSVDUJPOTCFFYFDVUFESFQFBUFEMZ

QPTTJCMZBHBJOCBTFEPOTPNFDPOEJUJPOr5IJTJTDBMMFEloopingWhat do they do?2 Programming and Data Structurew6TJOHSFMBUJPOBMPQFSBUPSTr'PVSSFMBUJPOPQFSBUPST r5XPFRVBMJUZPQFSBUPST w6TJOHMPHJDBMPQFSBUPSTDPOOFDUJWFTr5XPMPHJDBMDPOOFDUJWFT ccr6OBSZOFHBUJPOPQFSBUPSHow do we specify the conditions?3

Programming and Data Structurecount <= 100 (math+phys+chem)/3 >= 60 (sex=='M') && (age>=21) (marks>=80) && (marks<90) (balance>5000) || (no_of_trans>25) !(grade=='A') !((x>20) && (y<16))Examples4

Programming and Data Structurew;FSPr*OEJDBUFTFALSEw/PO[FSPr*OEJDBUFTTRUEr5ZQJDBMMZUIFDPOEJUJPO536&JTSFQSFTFOUFECZUIFWBMVFb`The conditions evaluate to ...5

Programming and Data Structurew%JBNPOETZNCPMEFDJTJPOTZNCPM

UIFCSBDFTDBOCFPNJUUFEBranching: The if Statement6

Programming and Data StructureA decision can be made on any expression. zero - false nonzero - trueif (grade>=60) { printf("Passed \n"); printf("Good luck\n"); }7grade >= 60print "passed; good luck"truefalse

Programming and Data Structure#include main() { int a,b,c; scanf (ʺ%d %d %dʺ, &a, &b, &c); if ((a>=b) && (a>=c)) printf (ʺ\n The largest number is: %dʺ, a); if ((b>=a) && (b>=c)) printf (ʺ\n The largest number is: %dʺ, b); if ((c>=a) && (c>=b)) printf (ʺ\n The largest number is: %dʺ, c); }Example8

Programming and Data Structurew%BOHFSPVTFSSPSr%PFTOPUPSEJOBSJMZDBVTFTZOUBYFSSPSTr"OZFYQSFTTJPOUIBUQSPEVDFTBWBMVFDBOCFVTFEJODPOUSPMTUSVDUVSFTr/PO[FSPWBMVFTBSFUSVF

[FSPWBMVFTBSFGBMTFw&YBNQMFif (payCode = = 4) printf(ʺYou get a bonus!\nʺ); if (payCode = 4) printf(ʺYou get a bonus!\nʺ); Confusing Equality (==) and Assignment (=) Operators9WRONG

Programming and Data Structureif (10<20) { a = b + c; printf (ʺ%dʺ, a); } if ((a>b) && (x=10)) { ............... } if (1) { .................. } if (0) { .................. }Some Examples10

Programming and Data Structurew"MTPBTJOHMFFOUSZTJOHMFFYJUTUSVDUVSFw"MMPXTVTUPTQFDJGZUXPBMUFSOBUFCMPDLTPGTUBUFNFOUT

POFPGXIJDIJTFYFDVUFEEFQFOEJOHPOUIFPVUDPNFPGUIFDPOEJUJPOw(FOFSBMTZOUBYif (condition) { ...... block 1 ...... } else { ...... block 2 ...... } r*GBCMPDLDPOUBJOTBTJOHMFTUBUFNFOU

UIFCSBDFTDBOCFEFMFUFEBranching: The if-else Statement11 Programming and Data Structure12if ( grade >= 60 ) printf ("Passed\n"); else printf ("Failed\n");grade >= 60print "Passed"truefalseprint "Failed" Programming and Data Structurew*UJTQPTTJCMFUPOFTUJGFMTFTUBUFNFOUT

POFXJUIJOBOPUIFSw"MMJGTUBUFNFOUTNBZOPUCFIBWJOHUIFlFMTFzQBSUr$POGVTJPO w3VMFUPCFSFNFNCFSFEr"OlFMTFzDMBVTFJTBTTPDJBUFEXJUIUIFDMPTFTUQSFDFEJOHVONBUDIFElJGzr4PNFFYBNQMFTTIPXOOFYUNesting of if-else Structures13

Programming and Data Structureif e1 s1 else if e2 s2 if e1 s1 else if e2 s2 else s3 if e1 if e2 s1 else s2 else s3 if e1 if e2 s1 else s214?

Programming and Data StructureJGFTJGFTFMTFJGFT FMTFJGFT JGFT JGFTFMTFJGFT FMTFJGFT FMTFT FMTFT JGFJGFT JGFJGFT FMTFT FMTFT FMTFT FMTFT JGFJGFT JGFJGFT FMTFT FMTFT15

Programming and Data Structure#include main() { int a,b,c; scanf (ʺ%d %d %dʺ, &a, &b, &c); if (a>=b) if (a>=c) printf (ʺ\n The largest is: %dʺ, a); else printf (ʺ\n The largest is: %dʺ, c); else if (b>=c) printf (ʺ\n The largest is: %dʺ, b); else printf (ʺ\n The largest is: %dʺ, c); }Example16

Programming and Data Structure#include main() { int a,b,c; scanf (ʺ%d %d %dʺ, &a, &b, &c); if ((a>=b) && (a>=c)) printf (ʺ\n Largest number is: %dʺ, a); else if (b>c) printf (ʺ\n Largest number is: %dʺ, b); else printf (ʺ\n Largest number is: %dʺ, c); }Example17

Programming and Data Structurew5IJTNBLFTVTFPGBOFYQSFTTJPOUIBUJTFJUIFSUSVFPSGBMTF"OBQQSPQSJBUFWBMVFJTTFMFDUFE

EFQFOEJOHPOUIFPVUDPNFPGUIFMPHJDBMFYQSFTTJPOw&YBNQMFinterest = (balance>5000) ? balance*0.2 : balance*0.1;The Conditional Operator ? :18Returns a value

Programming and Data Structurew&YBNQMFTx = ((a>10) && (b<5)) ? a+b : 0 (marks>=60) ? printf(ʺPassed \nʺ) : printf(ʺFailed \nʺ);19

Programming and Data Structurew5IJTDBVTFTBQBSUJDVMBSHSPVQPGTUBUFNFOUTUPCFDIPTFOGSPNTFWFSBMBWBJMBCMFHSPVQTr6TFTlTXJUDIzTUBUFNFOUBOElDBTFzMBCFMTr4ZOUBYPGUIFlTXJUDIzTUBUFNFOUswitch (expression) { case expression-1: { ...... } case expression-2: { ...... } case expression-m: { ...... } default: { ......... } } XIFSFlFYQSFTTJPOzFWBMVBUFTUPJOUPSDIBSThe switch Statement20

Programming and Data Structureswitch (letter) { case 'A': pr intf (ʺFirst letter \nʺ); br eak; case 'Z': pr intf (ʺLast letter \nʺ); b reak; default : pr intf (ʺMiddle letter \nʺ); br eak; } Example21

Programming and Data Structurew6TFEUPFYJUGSPNBTXJUDIPSUFSNJOBUFGSPNBMPPQr"MSFBEZJMMVTUSBUFEJOUIFQSFWJPVTFYBNQMFw8JUISFTQFDUUPlTXJUDIz

UPUIFGJSTUTUBUFNFOUGPMMPXJOHUIFlTXJUDIzTUBUFNFOUCMPDLThe break Statement22

Programming and Data Structureswitch (choice = getchar()) { case 'r': case 'R': printf (ʺRED \nʺ); bre ak; case 'g': case 'G': printf (ʺGREEN \nʺ); b rea k; case 'b': case 'B': printf (ʺBLUE \nʺ); b rea k; default: printf (ʺInvalid choice \nʺ); }Example23

Programming and Data Structureswitch (choice = toupper(getchar())) { case 'R': printf (ʺRED \nʺ); b rea k; case 'G': printf (ʺGREEN \nʺ); bre ak; case 'B': printf (ʺBLUE \nʺ); b rea k; default: printf (ʺInvalid choice \nʺ); }Example24

Autumn Semester 2019Programming and Data Structurew5IFlTXJUDIzTUBUFNFOUBMTPDPOTUJUVUFTBTJOHMFFOUSZTJOHMFFYJUTUSVDUVSF25switch statement

A Look Back at Arithmetic Operators: the Increment and Decrement26

Programming and Data Structurew#PUIPGUIFTFBSFVOBSZPQFSBUPSTUIFZPQFSBUFPOBTJOHMFPQFSBOEw5IFJODSFNFOUPQFSBUPSDBVTFTJUTPQFSBOEUPCFJODSFBTFECZr&YBNQMFa++, ++count w5IFEFDSFNFOUPQFSBUPSDBVTFTJUTPQFSBOEUPCFEFDSFBTFECZr&YBNQMFi--, --distanceIncrement (++) and Decrement (--)27

Programming and Data Structurew0QFSBUPSXSJUUFOCFGPSFUIFPQFSBOEJ J J

Programming and Data StructureInitial values :: a = 10; b = 20; x = 50 + ++a; a = 11, x = 61 x = 50 + a++; x = 60, a = 11 x = a++ + --b; b = 19, x = 29, a = 11 x = a++ - ++a; Undefined value (implementation dependent) Examples29Called side effects:: while calculating some values, something else get changed.

Control Structures that Allow Repetition 30

w-PPQ(SPVQPGJOTUSVDUJPOTUIBUBSFFYFDVUFESFQFBUFEMZXIJMFTPNFDPOEJUJPOSFNBJOTUSVF )PXMPPQTBSFDPOUSPMMFE Types of Repeated Execution 31Sentinel ControlledCounter Controlled Condition ControlledProgramming and Data Structure

Programming and Data Structurew$PVOUFSDPOUSPMMFESFQFUJUJPOr%FGJOJUFSFQFUJUJPOrLOPXIPXNBOZUJNFTMPPQXJMMFYFDVUFr$POUSPMWBSJBCMFVTFEUPDPVOUSFQFUJUJPOTw$POEJUJPODPOUSPMMFESFQFUJUJPOr-PPQFYFDVUFTBTMPOHBTTPNFTQFDJGJFEDPOEJUJPOJTUSVFw4FOUJOFMDPOUSPMMFESFQFUJUJPOr*OEFGJOJUFSFQFUJUJPOr6TFEXIFOOVNCFSPGSFQFUJUJPOTOPULOPXOr4FOUJOFMWBMVFJOEJDBUFTlend of dataz32

Programming and Data Structurew$PVOUFSDPOUSPMMFESFQFUJUJPOSFRVJSFT-name of a control variable (or loop counter). -initial value of the control variable. -condition that tests for the final value of the control variable (i.e., whether looping should continue). -increment (or decrement) by which the control variable is modified each time through the loop. Counter-controlled Repetition33

Read 5 integers and display the value of their sum.Counter Controlled Loop34int counter=1, sum=0, n; while (counter <6 ) { scanf ("%d", &n); sum = sum + n; counter++; }

Programming and Data Structure35int counter, sum=0, n; for (counter=1; counter<6; counter++) { scanf (ʺ%dʺ, &n); sum = sum + n; } printf (ʺ\nSum is: %dʺ, sum);

Programming and Data Structurew5IFlXIJMFzTUBUFNFOUJTVTFEUPDBSSZPVUMPPQJOHPQFSBUJPOT

BTMPOHBTTPNFDPOEJUJPOSFNBJOTTBUJTGJFEwhile Statement36while (condition) statement_to_repeat;while (condition) { statement_1; ... statement_N; }

Programming and Data Structure37Cstatement(s)truefalseSingle-entry / single-exit structure

Programming and Data Structureint digit = 0; while (digit <= 9) printf (ʺ%d \nʺ, digit++);while :: Examples38int weight=100; while (weight > 65) { printf (ʺGo, exercise,ʺ); printf (ʺthen come back. \nʺ); printf (ʺEnter your weight:ʺ); scanf (ʺ%dʺ, &weight); }

Example: Compute 1+2+...+N39STARTREAD NSUM = 0 COUNT = 1SUM = SUM + COUNTCOUNT = COUNT + 1IS COUNT > N?OUTPUT SUMSTOPYESNOint main () { int N, count, sum; scanf (ʺ%dʺ, &N); sum = 0; count = 1; while (count <= N) { sum = sum + count; count = count + 1; } printf (ʺSum=%d\nʺ, sum); return 0; }Programming and Data Structure

printf (ʺEnter positive numbers, end with -1.0\nʺ); max = 0.0; scanf(ʺ%fʺ, &next); while (next != -1.0f) { if (next > max) max = next; scanf(ʺ%fʺ, &next); } printf (ʺThe maximum number is %f\nʺ, max) ;Example: Maximum of inputs40Example of Sentinel-controlled loop Inputs: 10 5 100 25 68 -1 Programming and Data Structure

Programming and Data Structurew4JNJMBSUPlXIJMFz

UIFDIFDLJTNBEFBUUIFbeginningw-PPQCPEZJTFYFDVUFEat least oncedo-while Statement41do { statement-1; statement-2; statement-n; } while (condition );do statement_to_repeat; while (condition ); Programming and Data Structure42Cstatement(s)truefalseSingle-entry / single-exit structure

Programming and Data Structureint digit = 0; do printf (ʺ%d \nʺ, digit++); while (digit <= 9);do-while :: Examples43int weight; do { printf (ʺGo, exercise, ʺ); printf (ʺthen come back. \nʺ); printf (ʺEnter your weight:ʺ); scanf (ʺ%dʺ, &weight); } while (weight > 65 );

Programming and Data Structurew5IFlGPSzTUBUFNFOUJTUIFNPTUDPNNPOMZVTFEMPPQJOHTUSVDUVSFJO$w(FOFSBMTZOUBYfor (expression1; expression2; expression3) statement-to-repeat; for (expression1; expression2; expression3) { statement_1; : statement_N; }for Statement44

Programming and Data Structurew)PXJUXPSLT rlFYQSFTTJPOzJTVTFEUPinitializeTPNFWBSJBCMFDBMMFEindex

UIBUDPOUSPMTUIFMPPQJOHBDUJPOrlFYQSFTTJPOzSFQSFTFOUTBconditionUIBUNVTUCFUSVFGPSUIFMPPQUPDPOUJOVFrlFYQSFTTJPOzJTVTFEUPalterUIFWBMVFPGUIFindexJOJUJBMMZBTTJHOFECZlFYQSFTTJPOz45int digit; for (digit=0; digit<=9;digit++) printf (ʺ%d \nʺ, digit);int digit; for (digit=9;digit>=0;digit--) printf (ʺ%d \nʺ, digit);

Programming and Data Structure46Single-entry / single-exit structureexpression2statement(s)truefalseexpression1expression3

Programming and Data Structureint fact = 1, i, N; scanf (ʺ%dʺ, &N); for (i=1; i<=N; i++) fact = fact * i; printf (ʺ%d \nʺ, fact);for :: Examples47int sum = 0, N, i; scanf (ʺ%dʺ, &N); for (i=1; i<=N, i++) sum = sum + i * i; printf (ʺ%d \nʺ, sum);Compute factorialCompute 12

+22
+...+N2

1SJOU2-D Figure48#define ROWS 3 #define COLS 5 .... for (row=1; row<=ROWS; row++) { for (col=1; col<=COLS; col++) { printf(ʺ*ʺ); } printf(ʺ\nʺ); }Programming and Data Structure

1SJOUAnother 2-D Figure49#define ROWS 5 .... int row, col; for (row=1; row<=ROWS; row++) { for (col=1; col<=row; col++) { printf(ʺ* ʺ); } printf(ʺ\nʺ); }Programming and Data Structure

lFYQSFTTJPOz

BOElFYQSFTTJPOzfor (fact=1, i=1; i<=10; i++) fact = fact * i; for (sum=0, i=1; i<=N; i++) sum = sum + i*i;Programming and Data Structure50expression2statement(s)truefalseexpression1expression3

Programming and Data Structurew"SJUINFUJDFYQSFTTJPOTr*OJUJBMJ[BUJPO

MPPQDPOUJOVBUJPO

BOEJODSFNFOUDBODPOUBJOBSJUINFUJDFYQSFTTJPOTfor (k=x; k <= 4*x*y; k += y/x) w*ODSFNFOUNBZCFOFHBUJWFEFDSFNFOU

for (digit=9; digit>=0; digit--) w*GMPPQDPOUJOVBUJPODPOEJUJPOJOJUJBMMZfalser#PEZPGforTUSVDUVSFOPUQFSGPSNFEr$POUSPMQSPDFFETXJUITUBUFNFOUBGUFSforTUSVDUVSFfor :: Some Observations51

A common mistake (; at the end)52Programming and Data Structureint fact = 1, i; for (i=1; i<=10; i++) fact = fact * i; printf (ʺ%d \nʺ, fact); int fact = 1, i; for (i=1; i<=10; i++); fact = fact * i; printf (ʺ%d \nʺ, fact); "Loop body" will execute only once!

Programming and Data Structurewhile (1) { statements }Specifying "Infinite Loop"53for (; ;) { statements }do { statements } while (1);

Programming and Data Structurew#SFBLPVUPGUIFMPPQ\^rDBOVTFXJUIwXIJMFwEPXIJMFwGPSwTXJUDIrEPFTOPUXPSLXJUI wJGwFMTFw$BVTFTJNNFEJBUFFYJUGSPNBwhile

do/while, forPSswitchTUSVDUVSFw1SPHSBNFYFDVUJPODPOUJOVFTXJUIUIFGJSTUTUBUFNFOUBGUFSUIFTUSVDUVSFThe "break" Statement Revisited54

Programming and Data Structure#include main() { int fact, i; fact = 1; i = 1; while (i<10) { /* break when fact >100 */ fact = fact * i; if ( fact > 100 ) { p rin tf (ʺFactorial of %d above 100ʺ, i); break; /* break out of the loop */ } i+ +; } }An example with "break"55

Programming and Data Structurew4LJQTUIFSFNBJOJOHTUBUFNFOUTJOUIFCPEZPGBwhile

forPSdo/whileTUSVDUVSFr1SPDFFETXJUIUIFOFYUJUFSBUJPOPGUIFMPPQwXIJMFBOEEPXIJMFr-PPQDPOUJOVBUJPOUFTUJTFWBMVBUFEJNNFEJBUFMZBGUFSUIFDPOUJOVFTUBUFNFOUJTFYFDVUFEwGPSTUSVDUVSF-expression3 is evaluated, then expression2 is evaluated.The "continue" Statement56

Programming and Data Structurefact = 1; i = 1; /* a program to calculate 10! */ while (1) { fact = fact * i; i ++; if (i<10) co ntinue; /* not done yet ! Go to loop and perform next iteration*/ break; }An example with "break" and "continue"57

Some Examples58

Example: SUM = 12

+ 22 + 32 + ...+ N2

59int main () { int N, count, sum; scanf (ʺ%dʺ, &N) ; sum = 0; count = 1; while (count <= N) { sum = sum + count∗count; count = count + 1; } printf (ʺSum = %d\nʺ, sum) ; return 0; }Programming and Data Structure

Example: Computing Factorial60int main () { int N, count, prod; scanf ("%d", &N) ; prod = 1; for (count=1;count <= N; count++) { prod = prod*count; printf (ʺFactorial = %d\nʺ, prod) ; return 0; }Programming and Data Structure

Example: Computing ex

series up to N terms61ex = 1 + x/1! + x2 /2! + x3 /3! + ...Programming and Data Structure

Example: Computing ex

series up to 4 decimal places62STARTREAD XTERM = 1 SUM = 0 COUNT = 1SUM = SUM + TERM TERM = TERM * X / COUNTCOUNT = COUNT + 1IS TERM < 0.0001?OUTPUT SUMSTOPYESNOProgramming and Data Structure

Programming and Data Structure#include main() { int n, i=2; scanf ("%d", &n); while (i < n) { if (n % i == 0) { p rin tf ("%d is not a prime \n", n); e xit ; } i+ +; } printf ("%d is a prime \n", n); } Example: Test if a number is prime or not63

Programming and Data Structure#include #include main() { int n, i=3; scanf ("%d", &n); while (i < sqrt(n)) { if (n % i == 0) { pri ntf ("%d is not a prime \n", n); e xit (0); } i = i + 2; } printf ("%d is a prime \n", n); }More efficient??64

Programming and Data Structure#include main() { int n, sum=0; scanf ("%d", &n); while (n != 0) { su m = sum + (n % 10); n = n / 10; } printf ("The sum of digits of the number is %d \n", sum); }Example: Find the sum of digits of a number65

Programming and Data Structure#include main() { int dec; scanf ("%d", &dec); do { pr intf ("%2d", (dec % 2)); de c = dec / 2; } while (dec != 0); printf ("\n"); } Example: Decimal to binary conversion66

Programming and Data Structure#include main() { int A, B, temp; scanf ("%d %d", &A, &B); if (A > B) {temp = A; A = B; B = temp;} while ((B % A) != 0) { te mp = B % A; B = A; A = temp; } printf ("The GCD is %d", A); }Example: Compute GCD of two numbers6712 ) 45 ( 3 36 9 ) 12 ( 1 9 3 ) 9 ( 3 9 0 Initial: A=12, B=45 Iteration 1: temp=9, B=12,A=9 Iteration 2: temp=3, B=9, A=3 B % A = 0 ➔ GCD is 3

Programming and Data Structurew"EEJUJPOBMBTTJHONFOUPQFSBUPST r

BC JTFRVJWBMFOUUPBBCBC

JTFRVJWBMFOUUPBBC

BOETPPOShortcuts in Assignments68

More about scanf and printf69

Programming and Data Structurew(FOFSBMTZOUBYTDBOGDPOUSPMTUSJOH BSH BSH BSHO BSH B

BWFSBHF

UZQF GPMMPXFECZBDPOWFSTJPODIBSBDUFSEntering input data :: scanf function70

Programming and Data Structurer$PNNPOMZVTFEDPOWFSTJPODIBSBDUFSTDTJOHMFDIBSBDUFS EEFDJNBMJOUFHFS GGMPBUJOHQPJOUOVNCFS TTUSJOHUFSNJOBUFECZOVMMDIBSBDUFS 9IFYBEFDJNBMJOUFHFS r8FDBOBMTPTQFDJGZUIFNBYJNVNGJFMEXJEUIPGBEBUBJUFN

B C 71
Programming and Data Structurew(FOFSBMTZOUBYQSJOUGDPOUSPMTUSJOH BSH BSH BSHO BSH G

FUDWriting output data :: printf function72

Programming and Data Structurew&YBNQMFTQSJOUGʺ5IFBWFSBHFPGEBOEEJTGʺ B C BWH

QSJOUGʺ)FMMPaO(PPEaO.PSOJOHaOʺ

QSJOUGʺEEEʺ

B C BC

QSJOUGʺGGʺ

Y Z

An example74Programming and Data Structure#include main() { int fahr; for (fahr=0; fahr<=100; fahr+=20) printf (ʺ%3d %6.3f\n", fahr, (5.0/9.0)*(fahr-32)); } 0 -17.778 20 -6.667 40 4.444 60 15.556 80 26.667 100 37.778

Print with leading zeros75Programming and Data Structure#include main() { int fahr; for (fahr=0; fahr<=100; fahr+=20) printf ("%03d %6.3f\n", fahr, (5.0/9.0)*(fahr-32)); }000 -17.778 020 -6.667 040 4.444 060 15.556 080 26.667 100 37.778

quotesdbs_dbs17.pdfusesText_23
[PDF] statewide common course numbering

[PDF] static and instance methods java

[PDF] static application security testing tools open source

[PDF] static auto extern and register variables in c

[PDF] static block in interface java 8

[PDF] static checking in compiler design

[PDF] static class c++

[PDF] static class variables: are final. are public. are private. are shared by all objects of a class.

[PDF] static data member have same copy

[PDF] static function c

[PDF] static function c declaration definition

[PDF] static function c example

[PDF] static function c header

[PDF] static function c language

[PDF] static function c programming