C Programming Introduction - Part 2

C Programming Introduction - Part 2 - COP 3223: C...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3223: C Programming (Intro To C – Part 2) Page 1 © Dr. Mark J. Llewellyn COP 3223: C Programming Spring 2009 Introduction To C - Part 2 School of Electrical Engineering and Computer Science University of Central Florida Instructor : Dr. Mark Llewellyn markl@cs.ucf.edu HEC 236, 407-823-2790 http://www.cs.ucf.edu/courses/cop3223/spr2009/section1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3223: C Programming (Intro To C – Part 2) Page 2 © Dr. Mark J. Llewellyn More Basic C Programming Continuing where we left off in the last section of notes, we’ll continued to introduce some of the basic features of C in this section of notes. As we move on, note that the basics of C programming never change. We’ll always use the same basic style of coding, and many of the statements we include in subsequent programs are the same we used in our very first program. However, pay attention because we will always be introducing new features of the language.
Background image of page 2
COP 3223: C Programming (Intro To C – Part 2) Page 3 © Dr. Mark J. Llewellyn A Second C Program Again the line numbers are for illustrative purposes – I simply turned on this option in the IDE. Do not type them in your code.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COP 3223: C Programming (Intro To C – Part 2) Page 4 © Dr. Mark J. Llewellyn // sum of two integers (a second C program) // This program adds two, user supplied, integers and prints their sum // January 13, 2009 Written by: Mark Llewellyn #include <stdio.h> //main function int main() { int integer1; //first integer to be entered by user int integer2; //second integer to be entered by user int sum; //variable in which the sum will be stored //write prompts to user and get numbers printf("Enter first integer number\n"); scanf("%d", &integer1); printf("Enter second integer number\n"); scanf("%d", &integer2); sum = integer1 + integer2; //assign the total to sum printf("The sum is %d\n", sum); printf("\n\n"); system("PAUSE"); return 0; } //end main function Text version of the program – maybe easier to read for input.
Background image of page 4
COP 3223: C Programming (Intro To C – Part 2) Page 5 © Dr. Mark J. Llewellyn A Detailed Look At The Program The biggest difference between our first C program and this second C program is that this one requires the user to input two integer values for the program to add together. Our first program simply printed a line of text without requiring any input from the user. There are a number of different ways that input can be generated by the user to be entered into a program in C. We’ll start with a very simple technique which uses a standard library function named scanf (which like printf is defined in the stdio.h file). COMMON PROGRAMMING ERROR: It is important to note that standard library functions like printf and scanf are not part of the C programming language, rather they are part of a library of functions are available to C programs. This means, for example, that the compiler will not be able to detect spelling errors in printf or scanf. When the compiler compiles a printf statement, it merely provides space in the object program for a “call” to the library function, but the compiler does not know where the library functions are – that is the linker’s job.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/21/2010 for the course COP 3223 taught by Professor Guha during the Spring '08 term at University of Central Florida.

Page1 / 21

C Programming Introduction - Part 2 - COP 3223: C...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online