Write c-code for 5+55+555+5555+55555+555555+5555555.
Output will be it's answer...

Answers were Sorted based on User's Feedback



Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer.....

Answer / vinod

main()
{
long int f=0,ans=0;
for(int i=0;i<7;i++)
{
f=f*10+5;
ans+=f;
}
printf("%ld",ans);
}

Is This Answer Correct ?    46 Yes 12 No

Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer.....

Answer / ashish

#include<stdio.h>
#include<math.h>
void main()
{ long int f=0,ans=0,i;
clrscr();
for(i=0;i<7;i++)
{
f=f*10+5;
ans+=f;
}
printf("%ld",ans);
getch();
}

Is This Answer Correct ?    19 Yes 8 No

Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer.....

Answer / arjun

The actual answer is 6172835.But integer range is only -32768
to 32767.so the actual answer cannot be displayed.

Is This Answer Correct ?    24 Yes 15 No

Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer.....

Answer / sunny

Hi Guys,

The answers above are correct but i was wondering if one has to add 5+55+555+.... till 'n'digits then??

Then the answer would be

#include<stdio.h>
#include<math.h>
void main()
{

long int res=0;
int n;
printf("The Maximum Digit(i.e. if youy want result upto 555 then enter '3'):");
scanf("%d",&n);

res= (5*pow(10,(n+1)) - 50 -(45*n))/81;
// VII standard maths
printf("%ld",res);
}


THANX

Is This Answer Correct ?    10 Yes 3 No

Post New Answer

More C Interview Questions

What is the function of multilevel pointer in c?

0 Answers  


Does free set pointer to null?

0 Answers  


Can I pass constant values to functions which accept structure arguments?

2 Answers  


String concatenation

2 Answers  


How to add two numbers without using semicolon n c????

3 Answers  






What are register variables? What are the advantage of using register variables?

0 Answers   TISL,


Badboy is defined who has ALL the following properties: Does not have a girlfriend and is not married. He is not more than 23 years old. The middle name should be "Singh" The last name should have more than 4 characters. The character 'a' should appear in the last name at least two times. The name of one of his brothers should be "Ram" Write a method: boolean isBadBoy(boolean hasGirlFriend , boolean isMarried, int age , String middleName , String lastName , String[] brotherName); isHaveGirlFriend is true if the person has a girlfriend isMarried is true if the person is married age is the age of the person middleName is the middle name of the person lastName is the last name of the person brotherName is the array of the names of his brothers

0 Answers  


What is sizeof int in c?

0 Answers  


What does c mean?

0 Answers  


what is the difference between %d and %*d in c languaga?

7 Answers   TCS,


What’s a signal? Explain what do I use signals for?

0 Answers  


Program to trim a given character from a string.

5 Answers   NetApp,


Categories