Sie sind auf Seite 1von 27

C Programming Language

C Programming Language
- Simple
- Robust
- Powerful

..
+1300042774
+1400593419
+1200274027

load basepay
add overpay
store grosspay

grossPay = basePay + overTimePay;

Hello World

#include <stdio.h>
/* function main begins program execution */
int main( void )
{
printf( "Welcome to C!\n" );
return 0; /* indicate that program ended successfully */
} /* end function main */

Hello World
#include <stdio.h>
int main()
{
printf("hello, world\n");
}

Hello World

#include <stdio.h>
/* function main begins program execution */
int main( void )
{
printf( "Welcome to C!\n" );
return 0; /* indicate that program ended successfully */
} /* end function main */

Escape Characters
\n
\t
\a
\\
\"

Newline. Position the cursor at the beginning of the next line.


Horizontal tab. Move the cursor to the next tab stop.
Alert. Sound the system bell.
Backslash. Insert a backslash character in a string.
Double quote. Insert a double-quote character in a string.

Lets set up the IDE

Hello World

\o
|\
/\

Adding two integers

Memory Concepts
scanf( "%d", &integer1 ); /* read an integer */

Memory Concepts
scanf( "%d", &integer2 ); /* read an integer */

Memory Concepts
sum = integer1 + integer2; /* assign total to sum */

Arithmetic in C

Arithmetic in C

Control Structures

The if statement

If students grade is greater than or equal to 60


Print Passed

The if..else statement

If students grade is greater than or equal to 60


Print Passed
else
Print Failed

Nested if..else statement


If students grade is greater than or equal to 90
Print A
else
If students grade is greater than or equal to 80
Print B
else
If students grade is greater than or equal to 70
Print C
else
If students grade is greater than or equal to 60
Print D
else
Print F

The while repetition


statement
While there are more items on my shopping list
Purchase next item and cross it off my list

exercise
A class of ten students took a quiz. The grades (integers in the range
0 to 100) for this
quiz are available to you. Determine the class average on the quiz.

exercise
The Fibonacci series

Increment and Decrement


operators

Different ways to
increment/decrement
int number;
number = number + 1;
number += 1;
++number;
number++;

The for loop

exercise
A person invests $1000.00 in a savings account yielding 5%
interest. Assuming that
all interest is left on deposit in the account, calculate and
print the amount of money
in the account at the end of each year for 10 years. Use the
following formula for
determining these amounts:
a = p(1 + r)n
where
p is the original amount invested (i.e., the principal)
r is the annual interest rate
n is the number of years
a is the amount on deposit at the end of the nth year.

C : How To Program
Paul Deitel Harvey Deitel

Das könnte Ihnen auch gefallen