真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

C語言經(jīng)典題型(二)-創(chuàng)新互聯(lián)

文章目錄
  • 一、次方
    • 1.編寫一個(gè)函數(shù),實(shí)現(xiàn)n的k次方(考慮負(fù)數(shù))
  • 二、輸入一個(gè)非負(fù)整數(shù),返回組成它的數(shù)字之和
  • 三、交換完打印
    • 1. 迭代+temp法+數(shù)組
    • 2.用指針
    • 2.遞歸
  • 四、求二進(jìn)制中一的個(gè)數(shù)
    • 4.1 循環(huán)按位比較法
    • 4.2 余2除2法
    • 4.3 自己退格
  • 五、獲取并分別打印一個(gè)整數(shù)二進(jìn)制序列中所有的偶數(shù)位和奇數(shù)位
  • 六、求兩個(gè)整數(shù)m和n的二進(jìn)制表達(dá)中,有多少個(gè)位(bit)不同
    • 6.1 循環(huán)比較
    • 6.2 尋找中間媒介
    • 6.3 自己退格
  • 七、獲得月份天數(shù)
    • 7.1 數(shù)組
    • 7.2 switch語句
  • 八、進(jìn)制轉(zhuǎn)換
    • 8.1 遞歸
    • 8.2 數(shù)組實(shí)現(xiàn)
  • 九、刪除指定字符

成都網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、成都網(wǎng)站建設(shè)、微信開發(fā)、成都小程序開發(fā)、集團(tuán)成都企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。核心團(tuán)隊(duì)均擁有互聯(lián)網(wǎng)行業(yè)多年經(jīng)驗(yàn),服務(wù)眾多知名企業(yè)客戶;涵蓋的客戶類型包括:廣告制作等眾多領(lǐng)域,積累了大量豐富的經(jīng)驗(yàn),同時(shí)也獲得了客戶的一致稱贊!
一、次方 1.編寫一個(gè)函數(shù),實(shí)現(xiàn)n的k次方(考慮負(fù)數(shù))
#include#includedouble mul(int x, int y)
{if (y == 0)
	{return 1;
	}
	else if(y>0)
	{return x * pow(x, y - 1);
	}
	else
	{return 1.0 / pow(x, -y);
	}
}
int main()
{int n = 0;
	int k = 0;
	scanf("%d %d", &n, &k);
	double ret = mul(n, k);
	printf("%.2lf", ret);
	return 0;
}
二、輸入一個(gè)非負(fù)整數(shù),返回組成它的數(shù)字之和
#includeint DigitSum(int x)
{if (x >9)
		return DigitSum(x / 10) + x % 10;
	else
		return x;
}
int main()
{int num = 0;
	scanf("%d", &num);
	int ret = DigitSum(num);
	printf("%d", ret);
	return 0;
}
三、交換完打印 1. 迭代+temp法+數(shù)組
#include#includevoid string(char* ch,int sz)
{int left = 0;
	int right = sz - 1;
	char temp = 0;
	while (left<= right)
	{temp = ch[left];
		ch[left] = ch[right];
		ch[right] = temp;
		left++;
		right--;
	}
	printf("%s", ch);
}
int main()
{char ch[] = "abcdef";
	int sz = strlen(ch);
    string(ch,sz);     //返回值該用什么接收----不需要接收,地址直接是作用在上面的
	return 0;
}
2.用指針
#include#includevoid swap(char* ch,int x)
{int left = 0;
	int right = x - 1;
	while (left<= right)
	{char temp = 0;
		temp = *(ch + left);
		*(ch+left) = *(ch+right);
		*(ch + right) = temp;
		left++;
		right--;
	}

}
int main()
{char ch[] = "abcdef";
	int sz = strlen(ch);
	swap(ch,sz);
	printf("%s", ch);
	return 0;
}
2.遞歸
#include#includevoid swap(char ch[], int x)
{char temp = 0;
	temp = *ch;
	*ch = *(ch + x - 1);
	*(ch + x - 1) = '\0';
	if (strlen(ch + 1) >= 2)
	{swap(ch + 1,strlen(ch+1));
	}
	*(ch + x - 1) = temp;
}
int main()
{char ch[] = "abcdef";
	int sz = strlen(ch);
	swap(ch,sz);
	printf("%s", ch);
	return 0;
}
四、求二進(jìn)制中一的個(gè)數(shù) 4.1 循環(huán)按位比較法
#includeint count_one(int input)
{int i = 0;
	int count = 0;
	for (i = 0; i< 32; i++)
	{if (((input >>i) & 1) == 1)
		{	count++;
		}
	}
	return count;
}
int main()
{int input = 0;
	scanf("%d", &input);
	int ret = count_one(input);
	printf("%d", ret);
	return 0;
}

注意:

