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
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 |
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 |
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 |
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 |
What are examples of structures?
What is the full form of getch?
What is the difference between a free-standing and a hosted environment?
Why is not a pointer null after calling free?
Why does this code crash?
Explain the difference between the local variable and global variable in c?
write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.
C program to find all possible outcomes of a dice?
which operator having highest precedence? a.)+ b.)++ c.)= d.)%
What is bubble sort technique in c?
How can I get the current date or time of day in a c program?
What are the advantages of using new operator as compared to the function malloc ()?