平方根
sqrt(n) = 算出平方根
ex. int a = sqrt(9); //答案為3;because 3*3=9 ;3的平方等於9
次方
pow(intA,intB) =A的B次方
long long 的input 方法
long long x ;
scanf("%lld",x);
平方數、完全平方數
X平方=N*N
所以我們先求X的平方根
int y = sqrt(x)+0.5;
//這邊為什麼要加上0.5,因為怕精準度如果等於0.999999就等於零,而我們是要求整數,所以小數就不需要管
if(x=y*y)
階層、
const int MOD = 1000000;
int n, S = 0;
scanf_s("%d", &n);
for (int i = 1; i <= n; i++)
{
int factorial = 1;
for (int j = 1; j <= i; j++)
{
factorial *= j % MOD;
S += factorial % MOD;
}
}
printf("%d\n", S);
printf("tIME USED = %.2f\n", (double)clock()/CLOCKS_PER_SEC);
return 0;
OutputDebugString (聽說好用,不過還沒有多加以研究,先記錄)
#include "windows.h"
int main()
{
OutputDebugString(L"ab");
}
void WINAPI OutputDebugString(_In_opt_ LPCTSTR lpOutputString);
在CMD 無法結束程式??
按下CTRL +Z 在按下 ENTER
或是直接輸入 ^Z 在按下 ENTER也可以
無法使用freopen ,改用 freopen_s 之方法(這是讀取檔案,和寫入檔案之方法)
#include "stdafx.h"
#include <time.h>
#include <stdio.h>
FILE *stream;
int main()
{
#define INF 1000000000
freopen_s(&stream,"input.txt", "r", stdin);
freopen_s(&stream,"output.txt", "w", stdout);
int x=0, n = 0, min=INF, max = -INF, s = 0;
while (scanf_s("%d", &x) == 1)
{
s += x;
if (x < min) min = x;
if (x>max) max = x;
n++;
}
printf("%d %d %.3f\n", min, max, (double)s / n);
return 0;
}
參考
http://msdn.microsoft.com/zh-tw/library/88k7d7a7.aspx
以上使用的方式, 寫入檔案並沒有寫在 最下面,但仍然會輸出
取百位,十位,個位數 daffodil 水仙花數題目
int main()
{
for (int i = 100; i <= 999; i++)
{
int a = powf(i / 100, 3); //取百位數
int b = powf(i/10%10,3); //取十位數
int c = powf(i%10,3); //取個位數
if (i == a + b + c)
printf_s("%d\n", i);
}
return 0;
}
逆續輸出,例題 陣列控制
int main()
{
int a[105],x=0;
while (scanf_s("%d",&a[x])==1)
{
x++;
}
for (int i = x - 1; i >= 0; i--)
printf("%d\n", a[i]);
return 0;
}
階層、
const int MOD = 1000000;
int n, S = 0;
scanf_s("%d", &n);
for (int i = 1; i <= n; i++)
{
int factorial = 1;
for (int j = 1; j <= i; j++)
{
factorial *= j % MOD;
S += factorial % MOD;
}
}
printf("%d\n", S);
printf("tIME USED = %.2f\n", (double)clock()/CLOCKS_PER_SEC);
return 0;
OutputDebugString (聽說好用,不過還沒有多加以研究,先記錄)
#include "windows.h"
int main()
{
OutputDebugString(L"ab");
}
void WINAPI OutputDebugString(_In_opt_ LPCTSTR lpOutputString);
在CMD 無法結束程式??
按下CTRL +Z 在按下 ENTER
或是直接輸入 ^Z 在按下 ENTER也可以
無法使用freopen ,改用 freopen_s 之方法(這是讀取檔案,和寫入檔案之方法)
#include "stdafx.h"
#include <time.h>
#include <stdio.h>
FILE *stream;
int main()
{
#define INF 1000000000
freopen_s(&stream,"input.txt", "r", stdin);
freopen_s(&stream,"output.txt", "w", stdout);
int x=0, n = 0, min=INF, max = -INF, s = 0;
while (scanf_s("%d", &x) == 1)
{
s += x;
if (x < min) min = x;
if (x>max) max = x;
n++;
}
printf("%d %d %.3f\n", min, max, (double)s / n);
return 0;
}
參考
http://msdn.microsoft.com/zh-tw/library/88k7d7a7.aspx
以上使用的方式, 寫入檔案並沒有寫在 最下面,但仍然會輸出
取百位,十位,個位數 daffodil 水仙花數題目
int main()
{
for (int i = 100; i <= 999; i++)
{
int a = powf(i / 100, 3); //取百位數
int b = powf(i/10%10,3); //取十位數
int c = powf(i%10,3); //取個位數
if (i == a + b + c)
printf_s("%d\n", i);
}
return 0;
}
逆續輸出,例題 陣列控制
int main()
{
int a[105],x=0;
while (scanf_s("%d",&a[x])==1)
{
x++;
}
for (int i = x - 1; i >= 0; i--)
printf("%d\n", a[i]);
return 0;
}
沒有留言:
張貼留言