1.Write a program to accept number from user and print all digits in number seperatly
Input : 213
Output :
2
1
3
#include<stdio.h>
void Display(int);
int main()
{
int iValue = 0;
printf("Enter Number :");
scanf("%d",&iValue);
Display(iValue);
return 0;
}
void Display(int iNo)
{
int iDigit = 0;
while(iNo != 0)
{
iDigit = iNo % 10;
printf("%d\n",iDigit);
iNo = iNo / 10;
}
}
-----------------------------------------------------------------------------------------------------------------------------
2.Write a program to accept number from user and print addition of all digits.
Input : 213
Output : 6 (i.e. 2+1+3)
#include<stdio.h>
int Display(int);
int main()
{
int iValue = 0;
int bRet = 0;
printf("Enter Number :");
scanf("%d",&iValue);
bRet = Display(iValue);
printf("Addition of digits is %d",bRet);
return 0;
}
int Display(int iNo)
{
int iDigit = 0;
int iSum = 0;
if(iNo<0)
{
iNo = -iNo;
}
while(iNo != 0)
{
iDigit = iNo % 10;
iSum = iSum + iDigit;
iNo = iNo / 10; //752
}
return iSum;
}
-----------------------------------------------------------------------------------------------------------------------------
3.Write a program which accept number from user and print count of all digits.
Input : 213
Output : 3
Note : Use filter and updater also
#include<stdio.h>
int CountDigit(int);
int main()
{
int iValue = 0;
int bRet = 0;
printf("Enter Number :");
scanf("%d",&iValue);
bRet = CountDigit(iValue);
printf("Count of digits is %d",bRet);
return 0;
}
int CountDigit(int iNo)
{
int iCnt = 0;
if(iNo == 0) //filter
{
return 1;
}
if(iNo < 0) //updater
{
iNo = -iNo;
}
while(iNo != 0)
{
iCnt++;
iNo = iNo / 10; //752
}
return iCnt;
}
-----------------------------------------------------------------------------------------------------------------------------
4.Accept number from user and check whether digit is even or not and if it is even then return count of even numbers.
#include<stdio.h>
int CountEven(int);
int main()
{
int iValue = 0;
int bRet = 0;
printf("Enter Number :");
scanf("%d",&iValue);
bRet = CountEven(iValue);
printf("Count of digits is %d",bRet);
return 0;
}
int CountEven(int iNo)
{
int iCnt = 0;
int iDigit =0;
if(iNo == 0) //filter
{
return 1;
}
if(iNo < 0) //updater
{
iNo = -iNo;
}
while(iNo > 0)
{
iDigit = iNo%10;
if((iDigit%2)==0)
{
iCnt++;
}
iNo = iNo / 10; //752
}
return iCnt;
}
-----------------------------------------------------------------------------------------------------------------------------
5.Accept number from user and return sum of even digits
for ex :
Input: 2345
Output : 6 (2+4)
#include<stdio.h>
int SumEven(int);
int main()
{
int iValue = 0;
int bRet = 0;
printf("Enter Number :");
scanf("%d",&iValue);
bRet = SumEven(iValue);
printf("Sum of even digits are %d",bRet);
return 0;
}
int SumEven(int iNo)
{
int iDigit =0;
int iSum = 0;
if(iNo < 0) //updater
{
iNo = -iNo;
}
while(iNo > 0)
{
iDigit = iNo%10;
if((iDigit%2)==0)
{
iSum = iSum + iDigit;
}
iNo = iNo / 10; //752
}
return iSum;
}
-----------------------------------------------------------------------------------------------------------------------------
6.Accept number from user and return reverse number and print that number.
Input : 2345
Output : 5432
#include<stdio.h>
int Reverse(int);
int main()
{
int iNo = 0;
int iRet = 0;
printf("Enter Number :");
scanf("%d",&iNo);
iRet= Reverse(iNo);
printf("Reverse Number is : %d",iRet);
return 0;
}
int Reverse(int iValue)
{
int iDigit = 0;
int iRev = 0;
if(iValue < 0)
{
iValue = -iValue;
}
while(iValue>0)
{
iDigit=iValue%10;
iRev = (iRev * 10) + iDigit;
iValue = iValue/10;
}
return iRev;
}
-----------------------------------------------------------------------------------------------------------------------------
7.Accept number from user and check whether number is palindrome or not.
Input : 212
Output : True
Input : 234
Output : False
#include<stdio.h>
#include<stdbool.h>
bool CheckPallindrome(int);
int main()
{
int iNo = 0;
bool bRet = false;
printf("Enter Number :");
scanf("%d",&iNo);
bRet= CheckPallindrome(iNo);
if(bRet==true)
{
printf("Number is pallindrome\n");
}
else
{
printf("Number is not pallindrome\n");
}
return 0;
}
bool CheckPallindrome(int iValue)
{
int iDigit = 0;
int iRev = 0;
int iXerox = iValue;
while(iValue!=0)
{
iDigit=iValue%10;
iRev = (iRev * 10) + iDigit;
iValue = iValue/10;
}
if(iRev==iXerox)
{
return true;
}
else
{
return false;
}
}
-----------------------------------------------------------------------------------------------------------------------------
8.Write a program which accept number from user and check whether it contains 0 in it or not.
Input : 2395
Output : There is no Zero
Input : 1018
Output : It Contains Zero
#include<stdio.h>
#include<stdbool.h>
bool CheckZero(int);
int main()
{
int iNo = 0;
bool bRet = 0;
printf("Enter Number : ");
scanf("%d",&iNo);
bRet = CheckZero(iNo);
if(bRet == true)
{
printf("It contains zero value\n");
}
else
{
printf("It contains non zero value\n");
}
return 0;
}
bool CheckZero(int iValue)
{
int iDigit = 0;
int iCheck = 0;
while(iValue !=0)
{
iDigit = iValue%10;
if(iDigit == 0)
{
return true;
iCheck=1;
}
iValue = iValue/10;
}
if(iCheck == 0)
{
return false;
}
}
-----------------------------------------------------------------------------------------------------------------------------
9.write a program which accept number from user and count frequency of 2 in it.
Input : 214242
Output : 3
#include<stdio.h>
#include<stdbool.h>
int Frequency(int);
int main()
{
int iNo = 0;
int iRet = 0;
printf("Enter Number : ");
scanf("%d",&iNo);
iRet = Frequency(iNo);
printf("%d",iRet);
return 0;
}
int Frequency(int iValue)
{
int iDigit = 0;
int iCnt = 0;
while(iValue != 0)
{
iDigit = iValue%10;
if(iDigit == 2)
{
iCnt++;
}
iValue=iValue/10;
}
return iCnt;
}
-----------------------------------------------------------------------------------------------------------------------------
10.Write a program which accept number from user and return the count of odd digits.
Input : 2395
Output : 3
Input : 1018
Output : 2
Input : -1018
Output : 2
Input : 8462
Output : 0
#include<stdio.h>
int OddCount(int);
int main()
{
int iNo = 0;
int iRet = 0;
printf("Enter Number : ");
scanf("%d",&iNo);
iRet = OddCount(iNo);
printf("Odd digits are : %d",iRet)
return 0;
}
int OddCount(int iValue)
{
int iDigit =0;
int iCnt = 0;
if(iValue <0)
{
iValue= -iValue; //Updater
}
while(iValue != 0)
{
iDigit = iValue%10;
if((iDigit%2)!=0)
{
iCnt++;
}
iValue=iValue/10;
}
return iCnt;
}
-----------------------------------------------------------------------------------------------------------------------------
11.Write a program which accept accept range from user and display all numbers in between that range in reverse order.
Input : 23 35
Output : 35 34 33 32 31 30 29 28 27 26 25 24 23
Input : 10 18
Output : 18 17 16 15 14 13 12 11 10
Input : 10 10
Output : 10
Input : -10 2
Output : 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
Input : 90 18
Output : Invalid range
#include<stdio.h>
void ReverseRange(int, int);
int main()
{
int iNo1=0;
int iNo2=0;
printf("Enter Number : ");
scanf("%d",&iNo1);
printf("Enter Number : ");
scanf("%d",&iNo2);
ReverseRange(iNo1,iNo2);
return 0;
}
void ReverseRange(int iValue1, int iValue2)
{
int iCnt=0;
for(iCnt=iValue2;iCnt>=iValue1;iCnt--)
{
printf("%d\t",iCnt);
}
}
-----------------------------------------------------------------------------------------------------------------------------
Some problem statements for you : Try by your self :
1.Accept number from user and return reverse number with operator of that number also and print that number.
Input : 234
Output : 432
Input : -1018
Output : -8101
-----------------------------------------------------------------------------------------------------------------------------
2.Write a program which accept number from user and count frequency of 4 in it.
Input : 234
Output : 1
-----------------------------------------------------------------------------------------------------------------------------
3.Write a program which accept number from user and count frequency of such a digits which are less than 6.
Input : 2567
Output :2
-----------------------------------------------------------------------------------------------------------------------------
4.Write a program which accept number from user and return the count of even digits.
Input : 234567
Output : 4
Input : 2395
Output : 1
Input : 1018
Output : 2
Input : -1018
Output : 2
Input : 8462
Output : 4
--------------------------------------------------------------------------------------------------------------------------
5.Write a program which accept number from user and return the count of digits in between 3 and 7.
Input : 2395
Output : 1
-----------------------------------------------------------------------------------------------------------------------------
6.Write a program which accept number from user and return multiplication of all digits.
Name : Aniket Kanse
Topic : Digit Program
Input : 2395
Output : 1
---------------------------------------------------------------------------------------------------------------
7.Write a program which accept number from user and return difference between summation of even digits and summation of odd digits.
Input : 2395
Output : -15 (2-17)
---------------------------------------------------------------------------------------------------------------
Try to solve all the problems by your self and don't search on google because you are future developer.
Before solving problems read all basics.
Thanking You,
AniStudios.