初学c语言所编的程序

1.猜数字

#include<stdlib.h>

#include<stdio.h>
main(){
int guess;
int magic;
int counter=0;
magic=rand()%100+1;
while (guess!=magic){ 
printf("请输入数字:");
scanf("%d",&guess);
counter++;
if (guess>magic){
printf("错误,太大了\n");}
else if(guess<magic){
printf("错误,太小了\n");}
else {
printf("正确");
printf("这个数是= %d\n",magic);}
}while (guess!=magic)
 

 printf("counter=%d\n",counter);}

2.字符大小的判断

#include<stdio.h>
main(){
char ch;
printf("请输入字母:");
scanf("%c",&ch);
if (('a'<=ch)&&(ch<='z'))
{
printf("小写字母=%c\n",ch);}
else if(('A'<=ch)&&(ch<='Z')){
printf("大写字母=%c\n",ch);}
else {printf("不是字母\n");}

}

3.男女身高的预测

#include<stdio.h>
main(){
float faheight,maheight;
float gheight,boyheight;
int t;
printf("请输入1或2");
scanf("%d",&t);
if (t==1)
{
printf("请输入父亲的身高和母亲的身高\n");
   scanf("%f%f\n",&faheight,&maheight);
   gheight=(faheight+maheight)*0.50;
printf("女孩身高%f",gheight);
}


4.阶乘

#include<stdio.h>
main(){
int n;
int i=1;
long p=1;
printf("请输入n的值:");
scanf("%d",&n);
while (i<=n){
p=p*i;
i++;
}
printf("%d! =ld\n",n,p);}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值