Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- void vvod_dannih(char argc, char **argv)
- {
- char ni[10], no[10];
- printf( "Algandmete faili nimi on " );
- scanf( "%s", ni );
- printf( "Tulemuste faili nimi on " );
- scanf( "%s", no );
- }
- int main( int argc, char **argv )
- {
- char ni[10], no[10];
- double A, B, H, X, Y;
- int i = 0;
- int x;
- int digits[2];
- char letter[3] = {'A', 'B'};
- FILE *fi, *fo;
- /*
- printf( "Algandmete faili nimi on " );
- scanf( "%s", ni );
- printf( "Tulemuste faili nimi on " );
- scanf( "%s", no ); */
- vvod_dannih(ni, no);
- fi = fopen( ni, "r" ); //fail avatakse lugemiseks
- fo = fopen( no, "w" );
- if ( NULL == fi )
- {
- printf( "%s fail polnud voimalik avada.\n", ni );
- return 1;
- }
- if ( NULL == fo )
- {
- printf( "%s fail polnud voimalik avada.\n", no );
- return 1;
- }
- while ( EOF != fscanf( fi, "%d", &x ) ) //loeb failist lopuni
- {
- if ( 2 > i )
- {
- fprintf( fo, "%c = %d\n", letter[ i ], x );
- digits[ i ] = x;
- }
- i++;
- }
- A = digits[0];
- B = digits[1];
- if( A > B ) {
- do {
- printf("H (H < 0) = ");
- scanf("%lf", &H);
- fscanf(fo, "%lf", &H);
- } while ( H >= 0 );
- } else {
- do {
- printf("H (H > 0) = ");
- scanf("%lf", &H);
- fscanf(fo, "%lf", &H);
- } while ( H <= 0 );
- }
- //fprintf(fo, "H = %d\n", H);
- printf(" ARGUMENT | Funktsioon\n");
- fprintf(fo, " ARGUMENT | Funktsioon\n");
- printf("____________|_____________\n");
- fprintf(fo, "____________|_____________\n");
- i=0;
- do {
- if( i == 0 ) {
- X = A;
- }
- if( X > B ) {
- if ( i == 1 ) {
- X = A + H;
- }
- if( i > 1 ) {
- X = A + i * H;
- }
- if(X<B) {
- return 0;
- }
- }
- if( X < B ) {
- if( i == 1 ) {
- X = A + H;
- }
- if( i > 1 ) {
- X = A + i * H;
- }
- if(X>B) {
- return 0;
- }
- }
- Y = log( sqrt( exp( (double)(X - 1) ) ) );
- if( exp( X - 1 ) < 0 ) {
- printf("Puudub\n");
- fprintf(fo, "Puudub\n");
- } else {
- printf("%10.4lf |%10.4lf\n", X, Y);
- fprintf(fo,"%10.4lf |%10.4lf\n", X, Y);
- }
- if( X == B ) {
- return 0;
- }
- i++;
- } while(1);
- return 0;
- }
Add Comment
Please, Sign In to add comment