對網(wǎng)站建設(shè)服務(wù)公司的看法新東方烹飪學校學費一年多少錢
1.求最小公倍數(shù)
正整數(shù)A和正整數(shù)B 的最小公倍數(shù)是指 能被A和B整除的最小的正整數(shù)值,設(shè)計一個算法,求輸入A和B的最小公倍數(shù)。
1≤a, b≤100000
輸入描述:
輸入兩個正整數(shù)A和B。
輸出描述:
輸出A和B的最小公倍數(shù)。
#include <stdio.h>int main() {int a, b;while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 處理多個 case// 64 位輸出請用 printf("%lld") to int i = 0;int min = 0;min = a > b ? b : a;for (i = min; i <= a * b; i++){if (i % a == 0 && i % b == 0){printf("%d\n", i);break;}}}return 0;
}
2.求解立方根
計算一個浮點數(shù)的立方根,不使用庫函數(shù)。
保留一位小數(shù)。
輸入描述:
待求解參數(shù),為double類型(一個實數(shù))
輸出描述:
輸出參數(shù)的立方根。保留一位小數(shù)。
#include <stdio.h>
int main()
{double n, m;double i = 0;scanf("%lf", &n);if (n > 0){while (i * i * i < n){i = i + 0.01;}printf("%.1lf", i);}else{m = -n;while (i * i * i < m){i = i + 0.01;}printf("%.1lf", -i);}
}
3.字符逆序
將一個字符串str的內(nèi)容顛倒過來,并輸出。
數(shù)據(jù)范圍:
1~10000
1≤len(str)≤10000
輸入描述:
輸入一個字符串,可以有空格
輸出描述:
輸出逆序的字符串
#include<stdio.h>
#include<string.h>int main()
{char str[10001];gets(str); //得到一個字符串 scanf遇到空格會跳過for (int i = strlen(str) - 1; i >= 0; i--) {//strlen函數(shù)求字符串長度 頭文件string.hprintf("%c", str[i]);}return 0;
}
4.刪除公共字符
輸入兩個字符串,從第一字符串中刪除第二個字符串中所有的字符。例如,輸入”They are students.”和”aeiou”,
則刪除之后的第一個字符串變成”Thy r stdnts.”輸入描述\n輸入包含2個字符串。輸出描述\n輸出刪除后的字符串。
輸入:They are students.
輸出:Thy r stdnts.
int judge(char ch, char arr[])
{int i = 0;while (arr[i]){if (ch == arr[i]){return 1;}i++;}return 0;
}int main()
{char arr1[101] = { 0 };gets(arr1);//取字符串包括空格char arr2[101] = { 0 };gets(arr2);int i = 0;while (arr1[i]){if (judge(arr1[i], arr2) == 0){printf("%c", arr1[i]);}i++;}return 0;
}
5.添加逗號
對于一個較大的整數(shù)N(1<=N<=2,000,000,000)比如980364535,
我們常需要一位一位數(shù)這個數(shù)字是幾位數(shù),但是如果在這個數(shù)字每三位加一個逗號,他會變得更加易于朗讀
因此,這個數(shù)字加上逗號稱以下模樣:980,364,535請寫一個程序幫她完成這件事
輸入描述:一行一個整數(shù)N
輸出描述:一行一個字符串表示添加完逗號的結(jié)果
方法:取模得一個數(shù),除去掉一個數(shù)
int main()
{char arr[14] = { 0 };int N = 0;scanf("%d", &N);int k = 0;int i = 0;while (N){if (k != 0 && k % 3 == 0){arr[i++] = ',';}arr[i++] = N % 10 + '0';N /= 10;k++;}for (i = i - 1; i >= 0; i--){printf("%c", arr[i]);}return 0;
}