import java.util.Arrays;
// 注意:数组的下标和长度之间的相差1的,所以i<arr.length-1,即
// arr.length-1才是数组的最后一个元素
public class Switch {
public static void main(String[] args) {
int[] arr = {1,2,3,4,5,6,7,8,9,10};
int temp = arr[0];
for(int i=0;i<arr.length-1;i++){
arr[i] = arr[i+1];
}
arr[arr.length-1] = temp;
System.out.println(Arrays.toString(arr));
}
}
//写一个函数完成下列任务,输入一个表示正整数的字符串,将字符串转换成对应的数字。
//例如,输入3个字符组成的字符参“123”,将它转换成整型数123
#include <stdio.h>
int cton(){
char ch;
int n=0,f=0,n1=0;
while((ch =
getchar())<='0'||ch>='9'){
n1++;
//用n1计数,输入的非数字字符不能超过10个
if(n1>=10){
printf('data is wrong!');
return
0;
}
}
do{
编写最小公倍数的程序。
分析:正整数a、b的最小公倍数和最大公约数之间有关系,设正整数a、b的最大公约数为d,最小公倍数为c,则c=(a*b)/d。(存在调用)
编写求最大公约数的函数,函数原型为: int divisor(int a,int
b) 返回最大公约数。
编写求最小公倍数的函数,函数原型为: int multiple(int a,int
b) 返回最小公倍数。
#include <stdio.h>
int divisor(int a,int b){ //求最大公约数,使用辗转相除法
int r;
while((r=a%b)!=0){
a = b;
b = r;
}
return b;
}
int multiple(int a,int b){ //求最小公倍数
int d;
今天又重新复习里一下C语言,编写了几个程序,发现很基础的几个知识点还有点模糊,于是贴上来,和大家分享,交流探讨一下
#include <stdio.h>
void main(){
// int a=1,b=2,c=3;
//
printf('%d,%d,%d,%d,%d\n',a=b,a=b=c,a=b==c,a==(b=c),a==(b==c));
int a=1,b=2,c=3;
printf('%d,%d,%d\n',a=b,a=b=c,a=b==c);//结果为:3,3,3,最百思不得其解的是a=b==c,知道==比赋值
的 优先级高,但结果也不能是这个样的啊??
// int a=1,b=2,c=3;
//
printf('%d,%d\n',a=b,a=b==c);//结果为:2,2,这个结果也够费解的哈,但还是a=b==c的问题
int a=10,b=20,c=30,d;
d = ++a<=10||b-->=20||c++;
printf('%d,%d,%d,%d\n',a,b,c,d);//结果为:11,19,30,1
b为什么是19??
}