Riki_Tiki_Tavi Posted October 17, 2010 Report Share Posted October 17, 2010 #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 (); } Дано натуральное число n и действительное х.нужно решить На языке С Link to comment Share on other sites More sharing options...
Riki_Tiki_Tavi Posted October 17, 2010 Author Report Share Posted October 17, 2010 #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 (); } Дано натуральное число n и действительное х.нужно решить На языке С Link to comment Share on other sites More sharing options...
Teddy_Bear Posted October 17, 2010 Report Share Posted October 17, 2010 "f=f*i; s = s+(1/i+sqrt(fabs (x));" А разве не f=f*i; s = s+(1/f+sqrt(fabs (x)); Link to comment Share on other sites More sharing options...
Riki_Tiki_Tavi Posted October 17, 2010 Author Report Share Posted October 17, 2010 "f=f*i; s = s+(1/i+sqrt(fabs (x));" А разве не f=f*i; s = s+(1/f+sqrt(fabs (x)); Считает любое число, и получается постоянно 0 Link to comment Share on other sites More sharing options...
Бумер Posted October 17, 2010 Report Share Posted October 17, 2010 (edited) 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 October 17, 2010 by Бумер Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now