0% found this document useful (0 votes)
12 views1 page

TD 01: Functions and Procedures: Exercise 1 Exercise 5

Uploaded by

korichigpt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

TD 01: Functions and Procedures: Exercise 1 Exercise 5

Uploaded by

korichigpt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Kasdi Merbah Ouargla University

Faculty of New technologies and information and communication


Computer Science and Information Technology Department

Module: ADS2 Algorithms and Data Structure 2


Teachers: BELHADJ Mourad, MEISSA Marwa & KORICHI Aicha
Academic year: 2024/2025
Class: ING1 Computer engineering
Type: Tutorial

TD 01: Functions and Procedures


Exercise 1 Exercise 5
Write the following functions or procedures:
1. Calculates the square of a number. 1. Write a function that checks whether an array is
2. Find the maximum of two integers. in descending order instead of ascending order.
3. Checks whether a number is even or odd. 2. Modify the function to return 1 if sorted in as-
4. Checks if a positive integer is prime. cending order, -1 if sorted in descending order,
and 0 if not sorted.
Exercise 2
3. Write a function that takes an array and a num-
1. Write a function that takes a temperature in ber as input and returns the rst and last index
Celsius as input and converts it to Fahrenheit. where that number appears.
2. Write a function that calculates the area of a
circle given its radius. Exercise 6
Exercise 3 We want to implement a basic cryptography system
to encode and decode text. The encryption method
1. Write a procedure to print "Hello, World!". is simple: shifting characters forward in the alphabet
  
(e.g., `A' `B', `B' `C', ..., `Z' `A' for uppercase
2. Write a void function that takes two integers letters, and similarly for lowercase letters).
and prints their sum.
1. Write a function that takes a string and
Exercise 4 shifts each letter forward by one place (e.g.,
"HELLO" becomes "IFMMP"). The transfor-
1. Write an algorithm in function or procedure mation should be applied directly to the vari-
form that returns the number of vowels con- able storing the sentence.
tained in a character string. Note that one sub-
routine has every right to call another. 2. Modify the function to take a shift value as an
2. Write a function that purges a one-character argument. The user should enter a sentence
string, both the string and the character being and a shift value (e.g., shift by 3: "HELLO" 
passed as an argument. If the specied charac- "KHOOR").
ter is not part of the string, the string must be
returned intact. For example: 3. Write a function that replaces: Vowels with '*'
Purge("Hello","e") will return "Hllo" Consonants with ' #' The function should mod-
ify the string in-place.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy