Question

In: Computer Science

wite a program in C to print a right and left pointing arrow pattern using '#'...

wite a program in C to print a right and left pointing arrow pattern using '#' symbol. Do so within 10 lines i.e upper half of the occupies 5 lines and lower half occupies other 5 lones.

User will enter 'R' or'r' for printing right pointing arrow. 'l' or 'L' for left pointing arrow.'k'' for invalid option.

You must use if-else and while loop for do this.

Solutions

Expert Solution

Please find the code below::

#include<stdio.h>
#include<string.h>
int main(){

   char choice;
   while(1){
       printf("Enter your choice (L l R r k K) : ");
       scanf("%c",&choice);
       while(choice=='\n')
       scanf("%c",&choice);
       if(choice=='l' ||choice=='L'){
           printf(" #\n");
           printf(" #\n");
           printf(" #\n");
           printf(" #\n");
           printf("#############################\n");
           printf("#############################\n");
           printf(" #\n");
           printf(" #\n");
           printf(" #\n");
           printf(" #\n");
       }else if(choice=='R'||choice=='r'){
           printf(" #\n");
           printf(" #\n");
           printf(" #\n");
           printf(" #\n");
           printf("#############################\n");
           printf("#############################\n");
           printf(" #\n");
           printf(" #\n");
           printf(" #\n");
           printf(" #\n");
       }else if(choice =='k' || choice =='K'){
           break;
       }else{
           printf("Please enter valid choice....\n");
       }
   }
   return 0;
}

output:


Related Solutions

Write a C# console program that fills the right to left diagonal of a square matrix...
Write a C# console program that fills the right to left diagonal of a square matrix with zeros, the lower-right triangle with -1s, and the upper left triangle with +1s. Let the user enter the size of the matrix up to size 21. Use a constant and error check. Output the formatted square matrix with appropriate values. Refer to the sample output below. Sample Run: *** Start of Matrix *** Enter the size of square (<= 21): 5 1 1...
Program coding for C# (Visual Studio) to move block up and down left to right. Simple...
Program coding for C# (Visual Studio) to move block up and down left to right. Simple harmonic motion
USING a LOOP for C++ In this lab the completed program should print the numbers 0...
USING a LOOP for C++ In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and by 10....
write a program that will print a truth table for p ^ ~q. Using C++ please.
write a program that will print a truth table for p ^ ~q. Using C++ please.
1. Wite a program to exchange the contents of memory locations 2050H and 2370H using STA...
1. Wite a program to exchange the contents of memory locations 2050H and 2370H using STA and LDA instructions.
Write a Java program to print the pattern of asterisks shown below. For i=1 * For...
Write a Java program to print the pattern of asterisks shown below. For i=1 * For i=2 * * * For i=3 * ** * * * For i=n * * * * * * … … … * * * * * * ……… n
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
Using C++ code, write a program named q5.cpp to print the minimum of the sums x...
Using C++ code, write a program named q5.cpp to print the minimum of the sums x + y^3 and x^3 + y, where x and y are input by a user via the keyboard.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT