本文目錄一覽:
C語言題,求大神~~~
#include “stdafx.h”
#includestdio
#includestdlib.h
// 用於判斷輸入的數是否為素數
// 參數number為需要判斷的數
// 當number為素數時返回true,否則返回false
bool judgeprime(int number)
{
int i = 0;
for(i = 2; i number; i++)
if(number % i == 0)
return false;
return true;
}
void main()
{
bool judgeprime(int number);
int i = 0;
int a[10] = {5,4,9,8,7,6,0,1,3,2}; // 也可以是用scanf方法得到需要判斷的數
for(i = 0; i 10; i++)
{
if(judgeprime(a[i]))// 調用素數判斷函數
printf(“%d是素數. “, a[i]);
else
printf(“%d不是素數. “, a[i]);
}
getchar();
}
c語言中用遞歸法求最大公約數,要求如下,我試過好多次都不行,求大神幫忙,先謝謝了
#includestdio.h
int ged(int a, int b);
int main()
{
int a,b;
scanf(“%d %d”,a, b);
int c=ged(a,b);
printf(“%d\n”, c);
return 0;
}
int ged(int a, int b)
{
if ((a=0)||(b=0))
return 0;
if (ab) return ged(b,a-b);
if (ba) return ged(a,b-a);
if (a==b) return a;
}
C語言的get是怎樣使用的呢?
gets函數:從stdin流中讀取字元串,直至讀到換行符或EOF時停止,並將讀取的結果存放在buffer指針所指向的字元數組中。
換行符不作為讀取串的內容,讀取的換行符被轉換為 \0 空字元,並以此結束字元串;當使用unicode寬字元文本時,請使用寬字元版本函數 _getws()。
gets函數可以無限讀取,不會判斷上限,所以使用時應確保buffer的空間足夠大,以便在執行讀取操作時不發生溢出。
gets函數在C11標準中被移除,改為更加安全的gets_s函數;頭文件:stdio.h;返回值:若讀入成功,返回與參數buffer相同的字元指針。
若讀入過程中遇到EOF或發生錯誤,返回NULL指針。所以當遇到返回值為NULL的情況時,應使用ferror或feof函數檢查是發生錯誤還是遇到EOF。
擴展資料
#include iostream
#include limits
#include cstdio
using namespace std;
int main()
{
int i_test, c;
printf(“Please enter an integer: “);
scanf(“%d”, i_test);
printf(“You just entered %d.\nPress enter to continue…”, i_test);
while ( (c = getchar()) != ‘\n’ c != EOF ) ; // 清空輸入流
clearerr(stdin); // 清除流的錯誤標記
cin.get(); // 等待用戶輸入回車
return 0;
}
原創文章,作者:KIDL,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/143632.html