4.2 余2除2法
int count_one(unsigned int input)
{int count = 0;
	while (input)
	{if (input % 2 == 1)
		{	count++;
		}
		input /= 2;
	}
	return count;
}
int main()
{int input = 0;
	scanf("%d", &input);
	int ret = count_one(input);
	printf("%d", ret);
	return 0;
}
4.3 自己退格
int count_one(int input)
{int count = 0;
	while (input)
	{input = input & (input - 1);
		count++;
	}
	return count;
}

int main()
{int input = 0;
	scanf("%d", &input);
	int ret = count_one(input);
	printf("%d", ret);
	return 0;
}
五、獲取并分別打印一個(gè)整數(shù)二進(jìn)制序列中所有的偶數(shù)位和奇數(shù)位
void Print(int n)
{int i = 0;
	printf("奇數(shù)位: ");
	for (i = 30; i >=0; i -= 2)
	{printf("%d ", (n >>i) & 1);
	}
	printf("\n");

	printf("偶數(shù)位: ");
	for (i = 31; i >= 1; i -= 2)
	{printf("%d ", (n >>i) & 1);
	}
	printf("\n");
}

int main()
{int n = 0;
	scanf("%d", &n);
	Print(n);//打印n的2進(jìn)制中的所有奇數(shù)位和所有的偶數(shù)位
	return 0;
}
六、求兩個(gè)整數(shù)m和n的二進(jìn)制表達(dá)中,有多少個(gè)位(bit)不同 6.1 循環(huán)比較
#includeint is_different(int m,int n)
{int count = 0;
	int i = 0;
	for (i = 0; i< 32; i++)
	{if (((m >>i) & 1) != ((n >>i) & 1))
		{	count++;
		}
	}
	return count;
}
int main()
{int m = 0;
	int n = 0;
	scanf("%d %d", &m,&n);
	int ret = is_different(m,n);
	printf("%d", ret);
	return 0;
}
6.2 尋找中間媒介
#includeint is_different(int m, int n)
{int tmp = m ^ n;
	int count = 0;
	int i = 0;
	for (i = 0; i< 32; i++)
	{if (((tmp >>i) & 1) == 1)
		{	count++;
		}
	}
	return count;
}

int main()
{int m = 0;
	int n = 0;
	scanf("%d %d", &m,&n);
	int ret = is_different(m,n);
	printf("%d", ret);
	return 0;
}
6.3 自己退格
#includeint is_different(int m, int n)
{int count = 0;
	int tmp = m ^ n;
	while (tmp)
	{tmp = tmp & (tmp - 1);
		count++;
	}
	return count;
}
int main()
{int m = 0;
	int n = 0;
	scanf("%d %d", &m,&n);
	int ret = is_different(m,n);
	printf("%d", ret);
	return 0;
}
七、獲得月份天數(shù) 7.1 數(shù)組
int get_days_of_month(int y, int m)
{int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31 };
    //                1  2  3  4  5  6  7  8  9  10 11 12
    int day = days[m];
    if ((m == 2) && (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)))
    {day++;
    }
    return day;
}

int main() {int y = 0;
    int m = 0;
    while (scanf("%d %d", &y, &m) == 2)
    {int ret = get_days_of_month(y, m);
        printf("%d\n", ret);
    }

    return 0;
}
7.2 switch語句
int get_days_of_month(int y, int m)
{int day = 0;
    switch (m)
    {case 1: case 3: case 5:  case 7:  case 8:  case 10:  case 12:
        day = 31;
        break;
    case 4: case 6: case 9: case 11:
        day = 30;
        break;
    case 2:
    {day = 28;
        if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0))
            day++;
    }
    break;
    }
    return day;
}
八、進(jìn)制轉(zhuǎn)換 8.1 遞歸
#includevoid is_six_count(int input)
{if(input>5)
    {   is_six_count(input/6);
    }
       printf("%d",input%6);


}
int main()
{int input = 0;
    scanf("%d",&input);
    is_six_count(input);
    return 0;
}
8.2 數(shù)組實(shí)現(xiàn)
int main()
{int arr[20] = {0};
    int n = 0;
    scanf("%d", &n);
    int i = 0;
    while(n)
    {arr[i++] = n%6;
        n/=6;
    }
    for(--i; i>=0; i--)
    {printf("%d", arr[i]);
    }
    
    return 0;
}
九、刪除指定字符
#includevoid is_delect(int* arr, int delect, int sz)
{int i = 0;
    int j = 0;
    for (i = 0; i< sz; i++)
    {if (arr[i] == delect)
        {arr[j++] = arr[i];
        }
    }
    for (i = 0; i< j; i++)
    {printf("%d", arr[i]);
    }
}
int main()
{int num = 0;
    scanf("%d", &num);

    int i = 0;
    int arr[50] = 0;
    for (i = 0; i< num; i++)
    {scanf("%d", &arr[i]);
    }
    int delect = 0;
    scanf("%d", &delect);
    is_delect(arr, delect, num);
    return 0;
}

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧


網(wǎng)頁名稱:C語言經(jīng)典題型(二)-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://weahome.cn/article/egjcj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部