Пример #1
0
int main()
{
	int t;
	FRACTION f1,f2;
	scanf("%d",&t);
	printf("n0\tn1\t+\t-\t*\t/");
	putchar('\n');
	for(int i=0;i<t;++i)
	{
		f1=getFractionFromStream(stdin);
		f2=getFractionFromStream(stdin);
		writeFractionToStream(stdout,f1);
		putchar('\t');
		writeFractionToStream(stdout,f2);
		putchar('\t');
		writeFractionToStream(stdout,addFraction(f1,f2));
		putchar('\t');
		writeFractionToStream(stdout,subFraction(f1,f2));
		putchar('\t');
		writeFractionToStream(stdout,mulFraction(f1,f2));
		putchar('\t');
		writeFractionToStream(stdout,divFraction(f1,f2));
		putchar('\n');
	}
	return 0;
}
Пример #2
0
int main(void)
{
    //ex 1,2
    printf("Jussi\n\n");

    //ex 3
    printf("%6d, %4d\n", 86, 1040);
    printf("%12.5e\n", 30.253);
    printf("%.4f\n", 83.162);
    printf("%-6.2g\n\n", .0000009979);

    //ex 4
    printf("%d, %d, %d, %d\n\n", 5%2, -5%2, 5%-2, 5%-2);

    int i = 7;
    float f = 5.5;
    char c = 'w';
    printf("%lf\n", (double)(i+f));
    printf("%d\n", (int)(i+c));
    printf("%d\n", (int)(i+c-'0'));
    printf("%lf\n\n", (double)((i+c)-(2*f/5)));

    printf("%i\n\n", ((int)f)%2);

    i = 1;
    printf("i = %d \n", i);
    printf("i = %d \n", ++i);
    printf("i = %d \n", i);

    float x = 1.1;
    double d=2.2;
    printf("integer: %d \n", sizeof(i));
    printf("float: %d \n", sizeof(x));
    printf("double: %d \n", sizeof(d));
    printf("character: %d \n", sizeof(c));

    //ex 5
    d = (char)d;
    i = 8;
    int j = 5;
    x = (double)x;
    x = 0.005;
    double y = -0.01;
    c = 'c';
    d = 'd';

    abs(i - 2 * j); //absolute value
    fabs(x+y); //floating point abs
    isprint(c); //check if char is printable
    isdigit(c); //check if character is decimal digit
    toupper(d); //lowercase --> uppercase
    ceil(x); //round up
    ceil(x+y); //--
    floor(x); //round down
    floor(x+y); //--
    islower(c); //check if char is lowercase
    isupper(j); // -- uppercase
    exp(x); //e^x
    log(x); //trivial
    log(exp(x)); //x
    sqrt(x*x+y*y); //square root
    isalnum(10*j); //check if char is alphanumeric
    isalpha(10*j); // -- alphabetic
    isascii(10*j); // -- a 7-bit US-ASCII char code
    toascii(10*j); // converto to --
    fmod(x,y); //remainder of division
    tolower(65); //uppercase --> lowercase
    strlen("hello\0"); //string lenght
    strstr("hello\0", 'e'); //locate substring

    //ex 6
    printf("\n%d, %d\n\n", itseis(-4), itseis(8));

    //ex 7
    printf("GCD: %d\n\n", maxdiv(1235,345));

    //ex 8
    printf("SYT: %d\n\n", syt(1235,345));

    //ex 9
    int onnaa = addFraction(1,2,1,2);
    printf("%d\n\n",onnaa);

    //ex 10
    onnaa = subFraction(3,2,1,2);
    printf("%d\n\n",onnaa);

    //ex 11
    onnaa = mulFraction(3,2,1,2);
    printf("%d\n\n",onnaa);

    //ex 12
    onnaa = divFraction(3,2,1,2);
    printf("%d\n\n",onnaa);

    return 0;
}