While Loop
While Loop
h>
int main() {
int i = 1;
while (i <= 5) {
printf("%d\n", i);
i++;
}
return 0;
}
#include <stdio.h>
int main() {
int i = 1;
do {
printf("%d\n", i); // Prints the current value of i
i++; // Increment i by 1
} while (i <= 5); // Condition is checked after executing the block
return 0;
}
//WAP to program to calculate and display the sum of numbers from 1 to 10
#include <stdio.h>
void main() {
int i = 1, sum = 0;
while(i <= 10) {
sum = sum + i;
i++;
}
printf("Sum of numbers from 1 to 10 = %d", sum);
}
WAP to display the series 5 9 13 ….up 10th term
#include <stdio.h>
void main() {
int i = 1, n = 5;
do {
printf("%d\t", n);
n = n + 4;
i++;
} while(i <= 5); // Modify the loop condition as needed (i<=5 to print 5
terms)
}
WAP to display multiplication table of 6
#include <stdio.h>
void main() {
int i = 1, p;
do {
p = 6 * i;
printf("6 * %d = %d\n", i, p);
i++;
} while(i <= 10);
}