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...
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.
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.
Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2...
Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2 #####1 ####12 ###123 ##1234 #12345
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
IN C LANGUAGE This program will read in a series of strings and print only the...
IN C LANGUAGE This program will read in a series of strings and print only the consonants (including Y) until the word "stop" appears. No string will be longer than 100 characters. A consonant is any letter that is not a vowel. Don't forget to follow the standard read pattern! Examples Enter a string: Hello Hll Enter a string: World! Wrld Enter a string: 123! Enter a string: stop Enter a string: stop
Which of the patient’s limbs serves as an electrical ground? A)left arm b) right Arm c)right...
Which of the patient’s limbs serves as an electrical ground? A)left arm b) right Arm c)right leg d)left leg
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT