Looping Programs
Looping Programs
h>
int main() {
while (i >= 0) {
Copy
Sample Output:
0 1 2 3 4 5 6 7 8 9 10
Numbers from 10 to 0:
10 9 8 7 6 5 4 3 2 1 0
#include <stdio.h>
int main() {
while (1) {
if (number == 0) {
if (number > 0) {
}
Sample Output:
Input a number: 5
Input a number: 9
Input a number: -3
Input a number: 2
Input a number: 5
Input a number: 6
Input a number: 0
#include <stdio.h>
int main() {
product *= number;
number++;
}
return 0; // Indicate successful program execution
Copy
Sample Output:
#include <stdio.h>
int main() {
int index = 0; // Index to keep track of the current position in the array
while (!hasDuplicate) {
if (readStatus != 1) {
if (userInput == previousNumbers[i]) {
Sample Output:
Input a number: 2
Input a number: 3
Input a number: 1
Input a number: 4
Input a number: 5
Input a number: 3
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
srand(time(NULL)); // Seed the random number generator with the current time
while (1) {
if (userGuess == targetNumber) {
} else {
Sample Output:
#include <stdio.h>
int main() {
if (number < 0) {
}
// Calculate the factorial using a while loop
Sample Output:
Factorial: 120
#include <stdio.h>
#include <string.h>
int main() {
char username[20]; // Array to store the user input for the username
while (1) {
scanf("%s", username); // Read the user input and store it in the array
} else {
Sample Output: