A. 在c語言中標准輸入輸出語句應該如何編寫操作
Turbo C 2.0標准庫提供了兩個控制台格式化輸入、輸出函數 scanf();和printf();這兩個函數可以在標准輸入輸出設備上以各種不同的格式讀寫數據。scanf()函數用來從標准輸入設備(鍵盤)上讀數據,printf()函數用來向標准輸出設備(屏幕)寫數據。下面詳細介紹這兩個函數的用法。
1.標准輸入語句
scanf()函數是格式化輸入函數,它從標准輸入設備(鍵盤)讀取輸入的信息。其調用格式為:scanf(<格式化字元串>,<地址表>);
格式化字元串包括以下三類不同的字元;
(1).空白字元:空白字元會使scanf()函數在讀操作中略去輸入中的一個或多個空白字元。
(2).非空白字元:一個非空白字元會使scanf()函數在讀入時剔除掉與這個非空白字元相同的字元。
(3).格式化說明符:以%開始,後跟一個或幾個規定字元,用來確定輸出內容格式。
B. C語言中如何實現輸入輸出多組數據,該如何結束輸入
c語言中實現多組數據輸入輸出主要有兩種方式:
1.首先輸入一個n,表示將有n個輸入輸出,例如:
#include
int main()
{
int n,a;
scanf("%d",&n);
while(n--){
scanf("%d",&a);
printf("輸出:%d\n",a);
}
return 0;
}
/*
運行結果:
3
255
輸出:255
156
輸出:156
125
輸出:125
*/2.使用while(scanf("%d",&n)!=eof){}語句,直達輸入ctrl+z,結束輸入,例如:
#include
int main()
{
int a;
while(scanf("%d",&a)!=eof){
printf("輸出:%d\n",a);
}
return 0;
}
/*
運行結果:
54
輸出:54
5156
輸出:5156
21
輸出:21
^z
*/
C. c語言中如何用子函數調用結構體中的變數實現數據的輸入與輸出。
用子函數實現結構體數據的輸入與輸出:對於多數子函數的輸入與輸出,有一定規律性可言。
方法1:void型不傳值傳址調用與聲明。main中聲明void date_in(),void date_pout()。函數定義前一定在main()前先定義結構體變數(全局變數),然後定義輸入或輸出程序段。此時再main()調用即可。
如下:
struct student
{
char name[20];
int old;
char sex;
}stu;
void date_in();
void main()
{ date_in();
}
void date_in()
{ scanf("%s%d/c,"stu.name,stu.old,stu.sex);
}時間問題程序有點簡潔,有問題請追問,很樂意與你分享。
D. C語言中如何實現多組數據輸入輸出
C語言中如何實現多組數據輸入輸出? c語言中有一個標准輸入函數,即:scanf函數,它可以讀取輸入的宴答亂任意格式類型的數據。scanf函數也有返回值,返回類型為int類型,它返回成功讀入的項目的個數。如果它沒有讀取任何項目(當它期望一個數字而您卻鍵入了一個非數字字元串時就會發生這種情況,scanf()會返回0。當它檢測到「文件結尾」(end of file)時,它返回EOF(EOF是在文件stdio.h中定義的特殊值,一般#define指令把EOF的值定義為-1,我們可以理解為:#define EOF -1)。
c語言中,所有的輸入函數都共用同一個輸入緩沖區,我們從鍵盤鍵入數據時,其實是將輸入寫入緩沖區中,當我們按下回車鍵時,scanf()函數從緩沖區中讀取輸入,刷新緩沖區。
C語言中實現多組數據輸入輸出主要有兩種方式:
1.首先輸入一個n,表示將有n個輸入輸出,例如:
#include <stdio.h>int main(){ int n,a; scanf("%d",&n); while(n--){ scanf("%d",&a); printf("輸出:%d\n",a); } return 0;}/*運行結果:3255輸出:255156輸出:156125輸出:125 */
2.使用while(scanf("%d",&n)!=EOF){}語句,直達輸入ctrl+z,結束輸入,例如:
#include <stdio.h>int main(){ int a; while(scanf("%d",&a)!=EOF){ printf("輸出:%d\n",a); } return 0;}/*運行結果:54輸出:545156輸出:515621輸出:21^Z*/
你先要設置數組的大小,這個你必須要定義的。你要不確定你要多少你最好把你的數值設置大些。至於你要輸多個你可以用循環語句如:for(i=1;i<=n;i++)
scanf("%d",&a[n]);
輸出還是一樣之是把scanf改成printf不要取地址就行了。
希望能對你有幫助。
C語言多組數據輸入輸出
#include<stdio.h>int pow(int a,int n)計算a的n次方{ if(n==1) return a; return a*pow(a,n-1);}int main(){ int T; int n,k,sum,i; scanf("%d",&T); while(T--) { sum=0; scanf("%d%d",&n,&k); for(i=1;i<=k;i++) { sum+=pow(n,i);累加 } printf("%d\n",sum); } return 0;}
c語言,如何實現多組數據結果對應輸出
scanf 一個 for
printf另一個for ................
C語言如何實現輸入多組數據測試
#include<stdio.h>
void main()
{
int n;
while(scanf("%d",&n)!=EOF,n)
或者寫成while(scanf("%d",&n)!=EOF)然後在循環里加一句if(n==0)break;
{
if(n==0)break;
if((n/10000==n%10)&&(n/1000%10==n/10%10))
判斷迴文
printf("Yes.\
");
else
printf("No.\
");
}
}
這個代碼應該是對的,在OJ上,多組舉蘆數據都是這么處理的。
這個沒關系的,提交的時候,這樣也是對的,因為OJ系統在判斷答案的時候,輸入和輸出數據放在不同的文件夾下面的,只要它的輸入文件在你的程序下運行,對應的輸出文件和他的一致,你的程序就是正確的,所晌檔以,就不需要把結果存起來。
如果你真的想那樣,那就用一個數組把答案存起來,等循環結束的時候,再把結果printf就行了
在c語言中,輸入輸出數據可以用輸入輸出函數,匯編語言如何實現輸入輸出數據?
匯編語言中,根據不同的晶元,也是不同的語句實現輸入輸出,但思想都是一樣的:輸入——將值取入;輸出——將值送出。語句:
輸入:
有的用 in R0,INPORTADD ;INPORTADD 是埠地址
輸出:
有的用 out R0,OUTADD ;OUTADD 是埠地址
而且,數據與地址,哪個放前,哪個放後,不同編譯環境也不同,所以,你要根據具體的環境來定。
單片機中,除了你提到的輸入輸出辦法,還有:用I/O來進行,就是用輸入輸出點的信號狀態來表達;也可用存儲晶元,如FLASH來進行處理數據的輸入輸出。
什麼叫數據的輸入輸出?在C語言中如何實現?
數據的輸入:在程序運行時,通過外部手段,發送數據給程序,供程序使用的過程,稱為數據的輸入。
數據的輸出:程序運行時,對外界的任何修改,都可以稱為輸出,包括但不限於,命令行的列印,圖形界面的顯示,存儲設備數據的修改等。
在C語言中,可以通過系統介面進行數據的輸入輸出,比較常用的有標准輸入輸出,文件輸入輸出,以及圖形界面輸入輸出等。
還可以通過硬體相關介面,實現特殊設備的輸入輸出,比如讀取串口設備的輸入輸出等。
E. C語言中如何實現多組數據輸入輸出
仔細認真看看下面的會對你有幫助的,嘿嘿
輸入格式:有多個case輸入,直到文件結束
輸出格式:一行一個結果
Problem Description
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.
Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample Input
1 5
10 20
Sample Output
6
30
Author
lcy
Recommend
JGShining
#include <stdio.h>
int main()
{
int a,b;
while( scanf( "%d%d" , &a , &b ) != EOF ) //輸入直到文件結尾
{
printf( "%d\n" , a+b ); //一行一個結果
}
return 0;
}
HDOJ1090
輸入格式:先輸入有case數,再依次輸入每個case
輸出格式:一行一個結果
#include <stdio.h>
Problem Description
Your task is to Calculate a + b.
Input
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample Input
2
1 5
10 20
Sample Output
6
30
Author
lcy
Recommend
JGShining
int main()
{ int n,a,b;
scanf( "%d" , &n ); //輸入的case數
while( n-- ) //控制輸入
{ scanf( "%d%d" , &a , &b );
printf( "%d\n" , a+b ); //一行一個結果
}
return 0;
}
HDOJ1091
輸入格式:每行輸入一組case,當case中的數據滿足某種情況時退出
輸出格式:一行一個結果
Problem Description
Your task is to Calculate a + b.
Input
Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample Input
1 5
10 20
0 0
Sample Output
6
30
Author
lcy
Recommend
JGShining
#include <stdio.h>
int main()
{
int a,b;
while( scanf( "%d%d" , &a , &b ) && (a||b) ) //輸入直到滿足a和b均為0結束
{
printf( "%d\n" , a+b ); //一行一個結果
}
return 0;
}
HDOJ1092
輸入格式:每組case前有一個控制輸入個數的數,當這個數為0結束
輸出格式:一行一個結果
#include <stdio.h>
Problem Description
Your task is to Calculate the sum of some integers.
Input
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
Sample Input
4 1 2 3 4
5 1 2 3 4 5
0
Sample Output
10
15
Author
lcy
Recommend
JGShining
int main()
{
int n,sum;
while( scanf( "%d" , &n ) && n ) //每組case前有一個控制該組輸入數據的數,為0結束
{
int x;
sum = 0;
while( n-- ) //控制該組輸入個數
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一個結果
}
return 0;
}
HDOJ1093
輸入格式:一開始有一個控制總的輸入case的數,而每個case中又有一個控制該組輸入數據的數
輸出格式:一行一個結果
Problem Description
Your task is to calculate the sum of some integers.
Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.
Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
Sample Input
2
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
Author
lcy
5
#include <stdio.h>
int main()
{
int casnum,n,sum;
scanf( "%d" , &casnum ); //控制總的輸入case的數
while( casnum-- ) //控制總的輸入個數
{
int x;
sum = 0;
scanf( "%d" , &n ); //每個case中控制該組輸入個數
while( n-- )
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一個結果
}
return 0;
}
HDOJ1094
輸入格式:總的case是輸到文件結尾,每個case中的一開始要輸入一個控制該組個數的數
輸出格式:一行一個結果
Problem Description
Your task is to calculate the sum of some integers.
Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.
Output
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.
Sample Input
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
6
#include <stdio.h>
int main()
{
int n,sum;
while( scanf( "%d" , &n ) != EOF ) //輸出到文件結尾
{
int x;
sum = 0;
while( n-- ) //控制該組輸入個數
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一個結果
}
return 0;
}
HDOJ1095
輸入格式:輸入直到文件結束
輸出格式:一行一個結果,結果輸完後還有一個blank line
Problem Description
Your task is to Calculate a + b.
Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.
Sample Input
1 5
10 20
Sample Output
6
30
7
#include <stdio.h>
int main()
{
int a,b;
while( scanf( "%d%d" , &a , &b ) != EOF ) //輸入直到文件結束
{
printf( "%d\n\n" , a+b ); //一行一個結果,結果輸完後還有一個回車
}
return 0;
}
HDOJ1096
輸入格式:一開始輸入總的case數,每組case一開始有控制該組輸入個數的數
輸出格式:一行一個結果,兩個結果之間有一個回車,注意最後一個case的處理。
Problem Description
Your task is to calculate the sum of some integers.
Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.
Output
For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.
Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
Sample Output
10
15
6
#include <stdio.h>
int main()
{
int casnum,n,sum;
scanf( "%d" , &casnum ); //總的輸入case數
while( casnum-- ) //控制輸入組數
{
int x;
sum = 0;
scanf( "%d" , &n ); //控制每組的輸入個數
while( n-- )
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一個結果
if( casnum ) printf( "\n" ); //兩兩結果之間有一個回車,最後一個結果後面沒有
}
return 0;
}
F. C語言:編程實現輸入,輸出
方法很多,我用數組實現。
定義20大小數組,下標加1就是1~20的數字,數組元素值就是輸入狀態。
#include<stdio.h>
#include<windows.h>
#include<conio.h>
void show(int *nums);
int main()
{
int nums[20]={0};//表示1到20個數字的狀態,0表示未被輸入,1表示已被輸入
int save[19],*p=save,n=19,in=0,flag;
while(n--)
{
flag=1;
system("cls");
show(nums);
printf("請輸入一個數字(1~20):"),scanf("%d",&in);
while(in<1 || in>20 || nums[in-1]==1)
{
if(in<1 || in>20)
printf("輸入錯誤!只能輸入1~20的整數!...按任意鍵重新輸入... "),getch();
else if(nums[in-1]==1)
printf("輸入錯誤!數字%d已輸入,不能重復!...按任意鍵重新輸入... ",in),getch();
flag=0;
n++;
break;
}
if(flag)
*p=in,nums[in-1]=1;
}
return 0;
}
void show(int *nums)
{
int i;
printf("已輸入數字:");
for(i=0;i<20;i++)
if(nums[i])
printf("%d ",i+1);
printf(" 未輸入數字:");
for(i=0;i<20;i++)
if(!nums[i])
printf("%d ",i+1);
printf(" ");
}
G. C語言輸入輸出格式
在C語言中,輸入使用的是scanf函數,scanf函數的格式為scanf(格式控制,地址列表),如scanf("%d"&a)。
輸出使用的是printf()函數,printf函數的格式為printf(格式控制,輸出表列),如printf("%d ",a)。在輸出時可以在"%"和字母之間插進數字表示最大場寬。可以根據需要輸出數字的位數來決定「%」前的數值。
如:%3d表示輸出3位整型數, 不夠3位右對齊。
%9.2f 表示輸出場寬為9的浮點數, 其中小數位為2, 整數位為7,小數點佔一位, 不夠9位右對齊。
%8s 表示輸出8個字元的字元串, 不夠8個字元右對齊。
(7)數據輸入與輸出c語言示例擴展閱讀
C語言輸入輸出時的規則:
一、格式說明符個數與輸入數據個數不相等的情況:
當我們輸入數據時,只要沒有按回車鍵,所輸入的數據都還存放在緩沖區,並沒有存入變數中。按【Enter】鍵後,scanf()函數才會從緩沖區中取走數據。緩沖區是一個先進先出的隊列,即取走數據的時候,遵循先輸入的數據先取走的原則。
scanf函數的格式說明符有幾個就要取幾次數據,只要碰到格式說明符就必須把數據取走,至於是不是要把取走的數據存放起來,就得看數據列表中的數據個數。沒取完的數據繼續留在緩沖區中。
二、寬度輸出的情況:
1、在%和格式字元之間加入一個整數來控制輸出數據所佔寬度
2、在%和格式字元f之間加入一個「整數1.整數2」來控制輸出數據的格式。
整數1:整個輸出數據占的總寬度
整數2:輸出實數的小數部分的個數
注意:先用整數2處理小數部分,再用整數1處理整個數據,包括已處理好的小數部分
三、寬度輸入的情況:
寬度輸入指的是在%和格式說明符d之間加入一個整數。如:scanf("%2d", &x);
注意:
1、%d與%1d是不同的,它們具有不同的含義。
2、 當寬度小於數據的實際寬度時,截取指定寬度的部分作為一個數進入緩沖區,再將剩餘部分作為另一個數放入緩沖區。
H. C語言中如何輸入輸出文字
需要准備的材料分別有:電腦、C語言編譯器。
1、首先,打開C語言編譯器,新建一個初始.cpp文件,例如:test.cpp。
I. C語言中如何實現多組數據輸入輸出
C語言中實現多組數據輸入輸出主要有兩種方式:
1.首先輸入一個n,表示將有n個輸入輸出,例如:
#include<stdio.h>
intmain()
{
intn,a;
scanf("%d",&n);
while(n--){
scanf("%d",&a);
printf("輸出:%d ",a);
}
return0;
}
/*
運行結果:
3
255
輸出:255
156
輸出:156
125
輸出:125
*/
2.使用while(scanf("%d",&n)!=EOF){}語句,凱神慎直達輸入ctrl+z,結束輸盯敬入,例如:
#include<stdio.h>
intmain()
{
inta;
while(scanf("%d",&a)!=EOF){
printf("輸出:%d ",a);
}
return0;
}
/*
運行瞎禪結果:
54
輸出:54
5156
輸出:5156
21
輸出:21
^Z
*/
J. 急急!!!如何用c語言輸入和輸出一個二維數組
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[2][2];
int i,j;
for (i=0;i<2;i++)
{
for (j=0;j<2;j++)
{
scanf("%d ",&a[i][j]);
}
}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
printf("%d",a[i][j]);
return 0;
}
運行成功