Structure of code: - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Structure of code:

Description:

#include math.h void main( ) float x, sinx, cosx,powx2; printf('n Enter a number' ... Include the math library: #include math.h Now you can use math functions: ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 10
Provided by: Fio110
Category:

less

Transcript and Presenter's Notes

Title: Structure of code:


1
Structure of code
/ A simple C program / include
ltstdio.hgt include ltconio.hgt void main(
) printf(\n This is a C program) printf(\n
Press any key to exit) getch( )
2
Variables
void main( ) int x float y double
z printf(\n Enter value for x) scanf(d,
x) printf(\n Enter value for
y) scanf(f, y) printf(\n Enter value
for z) scanf(lf, z) printf(x d, y
f, z lf, x, y, z) getch( )
3
printf and scanf
void main( ) int x float y double
z printf(\n Enter value for x) scanf(d,
x) printf(\n Enter value for
y) scanf(f, y) printf(\n Enter value
for z) scanf(lf, z) printf(x d, y
f, z lf, x, y, z) getch( )
4
Defining Variables
void main( ) float pounds, ounces printf(\n
Enter value for pounds) scanf(f,
pounds poundsounces16 ouncespounds16 pr
intf(f pounds is f ounces, pounds,
ounces) getch( )
Need to order calculations correctly.
5
Math.h
include ltstdio.hgt include ltconio.hgt include
ltmath.hgt void main( ) float x, sinx,
cosx,powx2 printf(\n Enter a
number) scanf(f, x) sinx
sin(x) cosx cos(x) powx2
pow(x,2) printf(\n sin f is f, cos f is f,
f squared is f, x, sinx, x, cosx,
x, powx2) getch( )
Help files HELP menu ? INDEX. Then type name of
command.
6
Loop runs the same command while certain
conditions are satisfied
Do.while Loop
void main( ) int i 0 do printf(\n
d, i) i while (ilt10) getch( )
7
While Loop Very similar to Dowhile
While Loop
void main( ) int i 0 while (ilt10)
printf(\n d, i) i getch( )
8
For Loop More detailed conditions than the
DoWhile or While loops
For Loop
void main( ) int i double value, root for
(i1, ilt20, i) valuei
rootsqrt(i) printf(\n Sq. root of lf is
lf,value,root) getch( )
Loop 1. i1, value 1, prints ?1. 2. For
statement increments i by 1 i i1 i 2, value
2, prints ?2. 19. i 19, value 19, prints
?19. 20. i 20, value 20, prints ?20. 21. i no
longer ? 20 so for loop is not run.
9
If.Else gives 2 (or more) conditions that may
be satisfied.
If.else statements
void main( ) int z0 do if
(z20) printf(\n EVEN) else printf(\n
ODD) z while zlt20
I have put this in a dowhile loop otherwise z
would just keep increasing
  • Ifelse if.else
  • If condition what happens
  • Second if condition what happens
  • Else what happens if neither 1 nor 2
  • are meet.
Write a Comment
User Comments (0)
About PowerShow.com