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

C Lab04

The document provides instructions for a C/C++ programming lab assignment involving functions. It includes tasks to write functions to calculate sums, pi, check for perfect numbers, input/output arrays, find max/min array indices, check array symmetry, move positive elements to front of array, and sort arrays with alternating order.

Uploaded by

Nguyễn Duy
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)
21 views1 page

C Lab04

The document provides instructions for a C/C++ programming lab assignment involving functions. It includes tasks to write functions to calculate sums, pi, check for perfect numbers, input/output arrays, find max/min array indices, check array symmetry, move positive elements to front of array, and sort arrays with alternating order.

Uploaded by

Nguyễn Duy
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

C/C++ Programming

Lab 04
Create one single .c file and use functions for all questions

1. Write a function to calculate 1*2 + 2*3 + 3*4 +...+ n(n+1)=

2. The pi number (π) can be calculated by this formula:

𝜋2 1 1 1
= 1 + 2 + 2 + ⋯+ 2
6 2 3 𝑛

Write a c function to calculate the value of pi with input parameter n, then use this c
function in main() function to print out the value of pi as follows:

N Pi
10.000 ……
11.000 ……

20.000 ……

3. A perfect number is a positive integer number having the sum of all divisors equal to its
value. e.g., 6 is a perfect number since 6=1+2+3, and {1,2,3} are 6’s divisors. Write a
function to check whether an input integer number is a perfect number, then, in the main()
function, you have to use this function to find all perfect numbers less than 1000.

4. Write 2 functions to input and output an array of n integers. Reuse these functions for the
questions related to array

5. Write functions to find the index of the maximum and minimum elements of a given array
of n integers.
Example: 5 2 3 9 1 --> index of min element is 4 and index of max is 3

6. Input an array of n integers. Write a function to check whether the array is symmetric or
not; the function returns 1 if the array is symmetric and 0 otherwise (optional: use
recursive)
Example: 1 2 3 2 1 🡪 symmetric

7. Write a function to move all positive elements of an array upfront


Example: 2 -3 4 6 -7 9 8 -2 🡪 2 4 6 9 8 -3 -7 -2

8. Input an array of n integers. Sort the numbers with even indexes in increasing order and
ones with odd indexes in decreasing order
Example: array = 3 5 2 4 8 6 7 9 2 🡪 result = 2 9 2 6 3 5 7 4 8

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