Solution April 13, 2011. #include int main( void ) { int salaries[ 11 ] = { 0 }; /*total salary */ int sales; /* sales per karyawan */ double salary;

Slides:



Advertisements
Similar presentations
Recursion Prog #include <stdio.h> #include<conio.h> main()
Advertisements

BNF <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana.
DS:Lab-1 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
What is shape function ? shape function is a function that will give the displacements inside an element if its displacement at all the node locations.
void count_down (int count) { for(i=count; i>1; i--) printf(" %d\t", count); } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n",
Example T1: T2: Constraint: Susan’s salary = Jane’s salary
We Have Learned main() { … } Variable –Definition –Calculation –Display We can do some real programming! –Think about your solution design –Express design.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
Sort the given string, without using string handling functions.
 2007 Pearson Education, Inc. All rights reserved. Structs as Function Arguments and Results  Arrays – Pass by referance  Struts – the same way as the.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
1 CSC103: Introduction to Computer and Programming Lecture No 8.
ENGR 3 rocks. Your friendly TA Damon Good list of VI commands Good online free guide to Linux (time-sucker)
Chapter 10: Recursion CS 201 Program Design with C Department of CS, Montana State University Mahmud Shahriar Hossain.
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
Arrays Ethan Cerami New York University Today n Array Basics (Review) n Random Number Example n Passing Arrays to Functions n Strings.
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);
Selection in C.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
CMSC 104, Version 9/011 Incremental Programming Topics Review of Incremental Programming Example of Incremental Programming Reading None.
Agenda  Perform Quiz#2 (20 Minutes)  Functions / Continued … –Functions - Definition –Types of Functions: Functions that do not accept or return a value.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
+ ARRAYS - SEARCHING - SORTING Dr. Soha S. Zaghloul updated by Rasha M. AL_Eidan 2015.
 2000 Prentice Hall, Inc. All rights reserved Arrays Array –Group of consecutive memory locations –Same name and type To refer to an element, specify.
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
Nested LOOPS.
1 C Programming Week 2 Variables, flow control and the Debugger.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Chapter 5 – Functions II Outline Recursion Examples Using Recursion: The Fibonacci Series.
ECE 103 Engineering Programming Chapter 18 Iteration Herbert G. Mayer, PSU CS Status 7/19/2015 Initial content copied verbatim from ECE 103 material developed.
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
Sudeshna Sarkar, IIT Kharagpur 1 Functions Lecture
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
Selection-making Decisions Selection allows you to choose between two or more possible program flow --- it lets you make decisions in your program. Examples.
How to design and code functions Chapter 4 (ctd).
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.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
CMSC 1041 More Loops ‘for’ loops and ‘do-while’ loops.
CS 161 Introduction to Programming and Problem Solving Chapter 17 Nested Loops Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Recursive. Recursive F(n) = F(n-1) + F(n-2) n! = (n-1)! x n C(m,n) = C(m-1,n-1)+C(m-1,n)......
REEM ALAMER REVISION FOR C LANGUAGE COURSE. OUTPUTS int main (void) { int C1, C2; int *p1, *p2; C1 = 8; p1 = &C1; C2 = *p1 / 2 + 5; p2 = &C2; printf ("C1.
Algorithm: procedure in terms of
- Standard C Statements
Lecture 7: Repeating a Known Number of Times
Week 4 – Repetition Structures / Loops
REPETITION STATEMENTS
Looping.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
توابع. توابع دليل استفاده از تابع اجتناب از نوشتن تكراري خطوط يكسان در يك برنامه ساختار برنامه بهتر و قابل فهم ميشود استقلال زير روالها از تابع main.
Lec 7.
A function with one argument
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Week 6 CPS125.
Relational, Logical, and Equality Operators
REPETITION STATEMENTS
Let’s all Repeat Together
Arrays, Part 1 of 2 Topics Definition of a Data Structure
ECE 103 Engineering Programming Chapter 19 Nested Loops
Let’s all Repeat Together
ECE 103 Engineering Programming Chapter 18 Iteration
More Loops Topics Counter-Controlled (Definite) Repetition
Character Arrays char string1[] = “first”;
More Loops Topics Counter-Controlled (Definite) Repetition
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
More Loops Topics Counter-Controlled (Definite) Repetition
Range check 範圍檢查: int age; int score; int month; 1-12
Presentation transcript:

Solution April 13, 2011

#include int main( void ) { int salaries[ 11 ] = { 0 }; /*total salary */ int sales; /* sales per karyawan */ double salary; /* pemasukan */ double i = 0.09; /* persen komisi*/ /* interaksi dgn user utk memasukan besar sales*/ printf( "Enter employee gross sales ( -1 to end ): " ); scanf( "%d", &sales );

/* sentinel value*/ while ( sales != -1 ) { /* hitung salary berdasarkan sales*/ salary = sales * i; printf( "Employee Salary is $%.2f\n", salary ); /* update salary range yang sesuai*/ if ( salary >= 200 && salary < 1000 ) { ++salaries[ ( int ) salary / 100 ]; } /* end if */ else if ( salary >= 1000 ) { ++salaries[ 10 ]; } /* end else if */

/*interaksi user*/ printf( "\nEnter employee gross sales ( -1 to end ): " ); scanf( "%d", &sales ); } /* end while */ /* display hasil*/ printf( "\nEmployees in the range:\n" ); printf( "$200-$299 : %d\n", salaries[ 2 ] ); printf( "$300-$399 : %d\n", salaries[ 3 ] ); printf( "$400-$499 : %d\n", salaries[ 4 ] ); printf( "$500-$599 : %d\n", salaries[ 5 ] ); printf( "$600-$699 : %d\n", salaries[ 6 ] ); printf( "$700-$799 : %d\n", salaries[ 7 ] ); printf( "$800-$899 : %d\n", salaries[ 8 ] ); printf( "$900-$999 : %d\n", salaries[ 9 ] ); printf( "Over $1000: %d\n", salaries[ 10 ] ); return 0; /* indicate successful termination */ } /* end main */