① 求简单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语言:求一段简单的代码。
#包括
使用命名空间std;
定义countof(x)的大小(X)/大小(X [0])
:( )
{
字符szText [256];
诠释nBytes个= 0 ;/ /字节数
诠释nSpace = 0 ;/ /数量的空格
诠释NROW = 0 ;/ /行数
诠释NABC = 0 ;/ /大小写的字母数字
法院<<“请输入一个字符串,统计,以#号结束的。” << endl;
cin.get(szText,countof(szText),'#');
为(int i = 0;我的strlen(szText),我+ +)
> {
((szText [I]> ='A'&& szText [I] <='Z')
| |(szText [I]> ='A'&& szText [我] <='Z'))
{
NABC + +;
}
其他(szText [I] =='')
{
nSpace + +;
}
其他(szText [I] =='\ n')
{
NROW + +;
}
nBytes个+ +;
}
cout <<“请字节数:”<< nBytes个<< endl;
法院<<“号的空格:”“; nSpace < <endl;
法院<<“行数:”<< endl << NROW;
cout <<“请一些大写和小写字母:”NABC << endl;
> 0;
}
③ 求几个比较有趣,简单的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语言程序代码
#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");
}
}
你题意不是太明确,我随意编了一个不知道是不是你想要的。
⑤ 求一段简单的C语言代码
#include <iostream>
using namespace std;
#define countof(x) sizeof(x)/sizeof(x[0])
int main()
{
char szText[256];
int nBytes = 0;//字节数
int nSpace = 0;//空格数
int nRow = 0;//行数
int nAbc = 0;//大小写字母数
cout<<"请输入要统计的字符串,以#号结束"<<endl;
cin.get( szText, countof(szText), '#' );
for ( int i = 0; i < strlen(szText); i++ )
{
if ( (szText[i] >= 'a' && szText[i] <= 'z')
|| (szText[i] >= 'A' && szText[i] <= 'Z') )
{
nAbc++;
}
else if ( szText[i] == ' ' )
{
nSpace++;
}
else if ( szText[i] == '\n' )
{
nRow++;
}
nBytes++;
}
cout<<"字节数:"<<nBytes<<endl;
cout<<"空格数:"<<nSpace<<endl;
cout<<"行数:"<<nRow<<endl;
cout<<"大小写字母数:"<<nAbc<<endl;
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>
#include
<string.h>
void
main()
{
char
a[10],b[10];
printf("请输入您要倒置的字符串:");
gets(a);
int
k=strlen(a);
int
i,j;
for(i=0,j=k-1;
j>=0;
i++,j--)//这改了下,
{
b[i]=a[j];
}
b[i]='\0';////这要加一句,不然下面的输出要出乱码,
printf("%s\n",b);
///加了个回车好看,
}
⑧ 帮忙写一段简单的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语言程序代码急急急
#include
<stdio.h>
main(int
argc)
{
print();
if(0
!=
argc)
{
printf("女:\n鹅鹅鹅\n白毛浮绿水\n红掌拨清波\n");
}
}
print()
{
printf("男:\n鹅鹅鹅\n白毛浮绿水\n红掌拨清波\n");
printf("<<<<<<请输入任意键>>>>>>\n");
getch();
}
输出是这样的:
男:
鹅鹅鹅
白毛浮绿水
红掌拨清波
<<<<<<请输入任意键>>>>>>
女:
//输入任意键后显示的
鹅鹅鹅
白毛浮绿水
红掌拨清波
不知道能不能帮上你~
⑩ 最简单的C语言代码
最简单的C语言代就是输出“helloWord”,通常是作为初学编程语言时的第一个程序代码。具体代码如下:
#include <stdio.h>
int main(){
printf("Hello, World! ");
return 0;
}
(10)一段简单的c语言代码扩展阅读:
1、程序的第一行#include <stdio.h>是预处理器指令,告诉 C 编译器在实际编译之前要包含 stdio.h 文件。
2、下一行intmain()是主函数,程序从这里开始执行。
3、下一行printf(...)是C中另一个可用的函数,会在屏幕上显示消息"Hello,World!"。
4、下一行return0;终止main()函数,并返回值0。