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 ).

Similar documents
Loops / Repetition Statements

Subject: Computer Science

VARIABLE, OPERATOR AND EXPRESSION [SET 1]

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

Section A Arithmetic ( 5) Exercise A

Mental Maths Competition Topics Included. (1) Q. No. 1 to 50 are based on basic. Calculation questions related to Addition,

Module 7 Highlights. Mastered Reviewed. Sections ,

Lab 2: Structured Program Development in C

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

Other Loop Options EXAMPLE

6th Grade Arithmetic (with QuickTables)

Loops / Repetition Statements

Suggestive List of C++ Programs

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

UNIT 1: INTEGERS Definition Absolute Value of an integer How to compare integers

COP 4516: Math for Programming Contest Notes

Huawei Test 2. 1 Two dice are thrown simultaneously. What is the probability of getting two numbers whose product is even?

LAB 7 FUNCTION PART 2

PROGRAMMING IN C AND C++:

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1

MATHEMATICS FOR ELEMENTARY TEACHERS I FINAL EXAM REVIEW

Algebra Summer Math HW check

6-8 Math Adding and Subtracting Polynomials Lesson Objective: Subobjective 1: Subobjective 2:

B. V. Patel Institute of Business Management, Computer & Information Technology, UTU 2013

Is the statement sufficient? If both x and y are odd, is xy odd? 1) xy 2 < 0. Odds & Evens. Positives & Negatives. Answer: Yes, xy is odd

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

C PROGRAMMING LAB MANUAL

College Readiness (597 topics) Course Name: College Prep Math Spring 2014 Course Code: ARTD4-3N6XJ

Lab ACN : C++ Programming Exercises

RtI 7. Curriculum (219 topics additional topics)

Final Examination Semester 2 / Year 2010

Number Theory Open, Round 1 Test #101

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

Object Oriented Programming Using C ++ Page No. : 1. ASSIGNMENT SHEET WITHOUT USING OBJECT AND CLASSES

Integer Operations. Summer Packet 7 th into 8 th grade 1. Name = = = = = 6.

Chapter 3 Problem Solving and the Computer

Section 3.1 Factors and Multiples of Whole Numbers:

3 The L oop Control Structure

YEAR 8 SCHEME OF WORK

Computer Programming. Decision Making (2) Loops

Alignments to SuccessMaker. Providing rigorous intervention for K-8 learners with unparalleled precision

CW Middle School. Math RtI 7 A. 4 Pro cient I can add and subtract positive fractions with unlike denominators and simplify the result.

FUNDAMENTAL ARITHMETIC

School of Science and Technology

Control Structure: Loop

Algorithms 4. Odd or even Algorithm 5. Greatest among three numbers Algorithm 6. Simple Calculator Algorithm

Number Sense and Operations Curriculum Framework Learning Standard

Lesson 2: Generating Equivalent Expressions

Algebra 1. Standard 11 Operations of Expressions. Categories Combining Expressions Multiply Expressions Multiple Operations Function Knowledge

Essar Placement Paper

Single Dimension Arrays

1 5 Integer Operations

Question Bank (SPA SEM II)

Iron County Schools. Yes! Less than 90 No! 90 No! More than 90. angle: an angle is made where two straight lines cross or meet each other at a point.

METHODS EXERCISES GuessNumber and Sample run SumAll Sample Run

Functions. Arash Rafiey. September 26, 2017

Dept. of CSE, IIT KGP

What is a Fraction? Fractions. One Way To Remember Numerator = North / 16. Example. What Fraction is Shaded? 9/16/16. Fraction = Part of a Whole

Basic Operations and Equivalent Expressions - Step-by-Step Lesson

Math Lesson Plan 6th Grade Curriculum Total Activities: 302

Objective 1 : The student will demonstrate an understanding of numbers, operations, and quantitative reasoning.

A. Incorrect! To simplify this expression you need to find the product of 7 and 4, not the sum.

Year 6 Term 1 and

Slide 1 / 180. Radicals and Rational Exponents

Name: Teacher: Form: LEARNER JOURNAL. Set: Mathematics. Module 2 END OF YEAR TARGET: GCSE TARGET:

6th Grade Math. Lindsay Law - Curriculum Facilitator (ext. 2085)

Mathematics LV 5 (with QuickTables)

Math Analysis Chapter 1 Notes: Functions and Graphs

3.1 Using Exponents to Describe Numbers

Question Bank. 4. Write a menu driven program to accept two numbers and find a. HCF / GCD b. LCM

Downloaded from

Structured programming. Exercises 3

Math 6 Unit 2: Understanding Number Review Notes

in normal arithmetic = == = == 5 7 x 2 = 24 7 * 2 == = 3 remainder 1 7 / 2 7 % 2

