Find the value of S=A+AA+AAA+AAAA+AA...A (where A is a number)

Source: Internet
Author: User
Tags count include printf

See the full set of "C language problem sets"

Topic:

Find the value of S=A+AA+AAA+AAAA+AA...A, where a is a number. For example 2+22+222+2222+22222 (there are 5 numbers added at this time), several numbers are added with keyboard control.

1. Procedure analysis: The key is to calculate the value of each item.

2. Program Source code:

#include "stdio.h"
#include "conio.h"
Main ()
{
int a,n,count=1;
long int sn=0,tn=0;
printf ("Please input A and n\n");
scanf ("%d,%d", &a,&n);
printf ("a=%d,n=%d\n", a,n);
while (count<=n)
{
Tn=tn+a;
Sn=sn+tn;
a=a*10;
++count;
}
printf ("a+aa+...=%ld\n", SN);
Getch ();
}

3.Visual C + + 6.0 debugging pass, as shown in figure:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.