『壹』 c語言新手入門代碼 隨便幾個就行。
咨詢記錄 · 回答於2021-08-05
『貳』 求各種簡單的C語言代碼來研究 新手練習 新手.剛學c 想聯系敲代碼
#include <stdio.h>
int main()
{
int i1 = 3;
int i2 = 5;
int i3=(a+b)/2;
printf("i3=%d\n",i3);
return 0;
}
『叄』 求50行簡單C語言程序代碼,基礎的就好
#include <stdio.h>
#include <stdlib.h>
#define NUM 10
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//冒泡排序演算法
//基本思想:比較相鄰的兩個數,如果前者比後者大,則進行交換。每一輪排序結束,選出一個未排序中最大的數放到數組後面。
void bubbleSort(int *arr, int n) {
int i,j;
for (i = 0; i<n - 1; i++)
for (j = 0; j < n - i - 1; j++) {
//如果前面的數比後面大,進行交換
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
//最差時間復雜度為O(n^2),平均時間復雜度為O(n^2)。穩定性:穩定。輔助空間O(1)。
//升級版冒泡排序法:通過從低到高選出最大的數放到後面,再從高到低選出最小的數放到前面,
//如此反復,直到左邊界和右邊界重合。當數組中有已排序好的數時,這種排序比傳統冒泡排序性能稍好。
//升級版冒泡排序演算法
void bubbleSort_1(int *arr, int n) {
//設置數組左右邊界
int left = 0, right = n - 1;
//當左右邊界未重合時,進行排序
while (left<=right) {
int i,j;
//從左到右遍歷選出最大的數放到數組右邊
for (i =left; i < right; i++) {
if (arr[i] > arr[i + 1]) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
right--;
//從右到左遍歷選出最小的數放到數組左邊
for (j = right; j> left; j--) {
if (arr[j + 1] < arr[j]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
left++;
}
}
int main(int argc, char *argv[]) {
int arr[NUM],i,j,temp;
printf("請輸入10個數:\n");
for(i=0; i<NUM; i++) {
printf("請輸入第(%d)個數:",i+1);
scanf("%d",&arr[i]);
}
printf("\n輸入如下排列:\n");
for(i=0; i<NUM; i++) {
printf("%4d",arr[i]);
}/*
for(i=0; i<NUM; i++) {
for(j=i+1; j<NUM; j++) {
if(arr[i]>arr[j]) {
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}*/
bubbleSort_1(arr,NUM);
/*printf("\n從小到大如下排列:\n");
for(i=0; i<NUM; i++) {
printf("%4d",arr[i]);
}*/
printf("\n從大到小如下排列:\n");
for(i=NUM-1; i>=0; i--) {
printf("%4d",arr[i]);
}
return 0;
}
『肆』 c語言初學:求簡單代碼:
#include "stdio.h"
void main() {
int a[10] = {1,2,3,4,5,6,7,8,9,10};
int temp,i,j;
for(i = 0,j=9; i<5; i++, j--) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
for(int k = 0; k<10; k++)
printf("%d", a[k]);
}
『伍』 求幾個比較有趣,簡單的C語言源代碼 小白自己敲著練一下手感
最簡單的模擬計時器:
#include<stdio.h>
#include<conio.h>
#include<windows.h>
int m=0,s=0,ms=0; //m是分 s是秒 ms是毫秒
//以下是5個自編函數
void csh( ); //初始化界面
void yinc(int x,int y); //隱藏游標的函數(y值設為0就會隱藏)
void jishi( ); //計時器運行(每100毫秒變化一次)
void Color (short x, short y); //設定顏色的函數(y設為0就是黑底)
void gtxy (int x, int y); //控制游標位置的函數
int main( ) //主函數
{ csh( );
getch( );
while(1)
{ jishi( );
Sleep(100); //間隔100毫秒
if( kbhit( ) )break; //有鍵按下就退出循環
}
return 0;
}
void csh( ) //初始化界面
{Color(14,0); //設定淡黃字配黑底
printf(「 計時器」);
Color(10,0); //設定淡綠字配黑底
printf(" ┌───────────┐");
printf(" │ │");
printf(" └───────────┘");
gtxy(10,4); //游標到屏幕第10列4行處輸出
Color(7,0); //恢復白字黑底
printf(" 00:00:00 ");
yinc(1,0 ); //隱藏游標(yinc代表隱藏)
return;
}
void jishi( ) //計時器運行
{ms+=1;
if(ms==10){s+=1;ms=0;}
if(s==60){m+=1;s=0;}
gtxy(10,4);
Color(9,0); //設定淡藍字配黑底
if(m>9) printf(" %d:",m);
else printf(" 0%d:",m);
Color(14,0); //設定淡黃字配黑底
if(s>9) printf("%d:",s);
else printf("0%d:",s);
Color(12,0); //設定淡紅字配黑底
printf("0%d",ms);
}
void gtxy (int x, int y) //控制游標位置的函數
{ COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );
}
void Color (short ForeColor= 7, short BackGroundColor= 0) //設定顏色的函數
{ HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute ( handle, ForeColor + BackGroundColor * 0x10 );
}
void yinc(int x,int y) //隱藏游標的設置(gb代表游標)
{ CONSOLE_CURSOR_INFO gb={x,y}; //x為1-100,y為0就隱藏游標
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &gb);
}
『陸』 求簡單C語言程序代碼!
輸入2個正整數m和n,求其最大公約數和最小公倍數
#include
#include
int main()
int m,n,p,q,s,r;
printf("請輸入兩個正整數;m,n ");
scanf("%d,%d",&m,&n);
#include<stdio.h>
main()
int a,b,t=0;
scanf("%d %d",&a,&b);
if (a<b)
printf("%d %d %d %d %d",(a+b),(a-b),(a/b),(a*b),(a%b));
}
主要特點
C語言是一種結構化語言,它有著清晰的層次,可按照模塊的方式對程序進行編寫,十分有利於程序的調試,且c語言的處理和表現能力都非常的強大,依靠非常全面的運算符和多樣的數據類型,可以輕易完成各種數據結構的構建,通過指針類型更可對內存直接定址以及對硬體進行直接操作,因此既能夠用於開發系統程序,也可用於開發應用軟體。
以上內容參考:網路-c語言
『柒』 幫忙寫一段簡單的c語言代碼
#include <stdio.h>
int main()
{
FILE *fp;
int a[3][9],i,j;
if((fp=fopen("C:\cDemo\data.txt","r"))!=NULL)
{
for(i=0;i<3;++i)
{
for(j=0;j<9;++j)
{
fscanf(fp,"%d",&a[i][j]);
}
}
for(i=0;i<3;++i)
{
for(j=0;j<9;++j)
{
printf("%d ",a[i][j]);
}
printf(" ");
}
}
else
{
puts("Can't open C:\cDemo\data.txt");
}
return 0;
}
『捌』 寫一個簡短的C語言代碼
最簡單的C語言代就是輸出「helloWord」,通常是作為初學編程語言時的第一個程序代碼。具體代碼如下:
#include <stdio.h>
int main(){
printf("Hello, World! ");
return 0;
}
(8)有趣的入門簡單c語言代碼擴展閱讀:
1、程序的第一行#include <stdio.h>是預處理器指令,告訴 C 編譯器在實際編譯之前要包含 stdio.h 文件。
2、下一行intmain()是主函數,程序從這里開始執行。
3、下一行printf(...)是C中另一個可用的函數,會在屏幕上顯示消息"Hello,World!"。
4、下一行return0;終止main()函數,並返回值0。
『玖』 求 一個超簡單的C語言程序代碼
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void
main()
{
int
a,b,d,f;
char
c[4],e[5]="EXIT";
while(true)
{printf("BEGIN(開始)EXIT(退出):");
scanf("%s",c);
while(strcmp(c,e)!=0)
{printf("請輸入a和b:");
scanf("%d
%d",&a,&b);
d=a+b;
printf("%d\n",d);
printf("是否繼續[1.是;0.否]:");
scanf("%d",&f);
if(f==0)
break;
else
continue;
}
if(strcmp(c,e)==0)
printf("結束\n");
printf("按回車返回開頭");
fflush(stdin);
getchar();
system("cls");
}
}
你題意不是太明確,我隨意編了一個不知道是不是你想要的。