adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C & C++ to remove given digit from given number.

Program in C & C++ to remove given digit from given number.

C PROGRAM
#include<stdio.h>
 int removeDigit(int n, int d){
 	int newN = 0, d1, base = 1;
 	while(n > 0){
 		d1 = n % 10;
 		if(d1 != d){
 		   newN = newN + base * d1;
		   base *= 10;	
		}
		n /= 10;
	 }
 	return newN; 	
 }
 int main(){
 	int n, d;
 	printf("Enter a number :- ");
 	scanf("%d", &n);
 	printf("Enter a digit which you want to remove from number :- ");
 	scanf("%d",&d);
 	n = removeDigit(n, d);
 	printf("\nNew number = %d", n);
 	return 0;
 }
C++ PROGRAM
#include<iostream>
 using namespace std;
 int removeDigit(int n, int d){
 	int newN = 0, d1, base = 1;
 	while(n > 0){
 		d1 = n % 10;
 		if(d1 != d){
 		   newN = newN + base * d1;
		   base *= 10;	
		}
		n /= 10;
	 }
 	return newN; 	
 }
 int main(){
 	int n, d;
 	cout<<"Enter a number :- ";
 	cin>>n;
 	cout<<"Enter a digit which you want to remove from number :- ";
 	cin>>d;
 	n = removeDigit(n, d);
 	cout<<"New number = "<<n;
 	return 0;
 }
Output :-














Related Programs
           Coming soon..............................

Post a Comment

0 Comments