Home > Backend Development > C++ > Write a program in C language that prints right arrow and left arrow patterns

Write a program in C language that prints right arrow and left arrow patterns

王林
Release: 2023-08-28 13:38:54
forward
1499 people have browsed it

Program description

Print left and right arrow patterns

Algorithm

Accepts the number of lines for printing left and right arrow patterns.

Print Upper Part of the Arrow with Stars Patterns
Print Inverted Right Triangle with Stars Patterns
Print Bottom Part of the Arrow with Stars Patterns
Print the Right Triangle with Stars Patterns
Copy after login

Example

/*Program to print the Left and right arrow pattern*/
#include<stdio.h>
int main() {
   int r, c, rows; //Left Arrow Pattern
   int r1, c1, rows1; //Right Arrow Pattern
   clrscr();
   printf("Enter number of rows to print the Left Arrow Pattern: ");
   scanf("%d", &rows);
   printf("</p><p>");
   printf("The Left Arrow Pattern is:");
   printf("</p><p>");
   for(r=1; r<rows; r++){
      for(c=1; c<=(rows-r); c++){
         printf(" ");
      }
      for(c=r;c<=rows; c++){
         printf("*");
      }
      printf("</p><p>");
   }
   for(r=1; r<=rows; r++){
      for(c=1; c<r; c++){
         printf(" ");
      }
      for(c=1; c<=r; c++){
         printf("*");
      }
      printf("</p><p>");
   }
   printf("Enter number of rows to print the Right Arrow Pattern: ");
   scanf("%d", &rows1);
   printf("</p><p>");
   printf("The Right Arrow Pattern is:");
   printf("</p><p>");
   for(r1=1; r1<rows1; r1++){
      for(c1=1; c1<=(2*r1-2); c1++){
         printf(" ");
      }
      for(c1=r1; c1<=rows1; c1++){
         printf("*");
      }
      printf("</p><p>");
   }
   for(r1=1; r1<=rows1; r1++){
      for(c1=1; c1<=(2*rows1 - 2*r1); c1++){
         printf(" ");
      }
      for(c1=1; c1<=r1; c1++){
         printf("*");
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}
Copy after login

Output

Write a program in C language that prints right arrow and left arrow patterns

Write a program in C language that prints right arrow and left arrow patterns

The above is the detailed content of Write a program in C language that prints right arrow and left arrow patterns. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template