Write a program to enter n number of digits. Form a number using these digits

Table of Contents

Program in C

#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
int number=0, digit[10], numofdigits,i;
clrscr();
printf("\n Enter the number of digits : ");
scanf("%d", &numofdigits);
for(i=0;i<numofdigits;i++)
{
printf("\n Enter the digit at position %d", i+1);

scanf("%d", &digit[i]);
}
i=0;
while(i<numofdigits)
{
number = number + digit[i] * pow(10,i);
i++;
}
printf("\n The number is : %d", number);
return 0;
}

Output

Enter the number of digits : 4
Enter the digit at position 1: 2
Enter the digit at position 2 : 3
Enter the digit at position 3 : 0
Enter the digit at position 4 : 9
The number is : 9032

Leave a Comment