Divisibility Find out if a number, Numb, is divisible by another number, Div. Is 432 divisible by 3? Is 432 divisible by 4? 432 / 3 = ? 432 / 4 = ? 432.

Slides:



Advertisements
Similar presentations
For loops For loops are controlled by a counter variable. for( c =init_value;c
Advertisements

Unit 2 The if-else-if LECTURE – 14
Selection Statements Selects statements to execute based on the value of an expression The expression is sometimes called the controlling expression Selection.
Modular Programming (2) H&K Chapter 6 Instructor – Gokcen Cilingir Cpt S 121 (July 8, 2011) Washington State University.
1 ICS103 Programming in C Lecture 17: Array of Strings.
ICS103 Programming in C Lecture 11: Recursive Functions
LOOP (Part 2) for while do-while 1. TK1913-C Programming2 TK1913-C Programming 2 Loop : for Loop : for Condition is tested first Loop is controlled by.
1 CSE1301 Computer Programming Lecture 27 Recursion (Part 1)
לולאות 02 יולי יולי יולי 1502 יולי יולי יולי 1502 יולי יולי יולי 15 1 Department of Computer Science-BGU.
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);
Programming Control Flow. Sequential Program S1 S2 S5 S4 S3 int main() { Statement1; Statement2; … StatementN; } Start End.
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
CP104 Introduction to Programming Modular Programming Lecture 16__ 1 Modular Programming II Functions with single output Functions with multiple outputs.
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
1 If statement and relational operators –, >=, ==, != Finding min/max of 2 numbers Finding the min of 3 numbers Forming Complex relational expressions.
Do-while loop Syntax do statement while (loop repetition condition)
CP104 Introduction to Programming Selection structures_2 Lecture 10 __ 1 If statement (preview version) Syntax form: if ( condition) Statements else Statements.
Chapter 6: Control Structures Computer Programming Skills Second Term Department of Computer Science Foundation Year Program Umm Alqura.
Introduction to C Programming CE Lecture 4 Further Control Structures in C.
Scope: Portion of the program in which the identifier can be referenced. Various types of scope, my examples are of block scope and global scope.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
FUNCTION Dong-Chul Kim BioMeCIS UTA 12/7/
Introduction to Programming Lecture 7: Repeating Statements.
Problems Reads a letter grade from user and displays the corresponding range for that letter grade (A  , B  80-89, C  70-79, D  60-69, otherwise.
1 Agenda If Statement True/False Logical Operators Nested If / Switch Exercises & Misc.
Pointers Value, Address, and Pointer. Values and Addresses int x, y, z; y x z values of x,
CSCI 171 Presentation 3. Operators Instructs C to perform some operation Assignment = Mathematical Relational Logical.
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Principle Prog Revision. Question 1 (a) Identify errors in the following program segment and how the errors can be corrected. void main(){ constant int.
Logical Operator It is useful to test multiple conditions OperatorANDORNOT Symbol&&||! ConditionBOTHEITHERREVERSE.
While loop Write a program that asks the user to enter a number, then displays whether this number is even or odd. The program repeats until the user quits.
DATA TYPE, MEMORY, AND FUNCTION Dong-Chul Kim BioMeCIS UTA 2/18/
Dr. Sajib Datta CSE 1320 Arrays, Search and Sort.
Dr. Sajib Datta Feb 21,  In the last class we discussed: ◦ Bubble sort  How it works  performance.
Functions Dr. Sajib Datta Functions A function is a self-contained unit of program code designed to accomplish a particular task. Some functions.
1 Agenda Arrays: Definition Memory Examples Passing arrays to functions Multi dimensional arrays.
Arrays Name, Index, Address. Arrays – Declaration and Initialization int x; y[0] y[1] y[2]
 Real numbers representation - Floating Point Notation  First C Program  Variables Declaration  Data Types in C ◦ char, short, int, long, float, double,
Dr. Sajib Datta Sep 3,  A new operator used in C is modulus operator: %  % only used for integers, not floating-point  Gives the integer.
Week 3.  TO PRINT NUMBERS FROM 1 TO 20  TO PRINT EVEN NUMBERS FROM 1 TO 20 2.
Tutorial #4 Summer 2005.
Why functions segments of code that repeat several times
最新C程式語言 蔡明志 編著.
Functions Dr. Sajib Datta
Functions Dr. Sajib Datta
CSE1320 INTERMEDIATE PROGRAMMING Operators+Conditionals+Loop
Dynamic memory allocation and Intraprogram Communication
מבוא כללי למדעי המחשב תרגול 2
Control Structures Lecture 7.
Introduction to Programming
Константе оператори Задаци....
C Programming Variables.
Programming application CC213
מ- C++ ל- C קרן כליף.
בקרת קלט #include int main () { int num; printf("Enter number(0-100)\n"); if (scanf("%d",&num) != 1) printf(“Input Error\n”); return 1; } printf("Very.
A function with one argument
Incremental operators
Week 2 Variables, flow control and the Debugger
Control Structures Lecture 6.
Week 6 CPS125.
Recursion.
CSCE 206 Lab Structured Programming in C
CSCE 206 Lab Structured Programming in C
FUNCTION ||.
Control Structure គោលបំណងនៃមេរៀន អ្វីជា Control structure ?
Presentation transcript:

Divisibility Find out if a number, Numb, is divisible by another number, Div. Is 432 divisible by 3? Is 432 divisible by 4? 432 / 3 = ? 432 / 4 = ? 432 % 3 = ? 432 % 4 = ?

Divisibility #include int main(void) { int num, div; printf("Please enter a number and a divider: "); scanf("%d%d", &num, &div); if(num%div == 0) printf("%d is divisible by %d\n", num, div); else printf("%d is not divisible by %d\n", num, div); } return(0);

Pick a number between 1 and 5 >3>454>23>121 4,51,2,3 1,2

Pick a number between 1 and 5 #include int main(void) { int answ; int num; printf("Please pick a number between 1-5\n"); printf("Is the number greater than 3 (1/0): "); scanf("%d", &answ); if(answ == 1) { printf("Is the number greater than 4 (1/0): "); scanf("%d", &answ); if(answ == 1) num=5; elsenum=4; } else { printf("Is the number greater than 2 (1/0): "); scanf("%d", &answ); if(answ == 1) num=3; else { printf("Is the number greater than 1 (1/0): "); scanf("%d", &answ); if(answ == 1) num=2; else num=1; } printf("The number you picked is %d\n", num); return(0); }

Find smallest of 3 numbers a<ba<cacb<cbc a,cb,c

Find smallest of 3 numbers #include int main(void) { inta, b, c, min; printf("Please enter three numbers: "); scanf("%d%d%d", &a, &b, &c); if(a<b) { if(a<c) { min = a; } else { min = c; } } else { if(b < c) { min = b; } else { min = c; } printf("The smallest of the numbers entered is %d\n", min); return(0); }

Find smallest of 3 numbers - redone #include int main(void) { inta, b, c, min; printf("Please enter three numbers: "); scanf("%d%d%d", &a, &b, &c); if(a<b) { if(a < c) min = a; else min = c; } else { if(b < c) min = b; else min = c; } printf("The smallest of the numbers entered is %d\n", min); return(0); }

Find smallest of 3 numbers - simpler #include int main(void) { inta, b, c, min; printf("Please enter three numbers: "); scanf("%d%d%d", &a, &b, &c); if(a<b) if(a < c)min = a; elsemin = c; else if(b < c)min = b; elsemin = c; printf("The smallest of the numbers entered is %d\n", min); return(0); }

Find smallest of 3 numbers – even simpler #include int main(void) { int a, b, c, min; printf("Please enter three numbers: "); scanf("%d%d%d", &a, &b, &c); min = c; if(a<b && a<c) min = a; else if (b<a && b<c) min = b; printf("The smallest of the numbers entered is %d\n", min); return(0); }