MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

Similar documents
MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

Lecture 2: C Programming Basic

Structured programming

Computer System and programming in C

These are reserved words of the C language. For example int, float, if, else, for, while etc.

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

Programming and Data Structure

Programming and Data Structures

NWEN 241 Systems Programming Exercises (Set 1)

Course Outline Introduction to C-Programming

AMCAT Automata Coding Sample Questions And Answers

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

Lecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar

Computers Programming Course 5. Iulian Năstac

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Materials covered in this lecture are: A. Completing Ch. 2 Objectives: Example of 6 steps (RCMACT) for solving a problem.

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

MA 511: Computer Programming Lecture 23 Partha Sarathi Mandal

Programming & Data Structure: CS Section - 1/A DO NOT POWER ON THE MACHINE

Basic Assignment and Arithmetic Operators

MA 511: Computer Programming Lecture 10: Pointers (Contd..) Partha Sarathi Mandal

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Lecture 3 Tao Wang 1

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II)

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Operators and Expressions:

BSM540 Basics of C Language

Fundamental of Programming (C)

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

CS102: Variables and Expressions

Unit 7. Functions. Need of User Defined Functions

SEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010

Full file at C How to Program, 6/e Multiple Choice Test Bank

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

Partha Sarathi Mandal

ME 172. Sourav Saha. Md. Mahamudul Hossain Kazi Fazle Rabbi Saddam Hossain Joy Kamruzzaman Lecturer,Dept. of ME,BUET

DEPARTMENT OF MATHS, MJ COLLEGE

BİL200 TUTORIAL-EXERCISES Objective:

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

Informatica e Sistemi in Tempo Reale

Fundamentals of Programming

Data Types and Variables in C language

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

Arithmetic type issues

Basics of Programming

LOOPS. 1- Write a program that prompts user to enter an integer N and determines and prints the sum of cubes from 5 to N (i.e. sum of 5 3 to N 3 ).

Function. specific, well-defined task. whenever it is called or invoked. A function to add two numbers A function to find the largest of n numbers

Data types, variables, constants

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Lecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours?

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }

Use a calculator and c = 2 π r to calculate the circumference of a circle with a radius of 1.0.

Engineering 12 - Spring, 1999

Preview from Notesale.co.uk Page 6 of 52

Fundamentals of Programming

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Partha Sarathi Mandal

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

1. Basics 1. Write a program to add any two-given integer. Algorithm Code 2. Write a program to calculate the volume of a given sphere Formula Code

Chapter 3. Section 3.10 Type of Expressions and Automatic Conversion. CS 50 Hathairat Rattanasook

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Arithmetic Expressions in C

EL2310 Scientific Programming

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

Chapter 2: Basic Elements of C++

Simple Java Reference

BASIC ELEMENTS OF A COMPUTER PROGRAM

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Objectives. In this chapter, you will:

C PROGRAMMING LAB MANUAL

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

3/13/2012. ESc101: Introduction to Computers and Programming Languages

WARM UP LESSONS BARE BASICS

Arithmetic Expressions Lesson #1 Outline

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

Work relative to other classes

C Programming Lecture V

Lecture 3. More About C

Structured programming. Exercises 3

Lecture 5: C programming

Procedural programming with C

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

C: How to Program. Week /Mar/05

1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

C Programming

Programming for Engineers: Operators, Expressions, and Statem

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

CMPE-013/L. Introduction to C Programming

Transcription:

MA 511: Computer Programming Lecture 2: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11

Largest of the set of numbers START READ NUMBER LARGEST NUMBER ANY MORE NUMBERS? Yes READ NUMBER No WRITE LARGEST STOP No IS NUMBER > LARGEST Yes LARGEST NUMBER

Exercise 1. Celsius to Fahrenheit conversation. 2. The largest of a set of numbers. 3. Given integer is prime or composite. 4. LCM of two given integers. 5. GCD of two given integers. 6. Solve: Ax^2 + Bx + C = 0 7. The Fibonacci numbers: Let a 0 = 1 and a 1 = 1, and an be given by the following recursive definition: a n = a n-1 + a n-2

Exercise 8. Write a program which takes in a positive integer and prints one factorization of it into primes.

/* Calculate the area of a circle */ #include<stdio.h> main(){ float radius, area; printf("radius =? "); scanf("%f", &radius); area = 3.14159 * radius * radius; printf("area = %f", area); } /* end of main */ Example C Program Preprocessor directive, stdio.h is included in the compiled machine code at #. It contains the standard I/O routines. Must be in the first column. Must not end with a semicolon. Declaration : it informs the compiler that radius and area are variables names and that individual boxes must be reserved for them in the memory of the computer. main() is a function, is required in all C pgs, it indicate start of a C pgs., main() it is not followed by a comma or semicolon. Braces { and } enclosed the computations carried out by main() Every statement is terminated by a semicolon Comments (remarks) are placed anywhere within the program within delimiters /* end of main */ or // end

/* Calculate the area of a circle */ #include<stdio.h> #define PI 3.14159 main(){ float radius, area; int i, n; printf("n =? "); scanf("%d", &n); for(i=1; i<= n; i=i+1){ printf("radius =? "); scanf("%f", &radius); area = PI * radius * radius; printf("area = %f\n", area); } /* end of for */ } /* end of main */ Example C Program Symbolic constant is a name that substitutes for a sequence of characters; numeric, character or string constant. It is replaced by its corresponding character constant during compile printf & scanf are not part of the C language; there is no input or output defined in C itself. Its just a useful function from the standard library of functions that are normally accessible to C pgs. The behavior of printf & scanf are defined in the ANSI standard. for is looping statement, the 1 st expression specifies an initial value for an index, 2 nd determines whether or not the loop is continued, 3 rd allows the index to be modified at the end of each pass.

Data types 1. Integer constant int a, b; (for 32bit machine ) long int a, b; Signed (- 2 31 to + 2 31-1), Unsigned : (0 to 2 32-1) short int a, b; Signed: Considered 16 bit integer with range (- 2 15 = -32768 to + 2 15-1 = +32767), Unsigned (0 to (2 16-1)=65535) 2. Floating point constant float a = 2.0, b = 0.9999, sum = 0.; [restricted within 3.4 x 10-38 to 3.4 x 10 38 ] double fact = 0.11236E-6; [0. 11236 x 10-6 ] [within 1.7 x 10-308 to 1.7 x 10 308 ] 3. Character constant char a = x, b = 3, c = #, text[18] = kolkata ; 4. String constant string a = Delhi, 100011, b = $20.95 ;

1. Integer constant Data types int a, b; (for 32-bit machine) long int a, b; Signed (- 2 31 to + 2 31-1), Unsigned : (0 to 2 32-1) short int a, b; Signed: Considered 16 bit integer with range (- 2 15 = -32768 to + 2 15-1 = +32767), Unsigned (0 to (2 16-1)=65535)

Variable declaration int i,j,k; long p,q; short s; unsigned u; float r; double dr; long double lr; char c, text[10];

Operators Operator purpose + addition - subtraction * multiplication / division % remainder after integer division (module operator)

Operands conversion float @ double = double @ : operator float @ long double = long double float @ char/long int/short int/int = float long int @char/short int/int = long int int i = 7; float f = 5.5; char c = w [w= 119 (ASCII) American Standard Code for Information Interchange] i+f = 12.5 float i+c = 126 int i+c- 0 = 78 int [zero, 0= 48 (ASCII)] (i+c)-(2*f/5) = 123.8 float