1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
1. #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
FILE *data = NULL;
char fname[16];
char sname[16];
int i = 0;
data = fopen("data.txt", "r");
if (in == NULL){
printf("ERROR\n");
system("pause");
}
fscanf(data, "%s", &fname);
fscanf(data, "%s", &sname);
for (i = 0; i < strlen(fname); i++){
printf("%c\n", fname[i]);
}
printf("\n");
for (i = 0; i < strlen(sname); i++){
printf("%c\n", sname[i]);
}
system("pause");
return 0;
}
2. #include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct person{
char name[16];
char lname[16];
int age;
}person;
int main(void)//
{
person tab[2];
char buf[64];
int i;
for (i = 0; i < 2; i++){
printf("enter the name: ");
fscanf_s(stdin, " %s", tab[i].name);
printf("etner the last name: ");
fscanf_s(stdin, " %s", tab[i].lname);
printf("enter the age of: ");
scanf_s(" %d", tab[i].age);
getchar();
}
for (i = 0; i < 2; i++){
printf("%s %s is %d years old.\n", tab[i].name, tab[i].lastname, tab[i].age);
}
system("pause");
return 0;
}
3. #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define _PI 3.14
int main ( int argc, char* argv[] )
{
float r;
if(argc=!4){
printf("ERROR\n");
system("pause");
exit(1);
}
a = atof( argv[1] );
b = atof( argv[2] );
c = atof( argv[3] );
printf( "Circle of radius %d has an area equal to %f and the circumference equal to %f", r, r*r*_PI, 2*r*_PI);
return 0;
}
4. #include<stdio.h>
#include<stdlib.h>
typedef struct
{
int a;
int h;
}triangle;
int main(void)
{
triangle OurTriangle={0};
printf("Specify the length of the base: ");
scanf("%d", &OurTriangle.a);
printf("enter the amount: ");
scanf("%d", &OurTriangle.h);
printf("Pole wynosi: %f \n", (float)OurTriangle.a*OurTriangle.h*0.5);
system("pause");
return 0;
}
|