Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <windows.h>
- void main()
- {
- SetConsoleCP(1251); //русификация
- SetConsoleOutputCP(1251);
- int mas[100];
- printf("Введите количество элементов массива:\n");
- int n;
- scanf_s("%d", &n);
- printf("Введите элементы массива:\n");
- for (int i = 0; i < n; i++)
- {
- printf("mas[%d]=", i+1);
- scanf_s("%d", &mas[i]);
- }
- int IndexFirstNull=0, IndexLastNull=0, sum = 0;
- for (int i=0;i<n;i++)
- if (mas[i] == 0)
- {
- IndexFirstNull = i;
- break;
- }
- for (int i = n-1; i > IndexFirstNull; i--)
- {
- if (mas[i] == 0)
- {
- IndexLastNull = i;
- break;
- }
- }
- if (IndexLastNull==0)
- printf("Всего 1 нулевой элемент\n");
- else {
- for (int i = IndexFirstNull; i < IndexLastNull; i++)
- sum += mas[i];
- printf("Сумма элементов расположенных между первым и последним нулевым элементом равна: %d", sum);
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement