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...
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)...
How would I write this function in C programming language? Function header: int input(int *a, int...
How would I write this function in C programming language? Function header: int input(int *a, int *b, int *c) This function should attempt to input 3 integers from the keyboard and store them in the memory locations pointed to by a, b, and c. The input may not be successful in reading all three values. The function should return the number of values that were successfully read.
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
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.
Be able to write Python programming of a factorial of an integer (given input parameters, output...
Be able to write Python programming of a factorial of an integer (given input parameters, output characteristics and expected output behavior, do not use internal python functions for factorials), recall for example that: 5! = 5 ∗ 4 ∗ 3 ∗ 2 ∗ 1 = 120 and to continue asking unless user says to stop NOT USING FACTORIAL FUNCTION
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop (instead of for). • The function takes a single integer n as a parameter • The function prints a series between 1 and that parameter, and also prints its result • The result is calculated by summing the numbers between 1 and n (inclusive). If a number is divisible by 5, its square gets added to the result instead. • The function does not...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT