CSC215 Homework Homework 03 Due date: Oct 07, 2016.

Slides:



Advertisements
Similar presentations
1 CSE1301 Computer Programming Lecture 8 Selection.
Advertisements

BBS514 Structured Programming (Yapısal Programlama)1 Selective Structures.
Selection Statements Selects statements to execute based on the value of an expression The expression is sometimes called the controlling expression Selection.
C Programming Input output Conditional statements and Iterative statements Rohit Khokher.
C workshop #3 flow control / strings.
Tutorial #5 Summer while x = -2; while (x < 0) { printf("x is still negative :(\n"); x++; } printf("x is no longer negative.\n");
1 CSE1301 Computer Programming Lecture 9 Selection.
C workshop Yuli Kaplunovsky - Today - Introduction to C Recommended book: The C programming Language / Kernighan & Ritchie.
1 Review of Class on Oct Outline of Chapter 4  How to write a function?  Function Prototypes  Function Invocation  Function Definition  The.
Introduction to Computers and Programming Class 15 Introduction to C Professor Avi Rosenfeld.
Imperative Programming Prof. Béat Hirsbrunner Amine Tafat, PhD Student Matthias Buchs and Raphaël Lesceux, Graduate Students Department of Informatics.
Guidelines for working with Microsoft Visual Studio.Net.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
C++ programming I Lab#3 Control Statements Instructor: Eng. Ruba A. Salamah Tuseday: 17/10/2010.
1 Agenda - Loops while for for & while Nested Loops do-while Misc. & Questions.
Algorithms and Computing Lecture 3 Control Statements By Dr. M. Tahir Khaleeq.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee C Language Part 2.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
Xuan Guo Review for the Final Exam Xuan Guo July 29 8:30AM – 10:30AM Classroom South 300 CSC
Lecture 13 Transition from Fortran to C Yi Lin Feb 27, 2007.
IIT Kanpur C Course Lecture 3 Aug 31, Rishi Kumar, Final year BT-MT, CSE.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
CS115 FALL Senem KUMOVA-METİN1 The Fundamental Data Types CHAPTER 3.
USER DEFINED FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Solution to Midterm Exam
CSC Programming for Science Lecture 8: Character Functions.
Char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout.
CMSC 1041 More Loops ‘for’ loops and ‘do-while’ loops.
Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different.
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
CPT: Chars/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to look at how C processes characters 4. Character.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 6.
Dr. Sajib Datta Sep 8,  char type technically is an integer type  Computer uses numeric codes to represent characters, and store characters.
Tutorial #4 Summer 2005.
CSE1301 Sem Selection Lecture 25 Lecture 9: Selection.
CSE 220 – C Programming Loops.
LESSON 3 IO, Variables and Operators
CSE1320 Loop Dr. Sajib Datta
Kontrola toka izvršenja
The C “switch” Statement
INC 161 , CPE 100 Computer Programming
توابع ورودي-خروجي.
The C “switch” Statement
C Programming Variables.
אבני היסוד של תוכנית ב- C
CSC215 Homework Homework 04 Due date: Oct 14, 2016.
Loops in C.
The switch Statement Topics Multiple Selection switch Statement
The switch Statement Topics Multiple Selection switch Statement
CSC215 Lecture Control Flow.
Program Control Topics While loop For loop Switch statement
CSC215 Homework Homework 06 Due date: Oct 30, 2016.
CSC215 Homework Homework 05 Due date: Oct 21, 2016.
CSC215 Homework Homework 05 Due date: Oct 21, 2016.
CSI 121 Structure Programming Language Lecture 9 Selection
CSC215 Homework Homework 02 Due date: Sep 30, 2016.
Incremental operators
Week 2 Variables, flow control and the Debugger
UMBC CMSC 104 – Section 01, Fall 2016
Your questions from last session
Computer Programming Techniques Semester 1, 1998
More Loops Topics Counter-Controlled (Definite) Repetition
Arrays.
More Loops Topics Counter-Controlled (Definite) Repetition
The switch Statement Topics Multiple Selection switch Statement
CSC215 Lecture Control Flow.
Iteration Statement for
More Loops Topics Counter-Controlled (Definite) Repetition
컴퓨터 프로그래밍 기초 - 13th : 마지막 수업 -
Presentation transcript:

CSC215 Homework Homework 03 Due date: Oct 07, 2016

Question 1 what is the output of the following code fragments: int n =5, i; if (n > 0) for (i = 0; i < n; i++) if (i % 7 > 0) { printf("..."); return i; } else printf("error, n is negative\n"); int c, i, j; char s[8] = "STRESSED"; for (i = 0, j = 7; i < j; i++, j--) { c = s[i]; s[i] = s[j]; s[j] = c; } printf("%s\n", s); int a = 10; do { if( a == 15) { a = a + 1; Continue; } printf("value of a: %d\n", a); a++; } while( a < 20 ); int x = 5, y = -3; if (x = y) printf("%d\t%d\n", x, y); else if (x > y) printf("%d > %d\n", x, y); else printf("%d < %d\n", x, y);

Question 2 complete the following program: #include <stdio.h> int main(){ char ch = getchar(); if (....................................) /* test if ch is a capital letter */ printf("%c is a capital letter\n", ch); else if (....................................) /* test if ch is a small letter */ printf("%c is a small letter\n", ch); else if (....................................) /* test if ch is a digit */ printf("%c is a digit\n", ch); else if (....................................) /* test if ch is an arithmetic operator */ printf("%c is an arithmetic operator\n", ch); else printf("Unrecognized character"); return 0; }

Question 3 find the number of iterations of each loop below: int a = 10; do { if( a == 15) a = a + 1; printf("value of a: %d\n", a++); } while( a < 20 ); int i; for(i=900;-5 ;i/=3){ printf("%d ",i); if(i<=34) break; } int i,j,k; for(i=0,k=0;i<=5,k<=3;i++,k+=2){ printf("%d ",i+k); } int n = 100; While (--n) printf("%d\n", n*2); unsigned char c; for(c=255; c; c>>=1){ printf("%d ",c); } unsigned char c; for(c=128; c; c>>=1){ printf("%d ",c); } unsigned char c; for(c=1; c; c<<=1){ printf("%d ",c); }