BACK TO 10+2 STEM LAB
10+2 MATHEMATICS & DRAWINGS•2016-08-11•3 MIN READ

Program using While Loop

Unlike most of the computer programming languages, a **while loop** is a control flow statement that allows code to be executed repeatedly based on a given boolean condition in C or C++. The **whil...

Key Architecture Takeaways

  • ›
    Point 1: Core computer science and engineering computing concept: Program using While Loop.
  • ›
    Point 2: Detailed trace of memory representation, algorithmic complexity, and control structures.
  • ›
    Point 3: Includes portable ISO C (C17/C23) code examples verified with modern GCC and Clang.
Notice

Compiler & Toolchain Modernization

While legacy educational environments used 16-bit DOSBox Turbo C++, all code presented here adheres to standard ANSI/ISO C standards. You can compile these programs cleanly on modern Linux, Windows (MSYS2/WSL), or macOS using:

bash
> gcc -Wall -Wextra -O2 program.c -o program
> ./program
> ```


---

Unlike most of the computer programming languages, a **while loop** is a control flow statement that allows code to be executed repeatedly based on a given boolean condition in C or C++. The **while loop** can be thought of as a repeating if statement. Here is some program using **while Loop:**

 	
- 

## **C Program to return reverse of a three digit number:**

Assume that you have input a number 123 to computer and computer return it to 321. we know that if a number divided by 10 then its reminder is always the last digit of inputted number. (123%10 =3, 12%10=2)

c #include<stdio.h> void main() { int number,reverse=0,reminder; clrscr(); printf("Enter any three digits value: "); scanf("%d",&number); while(number>0) { reminder=number%10; reverse=(reverse*10)+reminder; number=number/10; } printf("Reverse value is %d",reverse);

}

SHELL
Output:

[![reverse](http://technhit.in/wp-content/uploads/2016/08/reverse.jpg)](http://technhit.in/wp-content/uploads/2016/08/reverse.jpg)

 

 	
- 

## **C Program to find Armstrong number between a range :**

An **Armstrong number **is the  sum of the cubes of its digits and  is equal to the **number** itself. For example, 371 is an **Armstrong number **since 3**3 + 7**3 + 1**3 = 371.

c #include<stdio.h> void main() { int i=0,number, reminder, armstrong=0,term; clrscr(); printf("Enter term to search Armstrong:"); scanf("%d", &term); while(i<=term) { number=i; while(number>0) { reminder=number%10; armstrong =armstrong +(reminderreminderreminder); number=number/10; } if(armstrong ==i) printf("Armstrong No is %d",i)

i++; } }

SHELL
Output:

[![armstrong](http://technhit.in/wp-content/uploads/2016/08/armstrong.jpg)](http://technhit.in/wp-content/uploads/2016/08/armstrong.jpg)

 	
- 

## C Program to check a given number whether palindrome or not.

A **palindrome** is a word, phrase, [number](https://en.wikipedia.org/wiki/Palindromic_number), or other sequences of [characters](https://en.wikipedia.org/wiki/Character_(symbol)) which read the same backwards or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers. Examples in English include "A man, a plan, a canal, Panama!", "Amor, Roma", "race car", "stack cats", "step on no pets", "taco cat", "put it up", "Was it a car or a cat I saw?" and "No 'x' in Nixon" ,"121" etc.

In case of number we use reverse method:

c #include<stdio.h> void main() { int num,value,reminder,tmp; printf("Enter any number to check palindrome"); scanf("%d",&num); tmp=num; while(tmp>0) { reminder=tmp%10; value=value*10+reminder; tmp=tmp/10;

} if (num==value) { printf("Entered Number %d is a palidrome number",num); } else { printf("Entered Number %d is not apalindrome number",num); } }

SHELL
In case of String we use string function substr()

c #include<stdio.h> #include<string.h> void main() { char word[100],rev[100]; clrscr(); printf("Enter any word: "); scanf("%s", &word); strcpy(rev,word); if (strcmp(word,strrev(rev))==0) { printf("The word is palindrome"); } else { printf("The word is not a palindrome"); } getch();

} ```

palindrompalindrom

π
TechNHIT STEM Faculty
Department of Applied Mathematics & Physics
Program using While Loop | TechNHIT 10+2 STEM Lab | TechNHIT