>a>>b>>c; if((a+b
C程序设计源代码大全
-
格式:doc
-
大小:118.50 KB
-
文档页数:81
S2_1
#include
using namespace std;
void main()
{
float a,b,c;
cout<<"input a b c\n";
cin>>a>>b>>c;
if((a+bcout<<"Not Triangle\n";
else
cout<<"Triangle\n";
}
S2_2
#include
using namespace std;
void main()
{
int year;
cout<<"Input year: ";
cin>>year;
if((year%4==0&&year%100!=0)||(year% 400==0))
cout<else
cout<}
S2_3
#include
using namespace std;
void main()
{
float a1, a2;
char oper;
float result;
int flag=0;
cout<<"请输入简单的运算式:\n";
cin>>a1>>oper>>a2;
switch(oper)
{
case'+':
result=a1+a2;
break;
case'-':
result=a1-a2;
break;
case'*':
result=a1*a2;
break;
default:
cout<<"输入错误的运算符!\n";
flag=1;
}
if(flag==0)
cout<}
S2_4
#include
#include
using namespace std;
void main()
{
float a,b,c,x1,x2;
cout<<"请输入方程的3个系数a b c \n";
cin>>a>>b>>c;
x1=(-b+sqrt(b*b-4*a*c))/2*a;
x2=(-b-sqrt(b*b-4*a*c))/2*a;
if(b*b-4*a*c<0)
cout<<"无实根!\n";
else
cout<<"x1="<cout<<"x2="<}
S3_1
#include
using namespace std;
void main()
{
int x,y;
for(x=1;x<=30;x++)
for(y=1;y<=30;y++)
if(x+y==30&&2*x+4*y==90)
cout<<"鸡有
1
"<}
S3_2
#include
void main()
{
int a0,a1,a2;
int b;
for(a2=1;a2<=9;a2++)
for(a1=1;a1<=9;a1++)
for(a0=1;a0<=9;a0++)
{
b=100*a2+10*a1+a0;
if(b==a2*a2*a2+a1*a1*a1+a0*a0*a0)
cout<
}
}
S3_3
#include
void main()
{
int a0,a1,a2;
int b;
for(b=100;b<=999;b++)
{
a2=b/100;
a1=(b/10)%10;
a0=b%10;
if(b==a0*a0*a0+a1*a1*a1+a2*a2*a2)
cout<
}
}
S3_4
#include
void main()
{
int a,b,c;
for(a=1;a<=36;a++)
for(b=1;b<=36;b++)
for(c=1;c<=36;c++)
if(a+b+c==36&&a*4+b*2+c/2==36&&c %2==0)
cout<<"男人"<}
S3_5_1
#include
void main()
{
int a;
for(a=1;a<=599;a++)
{
if((a%10==5||(a/10)%10==5||(a/10/10)% 10==5)&&(a%3==0))
cout<}
}
S3_5_2
#include
void main()
{
int a,b,c=0;
cout<<"请输入整数:";
cin>>a;
while(a)
{ b=a%10;
c=c+b;
a=a/10;}
cout<}
S4_1
#include
void main()
{
int a,b;
int x,t;
cout<<"请输入两个正整数:";
cin>>a>>b;
x=a*b;
if(a
{
t=a;a=b;b=t;}
while(t=a%b)
{
a=b;
b=t;
}
cout<<"最大公约数:"<
cout<<"最小公倍数:"<}
S4_2
#include
void main()
{
int a, b,c;
cout<<"Input three number:";
cin>>a>>b>>c;
for(int i=a;;i--)
if(a%i==0&&b%i==0&&c%i==0)
break;
cout<
}
S4_3
#include
#include
void main()
{
银行叫号系统Visual C ++程序源代码
主函数:
#include "stdafx.h"
#include "Queue.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
Queue s;
s.q[0] = 0; // 让入队的第一个数取数值1
int a=1, b=0 ,d=1 ,e=0;
char c;
while(a) // 运用switch实现选择
{
printf("顾客要号请输入A \n要提示下一位下一位顾客的号码请输入B \n要显示等待的人数请输入C\n结束循环请输入D \n ");
c= getchar();
while(getchar()!='\n') continue ;
switch(c)
{
case 'A':;
case 'a':// 顾客要号之后让元素入队
s.addQ();
b = s.getQ();
printf("顾客要的号码为:%d\n", b);
break;
case 'B ': ;
case'b':// 删除队首元素 即显示要来办理业务的顾客
d = s.delQ();
printf("请%d号客户前来柜台办理业务\n", d);
case 'C ':;
case 'c':// 显示等待的人数
e = s.number();
printf("等待的总人数为:%d\n", e);
break;
case 'D' :;
case 'd':// 结束循环
c=0;break;
default:
printf("输入错误!\n");
}
}
printf("Hello World!\n");
return 0;
}
队列的建立:(类)Queue.h
#if !defined(AFX_QUEUE_H__BA389AF8_C207_4C3E_8A7F_99499FBBA143__INCLUDED_)
C语言程序设计 入门源代码代码集合【精选文档】
演示1
#include 〈stdio.h〉
void print_star(void)
{
printf("*****************\n");
}
void print_welcome(void)
{
printf(”C language,welcome!\n");
}
void main()
{
print_star();
print_welcome();
print_star();
getchar();
}
演示2
#include "stdio。h"
int sum(int i,int j)
{
return(i + j);
}
void main()
{
int n1,n2;
printf("input 2 numbers:\n”);
scanf("%d%d”,&n1,&n2);
printf("the sum = %d\n",sum(n1,n2));
getchar();
}
演示3
#include "stdio。h"
int maxnum(int,int,int);
main()
{
int a,b,c;
printf("Please enter 3 numbers:\n");
scanf(”%d,%d,%d”,&a,&b,&c);
printf(”Maxnum is %d\n",maxnum(a,b,c)); return 0;
}
int maxnum(int x,int y,int z)
{
int max=x;
if(y>max)
max = y;
if(z>max)
max = z;
return max;
}
演示4
#include 〈stdio。h〉
int s1(int n)
{
int j,s;
s=0;
for(j=1;j<=n;j++)
s=s+j;
C程序源代码集[1]
交换两个数的值 .................................................................................................... 1
求N! ...................................................................................................................... 1
给定两圆圆心用C语言判断两圆关系。 ........................................................... 1
完成一串和单个字母的大小的转换。 ................................................................ 2
进行摄氏度和华氏度的相互转换。 .................................................................... 2
编程实现分段函数 ................................................................................................ 2
求 S=1-1/2+1/3-~~~~-100. ................................................................................ 2
求1!+2!+3!----N! .......................................................................................... 3
C语言代码大全
------------------------------------------------------------------------摘自 宋鲁生 程序设计大赛
乘法口诀表
#include
#include
void main(void)
{
int i,j,x,y;
clrscr();
printf("\n\n * * * 乘法口诀表 * * * \n\n");
x=9;
y=5;
for(i=1;i<=9;i++)
{
gotoxy(x,y);
printf("%2d ",i);
x+=3;
}
x=7;
y=6;
for(i=1;i<=9;i++)
{
gotoxy(x,y);
printf("%2d ",i);
y++;
}
x=9;
y= 6;
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
gotoxy(x,y);
printf("%2d ",i*j);
y++;
}
y-=9;
x+=3;
}
printf("\n\n");
}
用一维数组统计学生成绩
#include
void main()
{
char SelectKey,CreditMoney,DebitMoney;
while(1)
{
do{
clrscr();
puts("=========================");
puts("| Please select key: |");
puts("| 1. Quary |");
puts("| 2. Credit |");
puts("| 3. Debit |");
puts("| 4. Return |");
puts("=========================");
SelectKey = getch();
}while( SelectKey!='1' && SelectKey!='2' && SelectKey!='3' &&
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。