Loops
Loops
A for, while and do while loop to print Hello World 10 times in given below:
#include<stdio.h>
i=0;
while(i<10){
printf("Hello World\n");
i++;
}
do{
printf("Hello World\n");
i++;
} while(i<10)
return 0;
}
Exercises:
1. Write a program to calculate the average of first ten natural numbers using loop.
3. Write a program that reads an integer with 5 digits and finds the sum and average of
digits of the number.
4. Write a program to find whether a positive integer (6 digits) entered by the user is a
palindrome or not. E.g. 12321 is a palindrome whereas 112233 is not.
5. Write a program to print the following pyramid for a user given positive n(<10). All the
below sample outputs are for N=4.
1
12
123
1234