Question

In C programming language write a function that takes an integer n as input and prints...

In C programming language write a function that takes an integer n as input and prints the following pattern on the screen:
1 (n times)
2 (n-1 times)
.n (1 time)
For example, if n was 5, the function should print

1 1 1 1 1
2 2 2 2
3 3 3
4 4
5

Homework Answers

Answer #1
#include <stdio.h>

void numberPattern(int n);

int main() {
    int n;
    printf("Enter a value for n: ");
    scanf("%d", &n);
    numberPattern(n);
    return 0;
}

void numberPattern(int n) {
    int i, j;
    for (i = n; i >= 1; --i) {
        for (j = 0; j < i; ++j) {
            printf("%d ", n - i + 1);
        }
        printf("\n");
    }
}

Know the answer?
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
Similar Questions
In C programming language write a function that takes two arrays as input m and n...
In C programming language write a function that takes two arrays as input m and n as well as their sizes: size_m and size_n, respectively. Then it checks for each element in m, whether it exists in n. The function should update a third array c such that for each element in m: the corresponding position/index in c should be either 1, if this element exists in m, or 0, if the element does not exist in n
In R- Studio : Write a function that takes as an input a positive integer and...
In R- Studio : Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Write a recursive function, do not use any of the loop commands in your code.
Using C programming Create a function called printMenu( ) with the following properties: Has no function...
Using C programming Create a function called printMenu( ) with the following properties: Has no function inputs or output. Prints the following menu to the screen: 1. Enter user name. 2. Enter scores. 3. Display average score. 4. Display summary. 5. Quit Create a function called printLine( ) with the following properties: Takes as input a char Takes as input an integer corresponding to the number of times to print the character Has no function output. For example, if we...
write a python program for a function that takes in an integer n and prints the...
write a python program for a function that takes in an integer n and prints the nth taylor approximation for the function f(x)=e^x at the point x=0 to x=1
In LISP, write a recursive function that takes an integer n and returns the summation of...
In LISP, write a recursive function that takes an integer n and returns the summation of n and all positive integers preceding it. ; e.g., passing 5 will return 15, which is 1+2+3+4+5. I have the worst skill when it comes to creating recursion in the LISP programming language. Any help at all would be appreciated.
Write a program that takes from standard input an expression without left parentheses and prints the...
Write a program that takes from standard input an expression without left parentheses and prints the equivalent infix expression with the parentheses inserted. For example, given the input: 1 + 2 ) * 3 - 4 ) * 5 - 6 ) ) ) your program should print ( ( 1 + 2 ) * ( ( 3 - 4 ) * ( 5 - 6 ) ) Without using imports for StdOut and StdIn and implementing your own Stack...
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY****************** Write a recursive Racket function "update-if" that takes...
***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY****************** Write a recursive Racket function "update-if" that takes two functions, f and g, and a list xs as parameters and evaluates to a list. f will be a function that takes one parameter and evaluates true or false. g will be a function that takes one parameter and evaluates to some output. The result of update-if should be a list of items such that if x is in xs and (f x)...
C programing Write a function that takes in an integer as input and returns an integer...
C programing Write a function that takes in an integer as input and returns an integer array of zeros.
For C++: a) Write a function is_prime that takes a positive integer X and returns 1...
For C++: a) Write a function is_prime that takes a positive integer X and returns 1 if X is a prime number, or 1 if X is not a prime number. b) write a program that takes a positive integer N and prints all prime numbers from 2 to N by calling your function is_prime from part a.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT