Thread: Help With Simple Summation...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    3
    Hi,
    If you want to take each number into separate variable, you can go with this.

    main()
    {
    int i,j,k,l,m;
    scanf("%1d%1d%1d%1d%1d",&i,&j,&k,&l,&m);

    printf("%d",i+j+k+l+m);
    }

    give input as 12345
    now it each digit is taken into new variable .
    and the result would be the sum of all five vars(15 here).
    If you give more than 5 digits, it will ignore remaining digits.

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    3
    Quote Originally Posted by venu
    Hi,
    If you want to take each number into separate variable, you can go with this.

    main()
    {
    int i,j,k,l,m;
    scanf("%1d%1d%1d%1d%1d",&i,&j,&k,&l,&m);

    printf("%d",i+j+k+l+m);
    }

    give input as 12345
    now it each digit is taken into new variable .
    and the result would be the sum of all five vars(15 here).
    If you give more than 5 digits, it will ignore remaining digits.
    If you give only 3 digits, then it will ask user for two more digits. It will calculate summation for first five digits entered.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    How do i missed point?

    Quzah was saying that it is better to provide a decent solution rather than focusing on minutae based on how the exercise was worded. That is, with a good solution we should be able to find the sum of other numbers not in the tens of thousands.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM