Question

In: Computer Science

Create a basic program (C Programming) that accomplishes the following requirements: Prints "for loop" and then...

Create a basic program (C Programming) that accomplishes the following requirements:

Prints "for loop" and then uses a for statement to count from 1 to 100.
Prints "while loop" and then uses a while statement to count from 1 to 100.
Prints "do while loop" and then use a do while statement to count from 1 to 100.
Using a nested if/else statement or a switch in one of the loops , print to the screen if a number is:
Less than or equal to 10 (print less than 11 to the screen)
Greater than or equal to 11 but less than 20. (print between 10 and 20 to the screen)
Greater than 21 (print greater than 21 to the screen)

Solutions

Expert Solution

#include<stdio.h>

int main()
{
   int i;
  
   /* Prints "for loop" and then uses a for statement to count from 1 to 100. */
   printf("for loop\n");
   for(i=1;i<=100;i++)
   {
       printf("%d",i);
       /*
       Using a nested if/else statement or a switch in one of the loops , print to the screen if a number is:
       Less than or equal to 10 (print less than 11 to the screen)
       Greater than or equal to 11 but less than 20. (print between 10 and 20 to the screen)
       Greater than 21 (print greater than 21 to the screen)
       */
       if(i<=10)
       {
           printf("\tless than 11");
       }
       else if(i>=11 && i<20)
       {
           printf("\tbetween 10 and 20");
       }
       else if(i>21)
       {
           printf("\tGreater then 21");
       }
       printf("\n");
   }
  
   /* Prints "while loop" and then uses a while statement to count from 1 to 100. */
   printf("\nwhile loop\n");
   i=1;
   while(i<=100)
   {
       printf("%d\n",i++);
   }
  
   /* Prints "do while loop" and then use a do while statement to count from 1 to 100. */
   printf("\ndo while loop\n");
   i=1;
   do
   {
       printf("%d\n",i++);
   }while(i<=100);
}


Related Solutions

Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to input 2 numbers, a starting number x and ending number y Implements a while loop that counts from x (start) to y(end). Inside the loop, print to the screen the current number Print rather the current number is even or odd If the number is even , multiply by the number by 3 and print the results to the screen. If the number is...
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Programming In C Write a program that prints the values in an array and the addresses...
Programming In C Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Write a C program that meets the following requirements. Uses a while loop to display the...
Write a C program that meets the following requirements. Uses a while loop to display the first 10 natural numbers (on one row, with a tab separating each number) Uses a while loop to find the sum of the second set of 10 natural numbers. Reads a user entry and displays all the natural numbers up to the user entry (on a column list with a new line separating each number). Finds and displays the sum of all natural numbers...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
develop an algorithm and then a C program that accomplishes the following. determines the minimum number...
develop an algorithm and then a C program that accomplishes the following. determines the minimum number of quarters, dimes, nickels, and pennies to make change for any amount of cents from 1 cent to 99 cents inclusive; produces an error message if 0 or more than 99 is entered as input, but the program will keep running and ask for another input; terminate if 0 or a negative number is entered. Here is possible example of the program running (remember...
develop an algorithm and then a C program that accomplishes the following. determines the minimum number...
develop an algorithm and then a C program that accomplishes the following. determines the minimum number of quarters, dimes, nickels, and pennies to make change for any amount of cents from 1 cent to 99 cents inclusive; produces an error message if 0 or more than 99 is entered as input, but the program will keep running and ask for another input; terminate if 0 or a negative number is entered. Here is possible example of the program running (remember...
Multithreaded programming Write a multithreaded program (JAVA) that prints messages with thread IDs. 1. Create at...
Multithreaded programming Write a multithreaded program (JAVA) that prints messages with thread IDs. 1. Create at least three user-threads. 2. Each thread needs to be terminated after printing each thread ID.
Create a c++ program with this requirements: Create an input file using notepad ( .txt )...
Create a c++ program with this requirements: Create an input file using notepad ( .txt ) . When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File”...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT