Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Лабы по программированию...docx
Скачиваний:
7
Добавлен:
26.09.2019
Размер:
71.35 Кб
Скачать

Лабораторная работа №2

  1. Привет, мир

#include "stdafx.h"

#include <stdio.h>

int main ()

{

printf("Hello, Wordl!\n");

return 0;

}

2. Перевод радиан в градусы

#include "stdafx.h"

#include <stdio.h>

#include <math.h>

#include <locale.h>

int _tmain(int argc, _TCHAR* argv[])

{

float ugol_radian;

setlocale(LC_ALL, "Russian");

printf("введите значение угла в радианах:\n");

scanf("%f", &ugol_radian);

float ugol_grad = ugol_radian*180/3.14;

printf("Угол в градусах равен: %f\n", ugol_grad);

return 0;

}

6. Площадь и периметр трапеции

#include "stdafx.h"

#include <stdio.h>

#include <math.h>

#include <locale.h>

Int _tmain(int argc, _tchar* argv[])

{

float a;

setlocale(LC_ALL, "Russian");

printf("введите значение длины первого основания:\n");

scanf("%f", &a);

float b;

printf("введите значение длины второго основания:\n");

scanf("%f", &b);

float h;

printf("введите значение длины высоты:\n");

scanf("%f", &h);

float S=(a+b)*h/2;

printf("Площадь трапеции равна %g\n",S);

float P=(b-a)*h/2+a*h;

printf ("Периметр трапеции равен %g\n",P);

return 0;

}

14. Типы данных с

#include "stdafx.h"

#include <stdio.h>

#include <math.h>

#include <locale.h>

Int _tmain(int argc, _tchar* argv[])

{

setlocale(LC_ALL, "Russian");

char frmt[] = "%-15s%5d\n";

printf("%-15s%5s\n", "Тип", "Размер");

printf("----------------------\n");

printf(frmt,"char", sizeof(char));

printf(frmt,"unsigned char",

sizeof(unsigned char));

printf(frmt, "short", sizeof(short));

printf(frmt,"unsigned short",

sizeof(unsigned short));

printf(frmt, "int", sizeof(int));

printf(frmt,"unsigned int",

sizeof(unsigned int));

printf(frmt, "float", sizeof(float));

printf(frmt, "double", sizeof(double));

printf(frmt, "bool", sizeof(bool));

printf("----------------------\n");

return 0;

}

18.Диаметр, длина и площадь окружности

#include "stdafx.h"

#include <stdio.h>

#include <math.h>

#include <locale.h>

Int _tmain(int argc, _tchar* argv[])

{

#define PI 3.14

float r;

setlocale(LC_ALL, "Russian");

printf("введите радиус окружности:\n");

scanf("%f", &r);

char frmt[] = "%-25s%5d\n";

printf("%-25s%5s\n", "Что вычисляется", "Значение");

printf("---------------------------------\n");

float D=2*r;

float C=2*PI*r;

float S=r*r*PI;

printf("Диаметр окружности %10g\n", D);

printf("Длина окружности %10g\n", C);

printf("Площадь окружности %10g\n", S);

printf("---------------------------------\n");

return 0;

}

23. Приветствие

#include "stdafx.h"

#include <stdio.h>

#include <windows.h>

Int _tmain(int argc, _tchar* argv[])

{

char name[30];

SetConsoleCP(1251);

SetConsoleOutputCP(1251);

printf("Введите имя:\n");

scanf("%s", &name);

printf("Привет, %s\n", name);

return 0;

}

Лабораторная работа №3

2. Значения битов

#include "stdafx.h"

#include <stdio.h>

#include <math.h>

#include <locale.h>

Int _tmain(int argc, _tchar* argv[])

{

unsigned char a;

setlocale(LC_ALL, "Russian");

printf("Введите число:\n");

scanf("%c", &a);

printf("Код этого числа %d\n", a);

printf("7-ой бит = %d\n", (a>>6)%2);

printf("5-ый бит = %d\n", (a>>4)%2);

printf("3-ий бит = %d\n", (a>>2)%2);

printf("1-й бит = %d\n", (a>>0)%2);

return 0;

}