Make a diamond using loops


SUBMITTED BY: Guest

DATE: Oct. 27, 2014, 12:23 p.m.

FORMAT: Text only

SIZE: 1.3 kB

HITS: 774

  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int rows, b, c;
  6. char choice;
  7. do
  8. {
  9. clrscr();
  10. cout<<"Enter number of rows \n\"Value should be > 1\" \n";
  11. cin>>rows;
  12. cout<<endl;
  13. for (int dash=1; dash<=80; dash++)
  14. {
  15. cout<<"-";
  16. }
  17. cout<<endl;
  18. for (b=1; b<=rows; b++)
  19. {
  20. for (c=rows; c>=b; c--)
  21. {
  22. cout<<"*";
  23. }
  24. for (c=1; c<=(b*2)-2; c++)
  25. {
  26. cout<<" ";
  27. }
  28. for (c=rows; c>=b; c--)
  29. {
  30. cout<<"*";
  31. }
  32. cout<<endl;
  33. }
  34. /*---------------------------*/
  35. for (b=1; b<=rows; b++)
  36. {
  37. for (c=1; c<=b; c++)
  38. {
  39. cout<<"*";
  40. }
  41. for (c=rows; c>=(b*2)-(rows-1); c--)
  42. {
  43. cout<<" ";
  44. }
  45. for (c=1; c<=b; c++)
  46. {
  47. cout<<"*";
  48. }
  49. cout<<endl;
  50. }
  51. cout<<endl;
  52. for (int dash=1; dash<=80; dash++)
  53. {
  54. cout<<"-";
  55. }
  56. cout<<endl;
  57. cout<<"Press Y to start again.";
  58. cin>>choice;
  59. }
  60. while (choice=='Y' || choice=='y');
  61. }

comments powered by Disqus