CSCE 206 Lab Structured Programming in C

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Computer Programming w/ Eng. Applications
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Lecture 2 Introduction to C Programming
Introduction to C Programming
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Lab 5 rC language Elements rVariables Declarations and Data Types rGeneral Form of a C Program rArithmetic Expressions rFormatting Numbers rExercises Note:
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Yu Yuanming CSCI2100B Data Structures Tutorial 3
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CS140: Intro to CS An Overview of Programming in C (part 3) by Erin Chambers.
Khalid Rasheed Shaikh Computer Programming Theory 1.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
SCP1103 Basic C Programming SEM1 2010/2011 Arithmetic Expressions Week 5.
Lecture2.
Arithmetic Expressions
CSCE 206 Structured Programming in C
Computer Science 210 Computer Organization
Zhang Hongyi CSCI2100B Data Structures Tutorial 3
CSE 220 – C Programming C Fundamentals.
Formatted Input/Output
INC 161 , CPE 100 Computer Programming
Chapter 2 Overview of C.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Formatted Input/Output
Introduction to C Programming
Visit for more Learning Resources
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
CSCE 206 Lab Structured Programming in C
Chapter 2 - Introduction to C Programming
Introduction to C Programming
CSCE 206 Lab Structured Programming in C
Chapter 2 - Introduction to C Programming
Conversion Check your class notes and given examples at class.
Lecture3.
CSCE 206 Lab Structured Programming in C
Functions.
Chapter 2 - Introduction to C Programming
Arrays.
CSCE 206 Lab Structured Programming in C
DATA TYPES There are four basic data types associated with variables:
Course Outcomes of Programming In C (PIC) (17212, C203):
Introduction to C Programming
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
Getting Started With Coding
Introduction to C Programming
Presentation transcript:

CSCE 206 Lab Structured Programming in C Fall 2018 Lecture 2 Ehsanul Haque Nirjhar

General Structure of a C program Header files and other preprocessing directions are included in the directive Variables are declared inside the main function. They can be integer, float, string, character etc. Calculations and instructions are placed in the statements portion of the code. Never ever forget to put semicolon(;) after each line of code in declaration and statements!! preprocessing directives int main(void) { declarations statements }

#include and #define These are basic preprocessing directives #include <filename.h> looks for filename.h header file in standard places. We will use #include <stdio.h> that is required for working with standard input and output processes. #define NAME VALUE makes sure that all occurrences of NAME corresponds to same VALUE #define GRADE 4 makes sure that any time GRADE is used in the code, it has a value 4

Variable Types & Operators Common Variable Types: int float double char Common Arithmetic Operators: +, - , *, /, %

#printf() and #scanf() Used for formatted printing output and reading input respectively printf("%conversion_character",variable_name) prints the value storedin the variable. scanf("%conversion_character",&variable_name) reads the value from user prompt to store in the variable conversion_character is for specifying the data type & used in scanf(), specifies the memory location of the variable You can write anything inside “” of the printf() function to show that on screen

Highly used conversion characters How the corresponding argument is printed c character d decimal integer f floating-point number s string

Sample Code-1 /*Lab2 sample code-1 */ #include <stdio.h> int main(void) { int n; n=5; printf("%d",n); // prints the value of n on screen return 0; }

Sample Code-2 /*Lab2 sample code-2 */ #include <stdio.h> int main(void) { float n; n=5.0; printf("Value stored in n:%f",n); // Difference?? return 0; }

Sample Code-3 /*Lab2 sample code-3 */ #include <stdio.h> int main(void) { int n; printf("Enter a number:"); // Asks user for input scanf("%d",&n); printf("You have entered:%d",n); // Shows the number return 0; }

Sample Code-4 /*Lab2 sample code-4 */ #include <stdio.h> #define VAL 2 // defining a constant int main(void) { int n,x; printf("Enter a number:"); // Asks user for input scanf("%d",&n); x=n*VAL; printf("Double of your input:%d",x); // Shows the number return 0; }

Now it’s your turn!

Practice Problem-1 Write a program with a char variable and an int variable. Store user input in the variables using scanf(). Print them on a line with a message saying what each one is. Example: If the user gives input 5 and E for int and char respectively, the program will print character: E integer: 5

Practice Problem-2 Write a program that calculates the area of circle of a given radius. First, the program will ask user to give a input for radius. Then it will print the area of the circle. Example: If the user gives 2 as the input of radius, the program should print Area of Circle: 12.5663

Practice Problem-3 Write a program that takes two integers as input in two variables a and b. It prints out the following: Sum of the 2 integers Result of the operation where a is divided by b Remainder of the operation where a is divided by b