Question

C Code

Make a function that prints the following output using loops.

void draw_pattern(int size){

}

Output for different size values

SIZE=1

+* + l/ INI IVVI IVVL

SIZE= 2

|../..../\..| 1/11/11 IN VI T.VV.Vol ...V....Voil t=*=*=*=*=*=*+

Size=3

J.../...../...) |../ ..../ .. 1./ ../ .. INVI WWWWWW| J.VV..VV. J..V ....W ... 1...V......V... +=*=*=*=*=*=*=*=*+

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

//function to draw patter
void draw_pattern(int size)
{
//draw upper half part of the pattern
for(int i=0; i<size+1; i++)
{
printf("|");
for(int p = 0; p<2; p++)
{
for(int j=0; j<size-i; j++)
printf(".");
for(int k=0; k<=i; k++)
printf("/\\");
for(int j=0; j<size-i; j++)
printf(".");
}
printf("|");
printf("\n");
}
  
//draw lower half part of the pattern
for(int i=0; i<size+1; i++)
{
printf("|");
for(int p = 0; p<2; p++)
{
for(int j=0; j<i; j++)
printf(".");
for(int k=0; k<=size-i; k++)
printf("\\/");
for(int j=0; j<i; j++)
printf(".");
}
printf("|");
printf("\n");
}
  
//draw the last line
printf("+");
for(int i=0; i<(size+1)*2; i++)
printf("=*");
printf("+");
}

int main()
{
//function calling
draw_pattern(2);

return 0;
}

OUTPUT:

1./../1. INVVV IVVI 1.V..V.L +=*=*=*=*+

|../..../.. 1./ ../V . WWWWW VVVVV \/\.. \.| J..V....V.. +=*=*=*=*=*=*+

1.../....../...| 1../ ..../V/\..| 1./11../ 1 1 . INWWWWWW \/\/\/\/\/\/\/\| 1.VVV..VVV.|| 1..V ....VV..|| ...V......V...| +=*=

Add a comment
Know the answer?
Add Answer to:
C Code Make a function that prints the following output using loops. void draw_pattern(int size){ }...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • QUESTION 62 Consider the following code: void Pancake(int x, int& y, int z); void Waffle(int& x,...

    QUESTION 62 Consider the following code: void Pancake(int x, int& y, int z); void Waffle(int& x, int& y); int Doughnut(int y, int z); int main( ) {             int a = 1;             int b = 2;             int c = 3;             int d = 4;             Pancake(a, b, c);             Waffle(b, c);             Pancake(d, c, b);             d = Doughnut(b, a);             return 0; } void Pancake(int x, int& y, int z) {             y += 3;            ...

  • pic 4: Loops What is the output of the following code? int main0 ( int x...

    pic 4: Loops What is the output of the following code? int main0 ( int x = 1; while (x < 7) t İf ( (x % 2)-= 1)(1/ if x is odd x=x+1; else t x = x + 2; return 0; Select óne O a. 124 6 8 O b. 1 234 5 6 7 O c. 246 O d. 24 6 8 PREVIOUS PAGE NE

  • C++ Write code using 2 nested loops, that produces the following output. Write code using 2...

    C++ Write code using 2 nested loops, that produces the following output. Write code using 2 nested loops, that produces the following output. 1 5 4 3 2 1 4 3 2 1 3 2 1 code.cpp New #include <iostream> 2 using namespace std; 3 4 int main() { 5 6 // TODO: your code go 7 8 9 2 1 1 }

  • Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which...

    Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which prints each character of the given string str on a new line, with each line numbered 1, 2, 3, …. For example calling the function with printNumberedChars("hello"); should output the following: 1. h 2. e 3. l 4. l 5. o Q2. Write a recursive function in C++ int sumArray(const int* arr, unsigned int size) { ... } which takes an array of integers,...

  • The following function prints a natural number sequence across the diagonal of an n by n...

    The following function prints a natural number sequence across the diagonal of an n by n square matrix. Debug the code to fix all the compilation and run-time errors, so that the code generates the desired output. For instance, when the num value passed to the function is 5, the output would look like the following. 1**** *2*** **3** ***4* ****5 void naturalDiagonal(int num); for (int i=0; i < num - 1; i++) { for (int j=1; j <= number;...

  • Give the output for the following code assume int globalvar 10: above the function prototypes void...

    Give the output for the following code assume int globalvar 10: above the function prototypes void foo(int&); void bar(int); int main() { int globalVar = 5; foo(globalVar); cout << globalVar << endl; bar(globalVar); cout << globalVar << endl; return 0; } void foo(int& x) { x = globalVar + x; cout << globalVar << endl; return; void bar(int x) { globalVar + x; cout << globalVar << endl; X = return;

  • Consider the following C++code snippet and what is the output of this program? # include<iostream> using...

    Consider the following C++code snippet and what is the output of this program? # include<iostream> using namespace std; void arraySome (int[), int, int); int main () const int arraysize = 10; int a[arraysize]-1,2,3,4,5, 6,7,8,9,10 cout << "The values in the array are:" << endl; arraySome (a, 0, arraySize) cout<< endl; system ("pause") return 0; void arraySome (int b[], int current, int size) if (current< size) arraySome (b, current+1, size); cout << b[current] <<""; a) Print the array values b) Double...

  • What is wrong with the following function definition? void fill(const int a[], int size) { for...

    What is wrong with the following function definition? void fill(const int a[], int size) { for (int i = 0; i < size; i++) {     a[i] = 0; } return; } Answers: The function cannot change the array parameter. The array should be passed as a call-by-reference, not call-by-value. The for loop causes an out-of-bounds indexing error. Nothing, the code works fine as is.

  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0)...

    (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0) return 0; 3 return (n-1 + g(n-1)); 4} (b) Consider the following C++ function: 1 bool Function (const vector <int >& a) { 2 for (int i = 0; i < a. size ()-1; i ++) { 3 for (int j = i +1; j < a. size (); j ++) { 4 if (a[i] == a[j]) return false; 5 6 } 7 return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT