Aptech accp2005 EPC Retake

Date: July 29 2008

Elementary Programming with C

Question 1: [2]
Khai báo các hàm sau:
– Tính tổng N số tự nhiên đầu tiên (1 – N).
– Tính chu vi đường tròn có bán kính R (int).
– Tính tổng N số nguyên tố đầu tiên (1, 3, 5, …, N).
– Hàm nhận vào 1 chuỗi và trả về kí tự cuối cùng của chuỗi đó.
ví dụ:

Hàm trả về tổng hai số tự nhiên:
int add(int a, int b);

Question 2: [8]
Viết chương trình thực hiện các chức năng sau:
– Hiển thị “N = ” và cho phép nhập vào một số nguyên dương.
– Cho phép nhập vào N chuỗi.
– In ra các chuỗi đã nhập.
– In ra tổng số chuỗi có chứa “31-Aug-05”.
– In ra các chuỗi thỏa mãn điều kiền trên.
Chương trình chia ra làm 3 phần.
– Phần 1: Cho phép nhập N và các chuỗi.
– Phần 2: In ra các chuỗi đã nhập.
– Phần 3: Tính và in ra các chuỗi thỏa mãn điều kiện.

Ví dụ:

N = 4
a[0] = Wed, 31-Aug-05
a[1] = Mon, 29-Aug-05
a[2] = 22-12-08
a[3] = 31-Aug-05, Wednesday

All string:
Wed, 31-Aug-05
Mon, 29-Aug-05
22-12-08
31-Aug-05, Wednesday

Total string contains “31-Aug-05”: 2

String(s)
Wed, 31-Aug-05
31-Aug-05, Wednesday

Question 3: [15]
Viết chương trình thực hiện các chức năng sau:
– Hiển thị menu:

1. Input N.
2. Input array elements
3. Calculate total of all positive odd number in the array.
4. Display all number.
5. Exit.

– Khi người dùng chọn 1: Cho phép nhập vào 1 số dương.
– Khi người dùng chọn 2: Tính M = 1 + 2 + 3 + … + N rồi cho người dùng nhập vào M số dương trong khoảng từ -100 đến 100).
– Khi người dùng chọn 3: In ra tổng của các số dương lẻ trong mảng đã nhập ở 2.
– Khi người dùng chọn 4: Hiển thị tất cả các số trong mảng đã nhập ở 2 theo định dạng:
+ Dòng 1 là phần từ đầu tiên, dòng 2 là 2 phần từ tiếp theo, dòng 3 là 3 phần tử tiếp theo dòng 2…
+ Các phần từ phải được đặt trong ô 3 kí tự và cách nhau 1 dấu cách.
Ví dụ:

N = 4
M = 1 + 2 + 3 + 4 = 10
a[0] = 1
a[1] = 12
a[2] = -22
a[3] = 18
a[4] = -33
a[5] = 26
a[6] = 40
a[7] = 5
a[8] = -11
a[9] = 3

Total of all positive odd number: 9
All number:
1
12 -22
18 -33  26
40   5 -11
3

– Khi người dùng chọn 5: Thoát chương trình.

aptech accp2003 Logic Building With C retake

Curriculum: ACCP2003
Semester: 1
Date: 10/22/2003
Duration: 90 minutes
Total Marks: 10

Logic Building With C

Write a menu-based program with the following menu:    [1.5]

1.    Input A & B.
2.    Display square of B.
3.    Calculate total of the number in the square.
4.    Calculate the factorial value of A.
5.    Exit.

Q1. Input A & B    [1.5]
When user chooses 1 from main menu, do the followings:
•    First, display “Enter the value of A: ” and accept integer A.
•    Second, display “Enter the value of B: ” and accept integer B.
•    Then, store A and B into variables in main function and return to the main menu.
This module must be coded in a function which do the followings:
–    Accept arguments by reference (using pointer).
–    Store values from user’s input into variables in main function.

Q2. Display square of B    [2.0]
When user chooses 2 from main menu, display square of B (the square which size A x A and contant numbers of B).
This module must be coded in a function which do the followings:
–    Accept arguments by value.
–    Display results.
For example:

With A = 3
B = 5
The function print:
5 5 5
5 5 5
5 5 5

With A = 5
B = 1
The function print:
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

Q3. Calculate total of the number in the square    [1.5]
When user chooses 3 from main menu, calculate total of all the number in the square of B (which generated from menu [2]).
This module must be coded in a function which do the followings:
–    Accept arguments by value.
–    Return the result to the main function.
For example:
With A = 3, B = 5
The function return: 45
With A = 5, B = 1
The function return: 25

Q4. Calculate the factorial value of A    [3.0]
When user chooses 4 from main menu, the program calculate the factorial value of A.
This module must be coded in a function which do the followings:
–    Accept an argument by value.
–    Return the result to the main function.
For example:
With A = 3
The function return: 6
With A = 5
The function return: 120

Q5. Exit.    [0.5]
When user chooses 5 from main menu, the program exits.


Example Source: Retake.C

EPC Assignment

Elementary Programming With C Assignment

Question 1: [15]
Write a menu-based program with the following menu: [1.5]

