0% found this document useful (0 votes)
4 views

Lab_7_Solution

Uploaded by

Omar Shady
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab_7_Solution

Uploaded by

Omar Shady
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Alexandria University Computer and Communication

Faculty of Engineering CSE016 Computers &


Specialized Scientific Programs Programming

Lab 7

Objective:
 Application on loops
 Application on nested loops
 Working with arrays
 Reading string from user

1. (Fibonacci series) Write a program that reads n, then generates the first n terms of the
Fibonacci series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,
(Note: F1 = 0, F2 = 1, for every i > 2, Fi = Fi−2 + Fi−1).

Using arrays:
Alexandria University Computer and Communication
Faculty of Engineering CSE016 Computers &
Specialized Scientific Programs Programming

Using loops only:


Alexandria University Computer and Communication
Faculty of Engineering CSE016 Computers &
Specialized Scientific Programs Programming

2. (Duplicate Elimination) Use a single-subscripted array to solve the following problem.


Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is
read, print it only if it’s not a duplicate of a number already read. Provide for the “worst
case” in which all 20 numbers are different. Use the smallest possible array to solve this
problem.
Alexandria University Computer and Communication
Faculty of Engineering CSE016 Computers &
Specialized Scientific Programs Programming

3. (Palindrome Checking) Read in a string into a character array of a length of at most


128, you can read in the string with scanf(‘‘%s’’), but then you cannot have spaces
inside the string since scanf stops reading as soon as it detects a white space. A better
solution is to use the function gets(str) which reads the entire line including everything.
It is defined in stdio.h.
Then you should print a message stating either that the input constitutes a palindrome or
that it is not a palindrome. A palindrome is a string that reads the same from right to left
as well as from left to right, ignoring spaces.

OR
Alexandria University Computer and Communication
Faculty of Engineering CSE016 Computers &
Specialized Scientific Programs Programming

4. (Bubble sort) Write a program that reads n integers (n <= 20) then use bubble sort to
sort the elements in ascending order.

Example:
5
Enter the elements: -1 7 5 30 -10
In ascending order: -10 -1 5 7 30

You might also like