Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <math.h>
  5.  
  6. struct complex_t* set(struct complex_t* cp, float re, float im, int *err_code);
  7.  
  8. struct complex_t
  9. {
  10. float re;
  11. float im;
  12. };
  13.  
  14. int main(){
  15. struct complex_t number1;
  16. printf("Podaj pierwsza liczbe: ");
  17. if(scanf("%f %f",&number1.re,&number1.im)!=2){
  18. printf("Incorrect input");
  19. return 1;
  20. }
  21. struct complex_t number2;
  22. printf("Podaj druga liczbe: ");
  23. if(scanf("%f %f",&number2.re,&number1.im)!=2){
  24. printf("Incorrect input");
  25. return 1;
  26. }
  27. float modul_1 = complex_abs(&number1,NULL);
  28. float modul_2 = complex_abs(&number2,NULL);
  29.  
  30.  
  31. return 0;
  32. }
  33.  
  34. struct complex_t* set(struct complex_t* cp, float re, float im, int *err_code){
  35. if (cp == NULL){
  36. return *err_code = NULL;
  37. }
  38. cp->re = re;
  39. cp->im = im;
  40. return *err_code = cp;
  41. }
  42.  
  43. void show(const struct complex_t* cp){
  44. printf("");
  45. }
  46.  
  47. float complex_abs(struct complex_t* cp, int * err_code){
  48. if(cp == NULL){
  49. return *err_code = 1;
  50. }
  51. float modul = sqrt(pow(cp->re,2)+pow(cp->im,2));
  52. return modul;
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement