Jump to content

В чем проблема программы?


Recommended Posts

#include <stdio.h>

#include <conio.h>

#include <math.h>

int main ()

{

int n, i, f;

float x, s;

printf ("Input n");

scanf ("%n",&n);

printf ("Input x");

scanf ("%x",&x);

s=0;

f=1;

for (i=1; i<=n; i++)

{

f=f*i;

s = s+(1/i+sqrt(fabs (x));

}

printf ("s=%f",s);

getch ();

}

1f8a169a40d3.jpg

Дано натуральное число n и действительное х.нужно решить

На языке С

Link to comment
Share on other sites

#include <stdio.h>

#include <conio.h>

#include <math.h>

int main ()

{

int n, i, f;

float x, s;

printf ("Input n");

scanf ("%n",&n);

printf ("Input x");

scanf ("%x",&x);

s=0;

f=1;

for (i=1; i<=n; i++)

{

f=f*i;

s = s+(1/i+sqrt(fabs (x));

}

printf ("s=%f",s);

getch ();

}

42535a2adc82.jpg

Дано натуральное число n и действительное х.нужно решить

На языке С

Link to comment
Share on other sites

f=f*i;

s = s+(1/f+sqrt(fabs (x))

на это должен был компилятор ругнуться.

Считаем скобки открылось три, закрылось две.

Вот так правильно: s = s+(1/f+sqrt(fabs (x)));

Вот так работает:

#include <stdio.h>

#include <conio.h>

#include <math.h>

int main ()

{

int n, i, f;

float x, s;

printf ("Input n");

scanf ("%d",&n);

printf ("Input x");

scanf ("%d",&x);

s=0;

f=1;

for (i=1; i<=n; i++)

{

f=f*i;

s = s+(1/f+sqrt(fabs (x)));

}

printf ("s=%f",s);

getch ();

}

PS: обрати внимание на ввод переменных

Edited by Бумер
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...