CS1100 Introduction to Programming

Math 10- Chapter 2 Review

MARLBORO CENTRAL SCHOOL DISTRICT CURRICULUM MAP Subject: Mathematics Grade: 6. Quarter 1 Content (What Students Should Know) Vocabulary Integer

4*4*4 2. What is the output of the following flowchart for the values given below: (25 p)

Alignments to SuccessMaker. Providing rigorous intervention for K-8 learners with unparalleled precision

Instructional. Essential Standards. Materials. Envision Topic 1 1-1; 1-2; 1-3; 1-4. Envision Topic 2 2-2; 2-3. Envision Topic 2 2-4; 2-5; 2-6

Chapter 4: Basic C Operators

YEAR 7 SCHEME OF WORK - EXTENSION

CHAPTER 1: INTEGERS. Image from CHAPTER 1 CONTENTS

SECTION A TRUE / FALSE QUESTIONS (10 MARKS) (INSTRUCTION: Please answer all 10 questions)

CSE 115 Programming Language I Final Examination Fall 2015


Foundation. Scheme of Work. Year 9. September 2016 to July 2017

Manipulate expressions containing surds and rationalise denominators (A*) Able to simplify surds (A)

NMC Sample Problems: Grade 8

Grade 7 Math Curriculum Map Erin Murphy

Programming & Data Structure Laboratory. Day 2, July 24, 2014

NFC ACADEMY MATH 600 COURSE OVERVIEW

Loki s Practice Sets for PUBP555: Math Camp Spring 2014

6 th Grade Math Reference Sheet

Mathematics. Grade 8 Curriculum Guide. Curriculum Guide Revised 2016

YEAR 6 MATHS LONG TERM PLAN ACADEMIC YEAR AUTUMN TERM

COMP 111 PROGRAMMING I MODULARITY USING FUNCTIONS

7 th GRADE PLANNER Mathematics. Lesson Plan # QTR. 3 QTR. 1 QTR. 2 QTR 4. Objective

DEPARTMENT OF ACADEMIC UPGRADING

CLASSIFICATION OF FRACTIONS 1. Proper Fraction : A Proper fraction is one whose numerator is less than its denominator. 1 eg., 3

Transcription:

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 ). 2-Give the result of the following program: #include<stdio.h> main() { int p, n; n = 0; while (n <= 5) n++; printf( A: n = %d \n, n); n = p = 0; while (n <= 8) n += p++; printf( B: n = %d \n, n); n = p = 0; while (n <= 8) n += ++ p; printf( C: n = %d \n, n); } 3- Write an algorithm that prints on the screen all the integers from 8 to 23. 4- Write an algorithm that reads 10 integers and then prints on the screen their summation. 5-Write an algorithm that reads two integers x and y and then prints on the screen their product. The algorithm should only use the + operator (the product operator * can t be used). 6- Write an algorithm that reads two integers x and y and prints all the odd numbers ranging between x and y. 7- A college has a list of test results (each test result is a number either 1 or 2: 1 = pass, 2 = fail) for 10 students. Write an algorithm that analyzes the results: if more than 8 students pass, prints "Raise Tuition". 8- Give the result of the following program if n = 10. #include<stdio.h> main() { int i, n, s ; printf("give an integer\n"); scanf("%d", &n); for(i = 1, x = 0, s = 0 ; x < n ; ++i) { x = 2 * i ; s += x; 1

} printf("the value of s is : %d \n",s); } 9- Write a program that prompts user to enter an integer n and determines and prints the sum of 1 + (2 3) 2 + (3 4) 3 + (4 5) 4 + + ((n 1) n) n 1 10-Write a program that reads two integers x and y and prints all the even numbers ranging between x and y. 11- Write a program that reads an integer N and prints N! 12- Write a program that prompts the user to enter the number of students, each student s score, and finally displays the highest score. 13- Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14 (i.e. 9 + 3 + 2 = 14). 14- Write a program that receives an ASCII code (an integer between 0 and 128) and displays its character. For example, if the user enters 97, the program displays character a. 15- Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. 16- Write a program that receives an ASCII code (an integer between 0 and 128) and displays its character. 17- Write a program that prompts user to enter an integer number, and displays on the screen the ten following numbers. For example, if the user enters the number 17, then the program should display the numbers from 18 to 27. 18- Write an algorithm that prints on the screen all the integers from 8 to 23. 19- Write an algorithm that prints all then even numbers ranging between 5 and 40. 20- Write an algorithm that reads an integer n and prints n! 21- Write an algorithm that prompts user to enter an integer n and determines and prints the sum of 1 + 1 2 + 1 3 + 1 4 + + 1 n 1 + 1 n 22- Rewrite the following program by using instead of the for loop a do while loop. #include<stdio.h> main() { int i,n, s = 0; for (i= 0; i < 4; i++) { 2

