Program to how do I print a fish pattern using a loop in C?



  1. Program to how do I print a fish pattern using a loop in C?
    This is the best fish pattern, I have used trigonometry for writing the program.
    To understand this program you should have knowledge of following topics in C.
    Program:
    #include <stdio.h>


  2. #include <stdlib.h>


  3. #include<math.h>


  4. int main()


  5. { float n,i,j,t,s;


  6. printf("Enter the size of fish\n");


  7. scanf("%f",&n);


  8. n=n+14;


  9. s=n/10;


  10. t=4.72/n;


  11. for(j=floor(s);j>=-ceil(s);j--){


  12. for(i=0;i<=4;i=i+t){


  13. if((j<s/2 && j>s/4 && i<1 && i>0.8||j==0 && i<0.6)||(pow(j/s,2)>=pow(sin(i),2))){


  14. printf(" ");


  15. }


  16. else {


  17. printf("*");


  18. }


  19. }


  20. printf("\n");
  21. }
  22. getch();
  23. }


  24. OUTPUT:
  25. Enter the size of fish. 74





No comments

Powered by Blogger.