178 Programming and Data Structures
Explanation The above program is an example of nested whi le loops._When the entered number is
even the first loop (B loop) is executed and a number is added to variable ' even' , otherwise the
whileloop (C loop) is executed and the same job of addition is done with variable 'odd' . Thus,
variables 'odd' and 'even' gives the sum of even and odd numbers.
6,64 Write a program to print the entered number in reverse order.
mainQ
{
int n,d,xsl;
int i;
clrscrO;
printf("Enter the number of digits
scanf ("%d",&cd);
printf("
Enter the number which is to be rev ersed ");
scanf("%d",&n);
printf ("nThe Reversed Number i s ");
while (x<=d)
I
i=«%10;
printf("%d",i);
n=n/10;
x++;
}
getcheO;
I
QUIPIUT;
Enter the number of digits4
Enter the number which is to be reversed:- 5428
The Reversed Number is :- 8245
Explanation The statements following thewhile loop are i=n%10 andn=n/10. They provide remainder
and quotient values respectively. By taking repeatedly remainders & quotients we get the number in
the reverse order. For repeating the loop the ' x ' is to be increased.
6.65 Write a program to enter a statement entering a combination of capital, small, symbols and
numerical. Carry out separation of capitals, small, symbols and numerical by using ASCII values
from 48 to 122.
# include <conio.h>
# include <stdio.h>
# include <ctype.h>
void mainO
{
s ta tic char scan [40], cap [20], small [2 0 ],num[20] ,oth[20];
in t i=0,c=0,s=0,h=0,n=0;
c lrs c rO ;
putsC'Enter Text Here :
");
gets(scan);