printf( give an integer : ); scanf( %d,&n); s += n ; } printf( sum is = %d, s); } 23- Write a program that prompts user to give an integer x and prints the following menu: 1. Add 1 2. Multiply by 2 3. Subtract 4 4. Exit The program prompts user to give a number c. If c is between 1 and 3, the program prints the result of the operation on x. The program prints again the menu and asks the user what he wants to do (which operation), until the user choose to exit from program. 24- Write a program that reads a positive integer x and prints on the screen the number of digits in x. 25- Write an algorithm that prompts user to give some positive numbers and prints the square of each of these numbers. The program stops reading numbers when user gives 0 (a number equal 0). 26- Write an algorithm that reads a set of integers ended by 1 and prints on the screen the maximum value, the minimum value, the number of times the maximum appears in the set and the number of times the minimum appears in the set. Example: Enter an integer (-1 to terminate): 12 Enter an integer (-1 to terminate): 8 Enter an integer (-1 to terminate): 13 Enter an integer (-1 to terminate): 7 Enter an integer (-1 to terminate): 12 Enter an integer (-1 to terminate): 7 Enter an integer (-1 to terminate): 9 Enter an integer (-1 to terminate): -1 27- Write a program that reads an integer x and prints on the screen all the divisors of x. 28- Write a program that reads two integers x and y and find their GCD (Greatest common divisor). 29- Write a program that reads a set of integers ended by 1 and prints on the screen the maximum value, the minimum value, the number of times the maximum appears in the set and the number of times the minimum appears in the set. Example: 3

Enter an integer (-1 to terminate) : 12 Enter an integer (-1 to terminae) : 8 Enter an integer (-1 to terminate) : 13 Enter an integer (-1 to terminate) : 7 Enter an integer (-1 to terminate) : 11 Enter an integer (-1 to terminate) : 12 Enter an integer (-1 to terminate) : 7 Enter an integer (-1 to terminate) : 9 Enter an integer (-1 to terminate) : -1 Maximum value is: 13, this maximum appears 1 times in the set Minimum value is: 7, this minimum appears 2 times in the set 30- Write a program that reads two integers x and y and then prints on the screen a rectangle of x*y stars. If we consider x=3 and y=6, the program must display: * * * * * * * * * * * * * * * * * * 31- Write a program that reads an integer x and then prints on the screen a triangle of x lines of stars. If we consider x=7, the program must display: * * * * * * * * * * * * * * * ***** * * * * **** * * * * * * *** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 32- The Syracuse sequence is a sequence of positive integers that begins by a positive integer n and ends by 1. Each Syracuse number is calculated in function of its previous number, according to the following rules: Ui=Ui-1/2 if Ui-1 is even Ui=Ui-1*3+1 if Ui-1 is odd 33- Write a program that reads an integer n and then prints on the screen the Syracuse sequence that begins by n. For example, if the user enters 22; the program prints on the screen: 22-11-34-17-52-26-13-40-20-10-5-16-8-4-2-1 4

34- Write a program that reads a set of characters until the user enters the EOF character and then prints on the screen the number of enters, the number of spaces, the number of lower-case letters and the number of upper-case letters entered by the user. 35- Write a program that reads an integer n and determines if n is prime. 36- Write a program that reads an integer n and prints on the screen all the prime divisors of n. 37- Write a program which calculates expression N^N where N is an integer value filled by the user. 38- Write a program which reads a sequence of real values filled by the user and stops by displaying "FINISHED" when the sum of these values exceeds 100. 39- Write a program which reads a sequence of positive integer values and shows their multiplication and their sum when the user fills a negative number. 40- Write a program which reads a positive integer value and shows its divisors. 41- Write a program which reads a positive integer value N and indicates if N is a perfect number or not (N is a perfect number if N = the sum of its divisors without the number itself). 42- Write a program which reads a positive integer value N, calculates and shows the result of the expression: 1 + 4 + 7 + 10 +... + N 43- Write a program which reads a positive integer value N, calculates and shows the sum of the even numbers < = N. 44- Write a program which reads a positive integer value N, calculates and shows the sum of the odd numbers < = N. 45- Write a program which reads a positive integer value n, calculates and shows the result of the expression: 46- Write a program which reads a positive integer number n, calculates and shows the following: 1 + 1/2 + 1/3 + 1/4 +... + 1/n if n is divisible by 7 N + n/2 + n/3 + n/4 +... + n/(n-1) + 1 else 5

