我是靠谱客的博主 健壮白昼,这篇文章主要介绍PTA《C语言程序设计实验与习题指导(第3版)》题目集 实验5-6 使用函数判断完全平方数 (10 分),现在分享给大家,希望可以做个参考。

本题要求实现一个判断整数是否为完全平方数的简单函数

本题要求实现一个判断整数是否为完全平方数的简单函数。

函数接口定义:

int IsSquare( int n );

裁判测试程序样例:

#include <stdio.h>
#include <math.h>

int IsSquare( int n );

int main()
{
    int n;

    scanf("%d", &n);
    if ( IsSquare(n) ) printf("YESn");
    else printf("NOn");

    return 0;
}

/* 你的代码将被嵌在这里 */

输入样例1:

90

输出样例1:

NO
输入样例2:

100

输出样例2:

YES

#include <stdio.h>
#include <math.h>

int IsSquare( int n );

int main()
{
    int n;

    scanf("%d", &n);
    if ( IsSquare(n) ) printf("YESn");
    else printf("NOn");

    return 0;
}

int IsSquare(int n)
{
    int i;
    i = sqrt(n);
    if(i*i==n)
    return 1;
    else
    return 0;
}

最后

以上就是健壮白昼最近收集整理的关于PTA《C语言程序设计实验与习题指导(第3版)》题目集 实验5-6 使用函数判断完全平方数 (10 分)的全部内容,更多相关PTA《C语言程序设计实验与习题指导(第3版)》题目集内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部