Sequence of statements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jvzj017
    New Member
    • Oct 2006
    • 10

    Sequence of statements

    Given that two int variables, total and amount , have been declared, write a sequence of statements that:
    initializes total to 0
    reads three values into amount , one at a time.

    After each value is read in to amount , it is added to the value in total (that is, total is incremented by the value in amount ).
  • koder
    New Member
    • Sep 2006
    • 23

    #2
    Hi,
    is the below code answer your queries?

    Code:
    #include<stdio.h>
    
    main()
    {
    
        int total=0,i,amount=0;
         for(i=1;i<=3;i++)
            {
              printf("\nenter amount" );
              scanf("%d",&amount);
              total=total+amount;
            }
        printf("\ntottal= %d",total);
        }
    ~

    Comment

    Working...