### Sum of Digit & Reverse of a Number - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
int r=0,n,sum=0,d;
printf("Enter the number:");
scanf("%d",&n);
while(n>0)
{
d=n%10;
sum=sum+d;
r=(r*10)+d;
n=n/10;
}
printf("\n sum of digits= %d",sum);
printf("\n Reverse=%d",r);
printf("\n");
//getch();
}

Output:
nn@linuxmint ~ \$ gcc c24.c
nn@linuxmint ~ \$ ./a.out
Enter the number:15

sum of digits= 6
Reverse=51
nn@linuxmint ~ \$

### Convert Digit to Words - C Program

Program:
#include<stdio.h>
#include<string.h>
//#include<conio.h>

void main()
{
int b,c,d,i=0,j,k,r;char a[100];int x[100];
//    clrscr();
printf("Enter the number:");
scanf("%s",a);
c=strlen(a);
b=atoi(a);
//printf("no.=%d\n",b);
while(b!=0)
{
r=b%10;
x[i]=r;
i++;
b=b/10;
}
if(c!=i)
{
d=c-i;
for(k=0;k<d;k++)
printf("Zero");
}
for(j=i-1;j>=0;j--)
{
switch(x[j])
{
case 0: printf("Zero");
break;
case 1: printf("One");
break;
case 2: printf("Two");
break;
case 3: printf("Three");
break;
case 4: printf("Four");
break;
case 5: printf("Five");
break;
case 6: printf("Six");
break;
case 7: printf("Seven");
break;
case 8: printf("Eight");
break;
case 9: printf("Nine");
break;
}
}
printf("\n");
//getch();
}

Output:
nn@linuxmint ~ \$ gcc c23.c
nn@linuxmint ~ \$ ./a.out
Enter the number:101
OneZeroOne
nn@linuxmint ~ \$

### Seperate Odd & Even Numbers - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
int i,n,a[100],o[100],e[100],on=0,en=0;//clrscr();
printf("Enter number of elements:");
scanf("%d",&n);
printf("Enter numbers into array:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if(a[i]==0)
continue;
if(a[i]%2==1)
{
o[on]=a[i];
on++;
}
else
{
e[en]=a[i];
en++;
}
}
printf("\nOdd numbers:\n");
for(i=0;i<on;i++)
printf("%d\t ",o[i]);
//printf("%d %d",on, en);
printf("\nEven numbers:\n");
for(i=0;i<en;i++)
printf("%d\t",e[i]);
printf("\n");
//    getch();
}

Output:
nn@linuxmint ~ \$ gcc c14.c
nn@linuxmint ~ \$ ./a.out
Enter number of elements:5
Enter numbers into array:5
4
3
2
0

Odd numbers:
5     3
Even numbers:
4    2
nn@linuxmint ~ \$

### Factorial of a Number - Non recursive -c program

Program:

(gcc)

#include<stdio.h>
main ()
{
int i,n,fact=1;
printf("Enter the number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact = fact*i;
}
printf("Factorial=%d\n",fact);

}

Output:
nn@linuxmint ~ \$ gcc c1.c
nn@linuxmint ~ \$ ./a.out
Enter the number: 5
Factorial=120
nn@linuxmint ~ \$

(Turboc)

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,f=1;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
if(n<0)
printf("sorry.......");
else if(n<=1)
printf("Factorial =1.");
else
{
for(i=1;i<=n;i++)
{
f*=i;
}
printf("Factorial=%d",f);
}
getch();
}