You are on page 1of 7

Варіант 7

Завдання 1 Виконати завдання наведені нижче. Ввід-вивд даних та виконання


інших окремих логічних дій необхідно реалізувати в окремих функціях. У
головній функції необхідно виконувати лише їх виклик. Використання
глобальних змінних не допускається. Інформація повинна передаватися у
функції лише за допомогою параметрів. 7. Обчислити означений інтеграл
функції: 7x^3 – x^2 + 3x + 2, на інтервалі [2,3], використовуючи формулу
середніх прямокутників. Крок вводити з клавіатури.

Рисунок 1. Блок-схема для завдання 1.


Код програми:
#include <stdio.h>
#include <stdlib.h>

float vvedenna()
{ float s;
printf("Enter an interval\n");
scanf("%f",&s);
return s;
}
float integrall(float s)
{ float a=0, y, p;
for(float i=2+s;i<=3-s;i+=s){
y=7*(pow(i,3))-(pow(i,2))+3*i+2;
a=(fabs(y))*s;
p=p+a;}
return p;
}
float vvuvedenna(float p)
{
printf("integral = %f ", p);

}
int main()
{ float s, q;
s = vvedenna();
q = integrall(s);
vvuvedenna(q);
return 0;
}
Рисунок 2. Результат виконанян програми.
2 завдання
Завдання 2 Виконати аналіз текстового файлу (текст довільний). Ввід-вивд
даних та виконання інших окремих логічних дій необхідно реалізувати в
окремих функціях. У головній функції необхідно виконувати лише їх виклик.
Використання глобальних змінних не допускається. Інформація повинна
передаватися у функції лише за допомогою параметрів. Назва текстового файлу
та інші вхідні дані передаються в програму через аргументи функції main().
Вихідні дані виводяться на консоль. Визначити кількість рядків та абзаців.
Text2.txt- файл
Його вміст: Every day in the elementary school in America begins at 9.20 a.m.
Children have classes till 3.15 p.m. At 12 o’clock children have lunch. Many boys
and girls bring their lunch from home. But some of them go for lunch to a school
cafeteria.
Mrs. Bradley prepares school lunches almost every weekday for her two children.
Sometimes she gives the children money and they eat in the school cafeteria. But
usually the children prefer to take a lunch from home.
This morning Mrs. Bradley is making peanut butter and cheese sandwiches, the
childrens favorite. She puts two bottles of apple juice for the children to drink. She is
going to put the sandwiches, some cherry tomatoes and two bananas in their
lunchboxes. The lunchbox is easy for the children to carry to school.
Блок-схема
Рисунок 3. Блок-схема для завданян 2.
Код програми
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void scan(char str1[10][700]){


FILE *fp = fopen("text2.txt","r");
int l=0;
for (int i = 0; i < 10; i++) {
fgets(str1[i], 700 , fp);
printf("%s\n",str1[i]);
l++;
if(strlen(str1[i])== 0)
break;
}
l=l-1;
printf("lines: %d\n",l);
fclose(fp);
}
int abc (){
FILE *fp=fopen("text2.txt","r");
int pCount=0;
char c;
while ((c=fgetc(fp))!=EOF)
{
if(c=='\n')
pCount++;
continue;
}
return pCount;
}
void print(int a){
printf("paragraph: %d", a);
}
int main(){
char str1[10][600];
int l,a;
scan(str1);
a=abc(str1);
print(a);
}

Рисунок 4. Результат виконання програми.


Висновок: на цій лабораторній роботі я зноайомитися із особливостями
застосування функцій у мові С.

You might also like