Vous êtes sur la page 1sur 2

ECE

175: Computer Programming for Engineering Applications


Fall 2013 To be demonstrated the week of Sep. 2th Sep. 7st
The purpose of the first in-lab assignment is to familiarize you with the MS Visual Studio 2012 environment. This lab consists of a series of exercises that will help you edit, compile, and execute C programs. Exercise 1: Follow the TA instructions for setting up the MS Visual Studio 2012 environment. These instructions can also be found at the class website under the tab Resources. Exercise 2: My first C program Compilation refers to the process of translating a program written in a high-level programming language (such as C) to low-level executable code (object code) that can be then executed by the CPU. Type the following program, save it, compile it and execute it. #include <stdio.h> // standard input library int main(void) { printf("My first C program\n"); // printing a prompt on screen return (0); // return value for main } Exercise 3: Experimenting with the printf function: Type the following program, compile it and execute it. Observe the various output format based on the different arguments given in the printf function. #include<stdio.h> // Example of printing variables with the printf function int main(void) { int x; // declaration of an integer float y; // declaration of a float char c; // declaration of a char x = 125; // initialization y = 3.14159; // initialization c = 'a'; // initialization printf("Printing an integer number:%d\n", x); // integer

printf("Printing a float number:%f\n",y); // real printf("Printing a character:%c\n",c); // char printf("You can also print message prompts\n"); printf("Integer:%d\tFloat:%.1f\n",x, y); // printing tabs printf("Two decimals:%4.2f\nThree decimals:%6.3f\n",y,2*y); return(0); } Exercise 4: Write printf statements that print the following formatted numbers. The printout should be obtained from variables and not be hardcoded within the printf double quotations. For item 10, use a char variable to print the letter a. 1. x = nn125 2. y = n3.14 3. y+1 = 4.14 4. y = n3.141590 5. x + y = 6. x/5 = 7. x/100 = 8. x/y = 9. (2*x+1)%x = 10. a + 3.14

Vous aimerez peut-être aussi