47- Write a program which indicates if a positive number N, filled by the user, is prime or not (N is a prime number if its only divisors are 1 and N). 48- Write a program which reads 10 real numbers. The program must then show the maximum and the minimum of these numbers. 49- Write a program which reads a sequence of positive real numbers. The program stops when the user fills a negative value and show the maximum of these numbers. 50- Write a program which reads 20 real numbers and shows their sum and their multiplication. 51- Write a program which reads two positive integer values and shows their GCD (Greatest Common Divisor) and their LCM (Least Common Multiple). 52- Write a program that reads a positive integer N and displays: 1 22 333 4444 NNNN.N 53- o Write a program that takes an integer n and displays the value of Un respecting: U0=1 ; Un = n 1 ( Ui ) i=0 (i 1)! 6 for n>=1 ; o Write a program that asks the user to enter an integer a and then prints the series elements from U0 to Ua. 54- An integer number is divisible by 9 if the sum of its digits is divisible by 9. Write a program that reads a positive integer, finds the number of digits of this integer and using the criteria above, discovers if it is divisible by 9 and then prints out the results. Example: if the user enters 57883 The program display : 57883 has 5 digits. The sum of digits is : 31

It is not divisible by 9 Write a program that uses the criteria above to display all the positive integers between 100 and 1000 that are divisible by 9. 55- Write a C program that asks the user to enter a positive integer N, and a real value R representing the radius of a circle C of center O(0,0). The program should then prompt the user to enter a sequence of points coordinates (x and y) until the number of points inside C is equal to N. Then the program should display the coordinates of the farthest point from the center O(0,0) (among the entered points). Note that: The distance between a point M(x,y) and the point O(0,0) is calculated using the formula sqrt(t) of the library math.h gives the value of y R O(0,0) x 56- We would like to write a program for a supermarket that offers a discount for his clients. The discount is valid only if at least 4 products are bought, and the total price of the bought products is at least 200000 L.L. This discount consists on a reduction of 10% on the most expensive product and 50% on the cheapest product among the list of bought products. Write a C program that prompts the user to enter a sequence of products price until a negative value or zero is entered. The program should calculate and display the number of bought products, their total price, and -if the discount is valid - the amount of reductions on the most expensive product and the cheapest product, and the total sum to be paid after reductions. Example of execution: Enter a product price: 12000 Enter a product price: 60000 Enter a product price: 10000 Enter a product price: 75000 Enter a product price: 10000 Enter a product price: 12000 Enter a product price: 0 You have bought 6 products. The total price is 179000 L.L. Reduction 10% : 0 L.L. Reduction 50% : 0 L.L. Total to be paid (after reduction): 179000 L.L. Another example of execution Enter a product price: 120000 Enter a product price: 60000 7

Enter a product price: 10000 Enter a product price: 10000 Enter a product price: 350000 Enter a product price: -12 You have bought 5 products. The total price is 550000 L.L. Reduction 10% : 35000 L.L. Reduction 50% : 5000 L.L. Total to be paid (after reduction): 510000 L.L. 57- Write a program that reads an integer N, asks the user to enter N characters, calculate the length of the longest ascending sequence of characters and the position of its first character. Example of execution: Enter a positive integer: 11 Enter 11 characters: A e c D k l n p a c D The longest sequence is of 5 characters, it begins at the position 4 58- Write an independent program for each of the following three parts: 1- Write a program that checks if a number is prime or not. 2- A number is said to be "special", if all its divisors are prime numbers (excluding 1 and the number itself) Example: 14, 21, 22.. are special numbers. Considering exercise (1), Write a program that reads a positive number and checks if it is special or not. 3- Considering exercise (2), write a program that prints the first 100 "special" numbers. 59- A company pays its employees according to the principle of a basic hourly rate for which we apply a coefficient K as follows: For the first 39 working hours per week, K = 1. From the 40 th to the 44 th hour per week, K = 1.5. After the 44 th hour, K = 2. Write a C program that asks the user to enter the basic hourly rate and the number of working hours for an employee, then calculates and displays his weekly wage. Execution example: Give the basic hourly rate: 6 Give the number of hours worked per week: 47 The salary corresponding to 47 hours is $ 315 Explication: (39*1*6) + (5*1.5*6) + (3*2*6) = 315 60- Write a program that asks the user to enter an integer making sure it is a positive number (a negative integer should not be accepted), and checks if this number is ABUNDANT. A number n 8

is said to be abundant when the sum of its divisors (including the number itself) is greater than its double (2n). Example: 12 is abundant (1 + 2 + 3 + 4 + 6 + 12 > 24) 61- The country A has 50 Million inhabitants, and its population grows 3% per year. The country B has 70 Million and its population grows 2% per year. Write a program that tells in how many years A will surpass B. Output: After 35 years the population of A will be 140693122.718576, and the population of B will be 139992268.686372 9