1.Input N,M.
2.Display rectangle number of M with N columns.
3.Calculate total of the prime numbers in this rectangle.
4.Calculate total of the numbers in the last col.
5.Exit.

Q1. Input N [3.0]
When user chooses 1 from main menu, do the followings:

  • First, display “Enter the value of N:” and accept integer N which must be a positive number.
  • Then, show warning message and reaccept N if user input a negative or zero number.
  • Next, display “Enter the value of M:” and accept integer M which must be greater than N.
  • Then, show warning message and reaccept M if it is less than N.
  • Finally, store N, M into variables in main function and return to the main menu.

This module must be coded in a function which does the followings:

  • Accept two arguments by reference (using pointer).
  • Store value from user’s input into variable in main function.

Q2. Display rectangle number of N [4.0]
When user chooses 2 from main menu, display rectangle number of M with N columns (the rectangle which the first position is 1, the second is 2, the third is 3… see the examples follows).
This module must be coded in a function which does the followings:

  • Accept two arguments by value.
  • Display results.

Example:

With N = 3, M = 10:
1 2 3
4 5 6
7 8 9
10

With N = 4, M = 10:
1 2 3 4
5 6 7 8
9 10

With N = 4, M = 15:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15

Q3. Calculate total of the prime number in the rectangle [3.0]
When user chooses 3 from main menu, calculate total of all the prime number in the rectangle and return the result to the main function.
This module must be coded in a function which does the followings:

  • Accept two arguments by value.
  • Return the result to the main function.

Notes: To easier, write a separate function to test a number which is prime number.
Example:

With N = 3, M = 10:
The result is:18
With N = 4, M = 10:
The result is:18
With N = 4, M = 15:
The result is:42

Q4. Count numbers in the last column [3.0]
When user chooses 4 from main menu, the program count numbers in the last column and return the result to the main function.
This module must be coded in a function which does the followings:

  • Accept two arguments by value.
  • Return the result to the main function.

Example:

With N = 3, M = 10:
The result is:18
With N = 4, M = 10:
The result is:12
With N = 4, M = 15:
The result is:24

Q5. Exit [0.5]
When user chooses 5 from main menu, the program will exits.

Question 2: [10]
Write a program to accept N strings, store them in separate elements of an array, and then display 3 parts which the first part contains all strings, the second row contains number of even string(string that have even length, example:s is even string if strlen(s)%2==0) and the third contains all even strings.
The program must be divided into modules which do the followings:

  • Accept N and all elements of the array from user’s input.
  • Display results in three parts.

Note: N < 100
Example:

N = 7
a[0] = Hello
a[1] = How
a[2] = are
a[3] = you
a[4] = I
a[5] = am
a[6] = fine
All Stríng:
Hello
How
are
you
I
am
fine
Number of even string: 2
Even string list:
am
fine


Example Source: epc_a

Đề thi thử thực hành C

Thời gian thi: 120 phút.
Tổng điểm: 25
Số câu: 3

Lưu ý: Câu 1 phải được ghi trong baithi1.c Câu 2 phải được ghi trong baithi2.c Câu 3 phải được ghi trong baithi3.c
Các bài làm đúng nhưng ghi sai tên tập tin sẽ bị bỏ qua và cho 0 điểm.

  1. (2/25)
    Viết khai báo của các hàm thực hiện các công việc sau:
    a) Tìm giá trị lớn nhất của mảng số thực gồm n phần tử.
    b) Tìm điểm lớn nhất (số thực) cho mảng sinh viên gồm n phần tử.
    c) Sắp xếp mảng số nguyên gồm n phần tử.
    d) Ghi mảng số thực xuống tập tin (cần chỉ ra tên tập tin để ghi).
    Ví dụ, khai báo của hàm kiểm tra ba số a, b, c có phải tam giác hay không int tamgiac(double a, double b, double c);
  2. (10/25)
    Viết chương trình thực hiện các công việc sau:
    a) Nhập số phần tử n của mảng trong khoảng 5 tới 10
    b) Nhập giá trị cho n chuỗi
    c) Tìm độ dài lớn nhất và in ra độ dài đó
    d) Sắp xếp mảng chuỗi và in ra
    Các công việc phải được viết thành hàm. (a) viết thành NhapSoPhanTu, (b) viết thành
    NhapMang, (c) viết thành TimGTLN, (d) viết thành SapXepMangInMang.
  3. (13/25)
    Viết chương trình cho phép lựa chọn các chức năng sau:
    Giả sử chúng ta thao tác trên mảng nguyên hai chiều int a[30][30] phần tử.

    1 – Nhập số hàng m và số cột n và các giá trị phần tử
    2 – In mảng đã nhập
    3 – In ra các phần tử chính phương (các phần tử khác biến thành dấu sao)
    4 – In ra các phần tử nguyên tố (các phần tử khác biến thành dấu sao)
    5 – In ra tổng theo hàng và theo cột của mảng (mỗi cột một tổng, mỗi hàng một tổng)
    6 – Thoát khỏi chương trình

    Mỗi chức năng phải viết thành một hàm, trừ chức năng thoát khỏi chương trình.