Knowee
Questions
Features
Study Tools

Develop a C program to print the following pattern of N rows using whileloop (Read N value from the Keyboard)For Example: N value : 512 34 5 67 8 9 1011 12 13 14

Question

Develop a C program to print the following pattern of N rows using whileloop (Read N value from the Keyboard)For Example: N value : 512 34 5 67 8 9 1011 12 13 14

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a step-by-step guide to develop a program in C to print the given pattern using a while loop:

  1. Start by including the necessary header files:
#include <stdio.h>
  1. Declare the main function:
int main() {
    // code goes here
    return 0;
}
  1. Declare the variables to store the input value and the current number:
int n, num;
  1. Prompt the user to enter the value of N:
printf("Enter the value of N: ");
scanf("%d", &n);
  1. Initialize the variables:
num = 1;
  1. Start the while loop to print the pattern:
while (num <= n) {
    printf("%d ", num);
    num++;
    if (num % 2 == 0) {
        printf("\n");
    }
}
  1. Finally, close the main function:
return 0;

The complete code will look like this:

#include <stdio.h>

int main() {
    int n, num;

    printf("Enter the value of N: ");
    scanf("%d", &n);

    num = 1;

    while (num <= n) {
        printf("%d ", num);
        num++;
        if (num % 2 == 0) {
            printf("\n");
        }
    }

    return 0;
}

This program will prompt the user to enter the value of N and then print the pattern accordingly using a while loop.

This problem has been solved

Similar Questions

Read a integer N and print a character pattern with N rows.For example if N=5, the pattern isABBCCCDDDDEEEEE

write a program to print integer no, from 1 to n where n is the input from the user using do while loop in c language use getch

Write a C program to print the Pyramid with numbersWrite a program to print a pyramid of numbers separated by spaces for the given number of rows.At the time of execution, the program should print the message on the console as:Enter number of rows : For example, if the user gives the input as:Enter number of rows : 5then the program should print the result as:Enter number of rows : 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Write a program to print the following pattern if a number of rows are entered by the user at run time : For Example: if the number of rows is 51 2 6 3 7 10 4 8 11 13 5 9 12 14 15 Sample Test CasesTest Case 1:Expected Output:Enter·the·number·of·rows:·71·2·8·3·9·14·4·10·15·19·5·11·16·20·23·6·12·17·21·24·26·7·13·18·22·25·27·28·Test Case 2:Expected Output:Enter·the·number·of·rows:·51·2·6·3·7·10·4·8·11·13·5·9·12·14·15·

What will be the output of the following program?#include<stdio.h> int main() {     char j=1;     while(j < 5)     {         printf("%d, ", j);         j = j+1;     }     printf("\n");     return 0; }Select one:4, 3, 2, 11 2 3 42 3 4 5 61, 2, 3, 4,

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.