1-Introduction To Algorithms and C Programming
1-Introduction To Algorithms and C Programming
Introduction to Algorithms
and Programming
• Software
– Programs and data (intangible).
– A program is a series of instructions.
• Application program
– generic term for any other kind of software.
– word processors, missile control systems, games.
Hi, Heather.
fetch
execute decode
Information is moved
Secondary memory
Central between main memory
devices provide
Processing and secondary memory
long-term storage
Unit as needed
Hard disks
Floppy disks Hard Disk
ZIP disks
Writable CDs Main
Writable DVDs Memory
Tapes Floppy Disk
Input / Output Devices
Edit and
save program
errors
errors
Compile program
The computer will always do what you tell it to do, not what you want it to do.
C Program Structure
#include <stdio.h>
main()
{
}
C Program Structure
#include <stdio.h>
main()
{
All programs must have a main function
}
C Program Structure
#include <stdio.h>
main()
{
char acharacter;
int i, j = 18, k = -20;
printf("Initially, given j = 18 and k = -20\n");
int main()
int id[7] = {1, 2, 3, 4, 5, 6, 7}; {
float x[5] = {5.6, 5.7, 5.8, 5.9, 6.1}; int i, j = 18, k = -20;
char vowel[6] = {'a', 'e', 'i', 'o', 'u', '\0'}; printf("Initially, given j = 18 and k = -20\n");
printf("Do some operations..."
"i = j / 12, j = k / 18 and k = k / 4\n");
enum days {Mon, Tue, Wed, Thu, Fri, i = j / 12;
Sat, Sun}; j = k / 8;
k = k / 4;
printf("At the end of the operations...\n");
printf("i = %d, j = %d and k = %d\n", i, j, k);
return 0;
}
C Program Structure - Comments
• Comments in a program are called inline // this comment runs to
documentation the end of the line
• They should be included to explain the
purpose of the program and describe
processing steps
/* this comment runs to the
terminating
• They do not affect how a program works symbol, even across line
• C comments can take two forms: breaks */
// for printf()
#include <stdio.h>
#include <string.h> // for strcpy_s() and their family
#include <stdio.h>
void main(void)
{
int MyAge = 12;
printf("My name is Mr. C. Cplusplus\n");
… }
C Program Structure - Commas
Commas separate function arguments, list of
variables, aggregate values. e.g.
#include <stdio.h>
e.g.
q = q + 3; or q += 3;