Translate

Total Pageviews

Friday, May 15, 2020

FOR LOOP BASIC PROBLEM

PRACTICE QUESTIONS ON "FOR LOOP"

sum is bill paid by all 10 patients
s1 is total amount of first 10 patients
s2 is total amount credited to his account

#include<stdio.h>
int main()
{
    int sum=0,s1=0,s2=0,a[20],i;
    for(i=0;i<20;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<20;i++)
    {
        sum = sum + a[i];
    }
    for(i=0;i<10;i++)
    {
        s1 = s1 + a[i];
    }
    s2= sum - s1;
    printf("%d\n %d\n %d\n",sum ,s1 , s2 );
    return 0;
}





OUTPUT

4 5 6 7 8 9 1 2 1 3 4 5 8 6 9 8 7 7 8 4 1  1 5 
112
 46
 66






No comments:

Post a Comment