Question

4.6.1: For loops.

Write a for loop that prints: 1 2 ... lastNumber
Ex: If the input is:

4

the output is:

1 2 3 4 Screenshot (53).png

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main()
{
    int n;
    printf("Enter the last number: ");
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        printf("%d ",i);
    }
}

Output:

image.png

answered by: Zahidul Hossain
Add a comment
Know the answer?
Add Answer to:
4.6.1: For loops.
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
  • IN MATLAB CHALLENGE ACTIVITY 25.5.1: For loops. Reset Write a for loop that prints from initialNumber...

    IN MATLAB CHALLENGE ACTIVITY 25.5.1: For loops. Reset Write a for loop that prints from initialNumber to finalNumber. Ex: initialNumber-3 and finalNumber 1 outputs 3 -2 -1 0 1 I #include <stdio.h> 3 int main(void) t 4 int initialNumber; 6 int i; int finalNumber; initialNumber--5 11 for 12 13 14 Your solution goes heref printf("%d ", i); return 161 17 5 Check Next

  • C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an...

    C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an initial number, followed by that number of integers. Output those integers' sum. Repeat until the initial number is O or negative. Ex: If the user enters 3 96 1 0, the output is 16 Ex: If the user enters 396125 3 0, the output is 16 Hints: Use a while loop as an outer loop. Get the user's initial number of ints before the...

  • Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of...

    Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of integers, declared to be "int** A," to the standard output. Each of the rows should appear on a separate line. Your input will be as follows with the first two values being the number of rows and columns respectively. HINT: This is best done with one for-loop nested within another Sample 1/0 1: Input: 3 2 1 2 3 4 Ол 6 Output: 12...

  • 4) (12 points) Write the CH code that continuously (use a loop) prompts a user to...

    4) (12 points) Write the CH code that continuously (use a loop) prompts a user to input a floating point number. Each time, the code prints out the input, numbered. So if the user inputs a -2.3 for the first input and a 116.79 for the second input, the output is input 1: -2.3 input 2: 116.79 The loop keeps running until the sum of all the numbers input is greater than 100. (This needs an accumulator!)

  • PYTHON 4. While Loops (25%) You will be writing a "shell" application, it will be on...

    PYTHON 4. While Loops (25%) You will be writing a "shell" application, it will be on a loop, taking in commands from the user. The command syntax is as follows command> <arga» <arg1> arg n> The commands you are to implement: Command Description Prints all arguments on the same line, with a space between each. Treats all arguments as floating-point numbers, and prints the average. MUST print an error if given invalid arguments Finds the index of arg1 in arg0....

  • Reverse of a digraph 30 Marks For a given set of digraphs, write a program that prints out the reverse of each digraph. Input format: described below under the heading “Digraph input format”. Note th...

    Reverse of a digraph 30 Marks For a given set of digraphs, write a program that prints out the reverse of each digraph. Input format: described below under the heading “Digraph input format”. Note that adjacency lists are sorted. Output format: use the input format to output your result ensuring that the output adjacency lists are sorted. the input format: 4 1. 3 2. 3 0 3 1. 2 1 0 2. Reverse of a digraph 30 Marks For a...

  • 3.11 LAB: Mad Lib - loops Mad Libs are activities that have a person provide various...

    3.11 LAB: Mad Lib - loops Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways. Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is quit 0. Ex: If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a...

  • C programming! Write a program that reads integers until 0 and prints the sum of values...

    C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...

  • For Java Write a program that reads a sequence of integer inputs all on one line...

    For Java Write a program that reads a sequence of integer inputs all on one line and prints: 1.)The smallest and largest of the inputs 2.)The number of odd and even inputs 3.)Cumulative totals. If the input is 1 7 2 9, the program prints 1 8 10 19. 4.)All adjacent duplicates. If the input is 1 3 3 4 5 5 6 6 6 2, the output is 3 5 6.

  • ANSWER IN C PLEASE (: ew History Bookmarks Window Help 13.16. Loops E ry> ECE 270...

    ANSWER IN C PLEASE (: ew History Bookmarks Window Help 13.16. Loops E ry> ECE 270 home > 13.16 Loops-Ex4 zyBooks catalog TO.TU LOOo Write a program that prints a pattern like the ones shown below Ask the user to input the letter that goes in the middle of the last row in the pyramid (uppercase or lowercase). The pattern should extend to the character entered. In the Example 1, the pattern is the result from an input value of...

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