码迷,mamicode.com
首页 > 编程语言 > 详细

C语言学习记录之二

时间:2016-10-27 01:13:55      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:stdio.h   strong   多层嵌套   注释   输出   成绩   src   笔记   model   

各种语句及编程笔记记录

1.if & else

#include<stdio.h>

int main(){

    int

if (situation)

{

        //model;

}

else

 {

        //mode2;

}

prinf("?\n")

    return 0;

}


 2.if & else(a>60)

#include<stdio.h>

int main()

{

    int a=100;

if (a > 60)

{

        printf("a\n");

}

else

 {

        printf("b\n");

    }

    return 0;

}

 技术分享

 技术分享    技术分享


3.hello world

#include <stdlib.h>

int main()

{

    printf("Hello world!\n");

    return 0;

}

技术分享

技术分享


4.if&else 嵌套char c

#include<stdio.h>

int main()

{

    int a=100;

    char c;

if (a >= 60)

{

        c = ‘a‘;

}

else

 {

        c = ‘d‘;

    }

    printf("%c\n", c);

    return 0;

}

技术分享

技术分享    技术分享


5.多层if

#include<stdio.h>

int main()

{

    int a=100;

    char c;

if (a >= 90)

{

        c = ‘a‘;

    }

if (a >= 80 && a < 90)

{

        c = ‘b‘;

    }

if (a >= 60 && a < 80)

{

        c = ‘c‘;

    }

if (a >= 0 && a < 60)

{

        c = ‘d‘;

    }

    printf("%c\n", c);

    return 0;

}

技术分享

技术分享    技术分享


6.if&else多层嵌套

#include<stdio.h>

int main()

{

    int mark = 100;

    char grade;

if (mark >= 90)

{

        grade = ‘a‘;

    }

else

 {

        if (mark >= 70)

        {

            grade = ‘b‘;

        }

         else

         {

            if (mark >= 60){

                grade = ‘c‘;

            }

            else

            {

                grade = ‘d‘;

            }

        }

    }

    printf("%c\n", grade);

    return 0;

}


7.区分等级abcd

#include<stdio.h>

int main()

{

    int a=100;

    char c;

    if (a >= 90)

    {

        c = ‘a‘;

    }

    else if (a >= 80 && a < 90)

    {

        c = ‘b‘;

    }

    else if (a >= 60 && a < 80)

    {

        c = ‘c‘;

    }

    else

    {

        c = ‘d‘;

    }

    printf ("%c\n", c);

    return 0;

}

技术分享

技术分享    技术分享


8.1+2+3+4+…+99+100=5050

 #include<stdio.h>

int main(){

    int i, s;

    s = 0;

    for (i = 1; i <= 100; i++)

    {

        s = s + i;

    }

    printf("%d\n", s);

    return 0;

}

技术分享

技术分享


9.1*2*3*…*9*10=3628800

#include<stdio.h>

int main()

{

    int i, s;

    s = 1;

    for (i = 1; i <= 10; i++)

    {

        s = s * i;

 

    }

    printf("%d\n", s);

    return 0;

}

技术分享

技术分享


10.1+2+3+...+n

#include<stdio.h>

int main()

{

    int i, s, n;

    scanf("%d", &n);

    s = 0;

    for (i = 1; i <= n; i++)

    {

        s = s + i;

 

    }

    printf("%d\n", s);

    return 0;

}

技术分享   技术分享

技术分享技术分享


11.用户输入十个同学的成绩

全部转化为abcd四个等级

#include<stdio.h>

int main()

{

    int i, n;

    for (i = 0; i <= 10; i++)

    {

        scanf("%d", &n);

        if(n >= 90)

        {

            printf("A\n");

            }else

            {

                if(n >= 75)

                {

                    printf("B\n");

                    }else

                    {

                        if(n >= 60)

                        {

                            printf("C\n");

                            }else

                            {

                                printf("D\n");

                            }

                    }

            }

    }

     return 0;

}

 技术分享   技术分享


12.标注

Int  main(){} 运行主体

scanf(“”,&); 输入

printf(“?\n”); 输出

int a    //“%d\n, a”   整数型

float b  //“%f\n, b”   浮点型

char c  //“%c\n, c”    字符

// 注释

\n 回收符

#include<stdio.h>

C语言学习记录之二

标签:stdio.h   strong   多层嵌套   注释   输出   成绩   src   笔记   model   

原文地址:http://www.cnblogs.com/moddy13162201/p/6002341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!