当前位置:编程学习 > C/C++ >>

问题一百四十五:发工资咯:)

[plain]  #include <stdio.h> 
 
int main() 

    int i; 
    int num; 
    int a[100]; 
    int count; 
 
    while(scanf("%d", &num)!=EOF && num!=0) 
    { 
        count=0; 
        for(i=0; i<num; i++) 
        { 
            scanf("%d", &a[i]); 
        } 
 
        for(i=0; i<num; i++) 
        { 
              if(a[i]>=100) 
              { 
                  count+=a[i]/100; 
                  a[i]=a[i]%100; 
         
              } 
              if(a[i]>=50) 
              { 
                   count+=a[i]/50; 
                   a[i]=a[i]%50; 
              } 
              if(a[i]>=10) 
              { 
                    count+=a[i]/10; 
                   a[i]=a[i]%10; 
              } 
              if(a[i]>=5) 
              { 
                    count+=a[i]/5; 
                   a[i]=a[i]%5; 
              } 
              if(a[i]>=2) 
              { 
                    count+=a[i]/2; 
                   a[i]=a[i]%2; 
              } 
              
                count+=a[i]/1; 
             
        } 
        printf("%d\n", count); 
    } 
     
    return 0; 

#include <stdio.h>

int main()
{
 int i;
 int num;
 int a[100];
 int count;

 while(scanf("%d", &num)!=EOF && num!=0)
 {
  count=0;
     for(i=0; i<num; i++)
  {
   scanf("%d", &a[i]);
  }

  for(i=0; i<num; i++)
  {
        if(a[i]>=100)
     {
      count+=a[i]/100;
      a[i]=a[i]%100;
  
     }
     if(a[i]>=50)
     {
          count+=a[i]/50;
       a[i]=a[i]%50;
     }
     if(a[i]>=10)
     {
           count+=a[i]/10;
       a[i]=a[i]%10;
     }
     if(a[i]>=5)
     {
           count+=a[i]/5;
       a[i]=a[i]%5;
     }
     if(a[i]>=2)
     {
           count+=a[i]/2;
       a[i]=a[i]%2;
     }
   
       count+=a[i]/1;
   
  }
  printf("%d\n", count);
 }
 
 return 0;
}
 \

补充:软件开发 , C语言 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,