Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #pragma warning(disable:4996)
- double grades[] = { 5.50,3.57,4.20,5.80,6.00,4.50,2.00,5.00,6.00,3.80 };
- double* arrayCapasityAndIni(int len) {
- double* arr2 = (double*)malloc(len * sizeof(double));
- int i;
- for (i = 0; i < len; i++) {
- arr2[i] = grades[i];
- }
- return arr2;
- }
- int gradesNumbers() {
- int n;
- do {
- printf("Numbers: ");
- scanf("%d", &n);
- if (n > 10 || n < 0) {
- printf("Enter number between 0 and 10");
- }
- if (n == 0) {
- return 0;
- }
- } while (n < 0 || n>10);
- return n;
- }
- double* newCapasity(double arr[], int len, int newLen) {
- double* arr2 = (double*)realloc(arr, (newLen) * sizeof(double));
- if (arr2 == NULL) {
- printf("Error recapasity");
- exit(1);
- }
- int i;
- for (int i = 0; i < len; i++)
- {
- arr2[i] = arr[i];
- }
- for (i = len; i < (newLen); i++) {
- arr[i] = 2.00;
- }
- return arr2;
- }
- int main()
- {
- int newGrades;
- int grades = gradesNumbers();
- int i;
- double* arr = arrayCapasityAndIni(grades);
- for (i = 0; i < grades; i++) {
- printf("arr[%d]: %.2f\n", i + 1, arr[i]);
- }
- printf("New grades: ");
- scanf("%d", &newGrades);
- double* newArr = newCapasity(arr, grades, newGrades);
- for (i = 0; i < newGrades; i++) {
- printf("arr[%d]: %.2f\n", i + 1, newArr[i]);
- }
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement