C Programming Introduction - Part 3

C Programming Introduction - Part 3 - 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 3) Page 1 © Dr. Mark J. Llewellyn COP 3223: C Programming Spring 2009 Introduction To C - Part 3 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 3) Page 2 © Dr. Mark J. Llewellyn More Basic C Programming Returning briefly to the program from the previous set of notes that produced the sum of two integer values, I want to show you a slight modification to the code that we could have made, which is perfectly legal in C. The modification involves the need and/or use of the variable sum . In the version of the program in the previous set of notes, we defined a variable, called sum , to hold the sum of integer1 + integer2 . As is shown in the code on the next page, we didn’t really need this variable, as we could have moved the calculation of the sum into the printf function call.
Background image of page 2
COP 3223: C Programming (Intro To C – Part 3) Page 3 © 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 //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); printf("The sum is %d\n", integer1 + integer2); printf("\n\n"); system("PAUSE"); return 0; } //end main function Modified version of the sum of two integers program
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 3) Page 4 © Dr. Mark J. Llewellyn A Brief Aside On Data Types In C In the last section of notes, when we introduced the concept of a variable , we said that every variable is required to have a name and a type . There are many different data types in C, but for right now, we are restricting ourselves to two types: int (short for integer) and float (short for floating-point). We’ll later see that correctly choosing the type of a variable is important from a program efficiency point of view, as well as determining what kinds of operations can be performed on the variable. The type of a numeric variable (a variable capable of storing a number) determines the smallest and largest value that can be stored in a variable of that type.
Background image of page 4
COP 3223: C Programming (Intro To C – Part 3) Page 5 © Dr. Mark J. Llewellyn A Brief Aside On Data Types In C Data type Smallest value Largest value short int -32,768 32,767 unsigned short int 0 65,535 int -32,768 32,767 unsigned int 0 65,535 long int -2,147,483,648 2,147,483,647 unsigned long int 0 4,294,967,295 The int data type on a 16-bit machine A machine with a 16-bit word size means that a “word” (the addressable component of the
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 / 38

C Programming Introduction - Part 3 - 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