//program to print/display ...11111,1111,111,11,1 to nth term.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m=1,n,number,denom;
printf("enter value of 'n' as a number of terms \n");
scanf("%d",&n);
printf("now enter number having %d digits(1)\n",n)
scanf("%d",&number);while(n>=m)
{
printf("%d\n",number);
denom=pow(10,n-1);
number=number/denom;
n--;
}
getch();
}
..................................
logics in mind:
if n= 6(It means a number with 6 ones i.e. 111111)
111111,11111,1111,111,...
can be shown as
first 11111
second dividing above number by 10th power of entered number -1
as the second iteration goes , it has value with 1 less digit.
it continues until the value lasts to 1.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m=1,n,number,denom;
printf("enter value of 'n' as a number of terms \n");
scanf("%d",&n);
printf("now enter number having %d digits(1)\n",n)
scanf("%d",&number);while(n>=m)
{
printf("%d\n",number);
denom=pow(10,n-1);
number=number/denom;
n--;
}
getch();
}
..................................
logics in mind:
if n= 6(It means a number with 6 ones i.e. 111111)
111111,11111,1111,111,...
can be shown as
first 11111
second dividing above number by 10th power of entered number -1
as the second iteration goes , it has value with 1 less digit.
it continues until the value lasts to 1.