标签: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>
标签:stdio.h strong 多层嵌套 注释 输出 成绩 src 笔记 model
原文地址:http://www.cnblogs.com/moddy13162201/p/6002341.html