请完成函数cal()。,函数cal( )接受输入若干正整数,将个位为3的数的个数存入参数thr,个位为7且十位为8的数的个数存入参数sev,偶数的个数存入参数e。中间用空格隔开。例如,文件中有数据31 5 187 18,则thr=0,sev=1,e=1。
样例输入:31 5 187 18
样例输出:0 1 1
#include
using namespace std;
void cal(int &thr, int &sev, int &e);
void cal(int &thr, int &sev, int &e)
{
int x;
thr = sev = e = 0;
while(cin>>x)
{
/**********Program**********/
/********** End **********/
}
}
int main()
{ int thr, sev, e;
cout<" "<" "<;
return 0;
}
在while循环中,提取输入的数x的个位和十位,然后分三种逐一判断然后计数即可,补充如下:
参考链接:
c语言引用详解_落叶过河的博客-CSDN博客_c语言引用
C语言指针与引用(IT技术)
#include <iostream>
using namespace std;
void cal(int &thr, int &sev, int &e);
void cal(int &thr, int &sev, int &e)
{
int x;
thr = sev = e = 0;
while(cin>>x)
{
/**********Program**********/
int one = x%10;
int ten = x/10%10;
if(one==3){
thr++;
}
if(one==7&&ten==8){
sev++;
}
if(x%2==0){
e++;
}
/********** End **********/
}
}
int main()
{
int thr, sev, e;
cal(thr,sev,e);
cout<<thr<<" "<<sev<<" "<<e<<endl;
return 0;
}
void cal(int &thr, int &sev, int &e)
{
int x;
thr = sev = e = 0;
while(cin>>x)
{
if(x%10 == 3)
thr++;
if(x%100 == 87)
sev++;
if(x%2==0)
e++;
}