Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2529362
  • 博文数量: 308
  • 博客积分: 5547
  • 博客等级: 大校
  • 技术积分: 3782
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-24 09:47
个人简介

hello world.

文章分类

全部博文(308)

分类: C/C++

2010-07-25 21:43:03

    题目:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。
    其实这道题,也不是太难,有很多种解法,利用三目运算符,进行求解。代码如下:

#include <stdio.h>

int main(int argc,int *argv[])
{
    int score;
    char grade;
    printf("please into a score:");
    scanf("%d",&score);
    grade = score >= 90 ? 'A':(score >= 60 && score <= 89 ? 'B' :'C');
    printf("the grade is :%c\n",grade);
    system("pause");
    return 0;
}


阅读(1355) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~