List of C Programming Loop Program are covered in this article. Looping means repeating a task. There are two types of loops – Entry Control Loop and Exit Control Loop. In the entry control loop, first, the condition will check then instructions or looping statements will execute. for and while are entry control loop. In the exit control loop, if the condition is false, the exit control loop will execute at least one time. do-while is an exit control loop. We can also provide PDF format to download that C program. To know Why Loops are used in C?
C Programming Loop Program (PDF)
C Programming Loop Program Download (PDF)
Following is the list of C Programming Loop program:
Table of Content
- Print Even Number from 1 to 10.
- Print Odd Number from 1 to 10.
- Check whether the Number is Armstrong Number or Not.
- Find the Factor of an Integer Number.
- Find the GCD or HCF of Two Integer Number.
- Print ASCII value of the Capital Letters (A to Z).
- Print ASCII value of the Small Letters (a to z).
- Check whether Number is Palindrome or Not.
- Print Reverse of a Number.
- Convert Binary Number to Decimal Number.
- Find the Factorial of an Integer Number.
- Print lists of Alphabets from a to z.
- Print lists of Alphabets from A to Z.
- Program to Count Number of Digits in a Number.
- Print Multiplication Table.
- Find First Digit in a Number.
- Calculate Sum of Digits in a Number.
- Print ASCII value of the Special Characters.
- Print Fibonacci Series.
- Check whether Number is Perfect Number or Not.
- Check whether Number is Prime Number or Not.
1. Print Even Numbers from 1 to 10.
Program
#include<stdio.h> int main() { int i; printf("Even numbers between 1 to 10 : "); for (i = 1; i <= 10; i++) { if(i%2 == 0) { printf("%d ", i); } } return 0; }
Output
Even numbers between 1 to 10 : 2 4 6 8 10
2. Print Odd Number from 1 to 10.
Program
#include<stdio.h> int main() { int i; printf("Odd numbers between 1 to 10 : "); for(i = 1; i <= 10; i++) { if ( i % 2 != 0 ) { printf(" %d", i); } } return 0; }
Output
Odd numbers between 1 to 10 : 1 3 5 7 9
3. Check the number is Armstrong number or not.
Armstrong Number: Armstrong number is a number that is equal to the sum of cubes of its individual digits.
Program
#include<stdio.h> int main() { int num, remainder, sum = 0, temp; printf("Enter an integer number : "); scanf("%d", &num); temp = num; while(num) { remainder = num % 10; sum = sum + (remainder * remainder * remainder); num = num / 10; } if(temp == sum) { printf("%d is Armstrong Number\n", temp); } else { printf("%d is not Armstrong Number\n", temp); } return 0; }
Output
Enter an integer number : 153 153 is Armstrong Number
4. Find the Factor of an Integer Number.
Factor of a Number: The factor of a number, is a divisor of the given number that divides it completely, without leaving any remainder.
Program
#include<stdio.h> int main() { int num, i; printf("Enter an Integer Number : "); scanf("%d", &num); printf("Factors of %d are : ", num); for (i = 1; i <= num; ++i) { if (num % i == 0) { printf("%d ", i); } } return 0; }
Output
Enter an Integer Number : 78 Factors of 78 are : 1 2 3 6 13 26 39 78
5. Find the GCD or HCF of Two Integer Number.
Program
#include<stdio.h> int main() { int num1, num2, i, gcd; printf("Enter the First Number : "); scanf("%d", &num1); printf("Enter the Second Number : "); scanf("%d", &num2); for(i=1; i <= num1 && i <= num2; ++i) { if(num1%i==0 && num2%i==0) gcd = i; } printf("HCF or GCD of Number %d and %d is : %d", num1, num2, gcd); return 0; }
Output
Enter the First Number : 10 Enter the Second Number : 20 HCF or GCD of Number 10 and 20 is : 10
6. Print ASCII value of the Capital Letters (A to Z).
Program
#include<stdio.h> int main() { int i; printf("ASCII value of Capital Letters (A to Z) are : "); for ( i = 65; i < 91; i++) { printf ("\nThe ASCII value of %c is %d ", i, i); } return 0; }
Output
ASCII value of Capital Letters (A to Z) are : The ASCII value of A is 65 The ASCII value of B is 66 The ASCII value of C is 67 The ASCII value of D is 68 The ASCII value of E is 69 The ASCII value of F is 70 The ASCII value of G is 71 The ASCII value of H is 72 The ASCII value of I is 73 The ASCII value of J is 74 The ASCII value of K is 75 The ASCII value of L is 76 The ASCII value of M is 77 The ASCII value of N is 78 The ASCII value of O is 79 The ASCII value of P is 80 The ASCII value of Q is 81 The ASCII value of R is 82 The ASCII value of S is 83 The ASCII value of T is 84 The ASCII value of U is 85 The ASCII value of V is 86 The ASCII value of W is 87 The ASCII value of X is 88 The ASCII value of Y is 89 The ASCII value of Z is 90
7. Print ASCII value of the Small Letters (a to z).
Program
#include<stdio.h> int main() { int i; printf("ASCII value of Small Letters (a to z) are : "); for ( i = 97; i < 123; i++) { printf ("\nThe ASCII value of %c is %d ", i, i); } return 0; }
Output
ASCII value of Small Letters (a to z) are : The ASCII value of a is 97 The ASCII value of b is 98 The ASCII value of c is 99 The ASCII value of d is 100 The ASCII value of e is 101 The ASCII value of f is 102 The ASCII value of g is 103 The ASCII value of h is 104 The ASCII value of i is 105 The ASCII value of j is 106 The ASCII value of k is 107 The ASCII value of l is 108 The ASCII value of m is 109 The ASCII value of n is 110 The ASCII value of o is 111 The ASCII value of p is 112 The ASCII value of q is 113 The ASCII value of r is 114 The ASCII value of s is 115 The ASCII value of t is 116 The ASCII value of u is 117 The ASCII value of v is 118 The ASCII value of w is 119 The ASCII value of x is 120 The ASCII value of y is 121 The ASCII value of z is 122
8. Check whether Number is Palindrome or Not.
Palindrome Number: A palindrome number is a number that remains the same when digits are reversed.
Program
#include<stdio.h> int main() { int n, tem, rev = 0, rem; printf("Enter Any Integer Number : "); scanf("%d", &n); tem = n; while (n > 0) { rem = n % 10; rev = rev * 10 + rem; n = n / 10; } if (tem == rev) { printf("Given number is a Palindrome Number"); } else { printf("Given number is not a Palindrome Number"); } return 0; }
Output
Enter Any Integer Number : 121 Given number is a Palindrome Number
9. Print Reverse of a Number.
Program
#include<stdio.h> int main() { int number, reverse = 0, remainder; printf("Enter Any Integer Number : "); scanf("%d", &number); while (number != 0) { remainder = number % 10; reverse = reverse * 10 + remainder; number = number / 10; } printf("Reversed Number : %d", reverse); return 0; }
Output
Enter Any Integer Number : 45678 Reversed Number : 87654
10. Convert Binary Number to Decimal Number.
Program
#include<stdio.h> int main() { int num, binary_num, decimal_num = 0, base = 1, rem; printf ("Enter a Binary Number (0s and 1s) : "); scanf (" %d", &num); binary_num = num; while ( num > 0) { rem = num % 10; decimal_num = decimal_num + rem * base; num = num / 10; base = base * 2; } printf ("The Decimal Number is : %d ", decimal_num); return 0; }
Output
Enter a Binary Number (0s and 1s) : 101 The Decimal Number is : 5
11. Find the Factorial of an Integer Number.
Factorial Number: The factorial of a positive number is the product of all positive integers less than or equal to the value of the number itself.
Program
#include<stdio.h> int main() { int i,fact=1,n; printf("Enter a Number to find Factorial : "); scanf("%d",&n); for(i=1;i<=n;i++) fact=fact*i; printf("Factorial of %d is : %d",n,fact); return 0; }
Output
Enter a Number to find Factorial : 6 Factorial of 6 is : 720
12. Print lists of Alphabets from a to z.
Program
#include<stdio.h> int main() { char ch; printf("List of Alphabets from a to z are : \n"); for(ch = 'a'; ch <= 'z'; ch++) { printf(" %c\n", ch); } return 0; }
Output
List of Alphabets from a to z are : a b c d e f g h i j k l m n o p q r s t u v w x y z
13. Print lists of Alphabets from A to Z.
Program
#include<stdio.h> int main() { char ch; printf("List of Alphabets from A to Z are : \n"); for(ch = 'A'; ch <= 'Z'; ch++) { printf(" %c\n", ch); } return 0; }
Output
List of Alphabets from A to Z are : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
14. Program to Count Number of Digits in a Number.
Program
#include<stdio.h> int main() { int number, count = 0; printf("Enter Any Integer Number : "); scanf("%d", &number); do { count++; number /= 10; } while(number != 0); printf("The Number of Digits in an Integer : %d", count); return 0; }
Output
Enter Any Integer Number : 10 The Number of Digits in an Integer : 2
15. Print Multiplication Table.
Program
#include<stdio.h> int main() { int n, i; printf("Enter an Integer Number : "); scanf("%d", &n); for (i = 1; i <= 10; ++i) { printf("%d * %d = %d \n", n, i, n * i); } return 0; }
Output
Enter an Integer Number : 10 10 * 1 = 10 10 * 2 = 20 10 * 3 = 30 10 * 4 = 40 10 * 5 = 50 10 * 6 = 60 10 * 7 = 70 10 * 8 = 80 10 * 9 = 90 10 * 10 = 100
16. Find First Digit in a Number.
Program
#include<stdio.h> int main() { int number, first_digit; printf("Enter Any Integer Number : "); scanf("%d", &number); first_digit = number; while(first_digit >= 10) { first_digit = first_digit / 10; } printf("First Digit in a Number : %d", first_digit); return 0; }
Output
Enter Any Integer Number : 875 First Digit in a Number : 8
17. Calculate Sum of Digits in a Number.
Program
#include<stdio.h> int main() { int number, sum=0; printf("Enter any Integer Number to find Sum of its Digit : "); scanf("%d", &number); while(number!=0) { sum += number % 10; number = number / 10; } printf("Sum of Digits : %d", sum); return 0; }
Output
Enter any Integer Number to find Sum of its Digit : 896 Sum of Digits : 23
18. Print ASCII value of the Special Characters.
Program
#include<stdio.h> int main() { int specialCh; printf("ASCII value of Special Characters are : \n"); for (specialCh = 33; specialCh < 48; specialCh++) { printf ("The ASCII value of '%c' special character is %d\n", specialCh, specialCh); } for (specialCh = 58; specialCh < 65; specialCh++) { printf ("The ASCII value of '%c' special character is %d\n", specialCh, specialCh); } for (specialCh = 123; specialCh < 127; specialCh++) { printf ("The ASCII value of '%c' special character is %d\n", specialCh, specialCh); } return 0; }
Output
The ASCII value of '!' special character is 33 The ASCII value of '"' special character is 34 The ASCII value of '#' special character is 35 The ASCII value of ' special character is 36 The ASCII value of '%' special character is 37 The ASCII value of '&' special character is 38 The ASCII value of ''' special character is 39 The ASCII value of '(' special character is 40 The ASCII value of ')' special character is 41 The ASCII value of '*' special character is 42 The ASCII value of '+' special character is 43 The ASCII value of ',' special character is 44 The ASCII value of '-' special character is 45 The ASCII value of '.' special character is 46 The ASCII value of '/' special character is 47 The ASCII value of ':' special character is 58 The ASCII value of ';' special character is 59 The ASCII value of '<' special character is 60 The ASCII value of '=' special character is 61 The ASCII value of '>' special character is 62 The ASCII value of '?' special character is 63 The ASCII value of '@' special character is 64 The ASCII value of '{' special character is 123 The ASCII value of '|' special character is 124 The ASCII value of '}' special character is 125 The ASCII value of '~' special character is 126
19. Print Fibonacci Series.
Fibonacci Number: Fibonacci series, next number is the sum of previous two numbers.
Program
#include<stdio.h> int main() { int n1=0,n2=1,n3,i,number; printf("Enter the number of elements : "); scanf("%d",&number); printf("%d %d",n1,n2); for(i=2; i< number; ++i) { n3=n1+n2; printf(" %d",n3); n1=n2; n2=n3; } return 0; }
Output
Enter the number of elements : 20 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
20. Check whether Number is Perfect Number or Not.
Perfect Number: A perfect number is a number that is equal to the sum of its proper divisors.
Program
#include<stdio.h> int main() { int i, number, sum = 0 ; printf("Enter Any Integer Number : ") ; scanf("%d", &number) ; for(i=1; i<number; i++) { if(number % i == 0) sum = sum + i ; } if (sum == number) printf("%d is a Perfect Number", number) ; else printf("%d is not the Perfect Number", number) ; return 0 ; }
Output
Enter Any Integer Number : 0 0 is a Perfect Number
21. Check whether Number is Prime Number or Not.
Prime Number: Prime number is a number that is greater than 1 and divided by 1 or itself. In other words, prime numbers can’t be divided by other numbers than itself or 1. Zero (0) and 1 are not considered as prime numbers. Two (2) is the only one even prime number because all the numbers can be divided by 2.
Program
#include<stdio.h> int main() { int n,i,m=0,flag=0; printf("Enter Any Integer Number : "); scanf("%d",&n); m=n/2; for(i=2;i<=m;i++) { if(n%i==0) { printf("Number is not Prime"); flag=1; break; } } if(flag==0) printf("Number is Prime"); return 0; }
Output
Enter Any Integer Number : 3 Number is Prime
Note:
- All the programs are compiled and executed in Dev C++ code editor and save with .c extension.
- %.2f is used to print fractional values only up to 2 decimal places. You can also use %f to print fractional values normally up to six decimal places.
More Topics
- C Programming Viva Question Answer
- Basic C Programming Example Program
- C Programming Difference List
- C Programming If-else Programs
- Conversion of Decimal Number to Other Base Number
To Download C Programming Basic Program Examples, Click Here and If-else Click Here.