7-2 分苹果 - C/C++ 语法基础

现有n个苹果,均分给5位同学,剩下的苹果交还老师。请编写程序,解决下述问题:

  • 每位同学能分得几个苹果?

  • 一共分出去多少个苹果?

  • 交还老师的苹果有几个?

输入样例:

17

输出样例:

Everyone have 3 apples.

15 apples have been taken in total.

returned 2 apples to the teacher.

#include
int main()
{
    int n,a,b,c;
    scanf("%d",&n);
    a=n/5;
    b=5*a;
    c=n-b;
    printf("Everyone have %d apples.\n%d apples have been taken in total.\nreturned %d apples to the teacher.",a,b,c);
    return 0;
}

总结:很基础的一道题目,没有什么难度,不会的可以留言哦!

你可能感兴趣的:(pta,c#,c语言)