❶ 三道簡單的編程題
不知道你學的是什麼語言,我是學C的,先把源程序先貼出來,如果你看不懂,可以再補充提問,我再把方法告訴你!
1.
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,m,in,out;
scanf("%d%d%d%d",&a,&b,&c,&d);
m=2.5*a+1.8*b+2*c+1.6*d;
printf("%d\n",m);//輸出應付錢數
scanf("%d",&in);
out=in-m;
printf("%d\n",out);//輸出應找的錢數
getch();
}
2.
#include<stdio.h>
#include<conio.h>
main()
{
char c1,c2,c3,c4,c5;
scanf("%c%c%c%c%c",&c1,&c2,&c3,&c4,&c5);
c1=c1+4;
c2=c2+4;
c3=c3+4;
c4=c4+4;
c5=c5+4;
printf("%c%c%c%c%c\n",c1,c2,c3,c4,c5);
getch();
}
第三題的圖案沒有顯示出來,不知道「中」有多大,你只要按照它的形狀列印就可以了
❷ C語言編程題
根據題意:
題目1:函數參數是除數(這里傳值8),返回滿足條件的數字和。
題目2:函數參數是要找的項目數(這里傳值10),返回對應項的值。
#include<stdio.h>
#define MIN 50
#define MAX 1000
int fa(int a);//對應題目1的函數,參數:要除的數,返回可以被整除的數之和
int getByIndex(int n);//對應題目2,返回數列第n項,錯誤返回-1
int main()
{
printf("1、%d~%d之間能被%d整除的數字之和為:%d ",MIN,MAX,8,fa(8));
printf("2、數列頭三個數為4,5,6,以後的每個數為前三數和,求此數列第%d項:%d ",10,getByIndex(10));
return 0;
}
int fa(int a)//對應題目1的函數,參數:要除的數,返回可以被整除的數之和
{
int i,sum=0;
for(i=MIN;i<=MAX;i++)
if(i%a==0)
sum+=i;
return sum;
}
int getByIndex(int n)//對應題目2,返回數列第n項,錯誤返回-1
{
if(n<1)
return -1;
int i,nums[n];
nums[0]=4,nums[1]=5,nums[2]=6;
for(i=3;i<n;i++)
nums[i]=nums[i-1]+nums[i-2]+nums[i-3];
return nums[n-1];
}
❸ 編程題:編寫程序輸入三角形的3條邊長,計算並輸出三角形的面積。
一、程序分析
三角形面積海倫公式:√[ p ( p - a ) ( p - b ) ( p - c ) ] 。其中 p = (a + b + c) / 2 。a、b、c分別是三角形的三邊長。
二、根據三角形面積計算公式用if語句編寫程序如下:
#include "stdio.h"
#include "math.h"
int main(void)
{
float a = 0, b = 0, c = 0, p = 0;
float area = 0;
printf("Please input three sides of triangle:");
scanf_s("%f %f %f", &a, &b, &c);
if((a + b) > c && (a + c) > b && (b + c) > a)
{
p = (a + b + c) / 2;
area = sqrt(p * (p - a) * (p - b) * (p - c));
}
else
printf("Triangle does not exist! ");
printf("The area of triangle is:%f ", area);
return 0;
(3)百度編程題擴展閱讀:
還可以使用switch語句計算三角形的面積,編寫程序如下
#include "stdio.h"
#include "math.h"
int main(void)
{
float a = 0, b = 0, c = 0;
float p = 0;
printf("Please input three sides of triangle:");
scanf_s("%f %f %f", &a, &b, &c);
switch (a + b > c && a + c > b && b + c > a)
{
case 0:printf("Triangle does not exist! "); break;
case 1:
p = (a + b + c)*0.5;
printf("The area of triangle is:%f ", sqrt(p * (p - a) * (p - b) * (p - c)));
break;
}
return 0;
}
❹ C語言編程題
以下程序把一個由小到大的有序數列放在a[1]到a[n]中,a[0]用作工作單元,程序把讀入的x值插入到a數組中,插入後,數組中的數仍然的序。請填空,完善程序。
#include<stdio.h>
{int
a[10]={0,12,17,20,25,28},x,i,n=5;
printf(「enter
a
number:」);
scanf(「%d」,&x);
a[0]=x;i=n;
while(a[i]>x)
{a[i+1]=a[i];
i--;
}
a[i+1]=x;n++;
for(i=1;i<=n;i++)
printf(「%4d」,a);
printf(「\n」);
}
你題目應該漏了幾個東西吧,我試著補充了下。題目是很簡單的,不用拿到這上面來問的。
❺ 編程題:為比賽選手評分,讀入10名評委的評分,從中扣除一個最高分和一個最低分,輸出這個選手的最後得分
#include
void main()
{
int a[10],i,max,min,sum=0;//補了「=0」
printf("輸入10名評委的評分: ");
for(i=0;ia[i]) min=a[i];
}
printf("最後得分:%.2f ",(sum-max-min)/8.0);
}
編譯:
#include<stdio.h>
void main()
{ int i,a[10],sum=0,j,t;
float avg;
for(i=0;i<10;i++) scanf("%d",&a[i]); /*輸入*/
if(a[j]>a[j+1]) {t=a[j];a[j]=a[j+1];a[j+1]=t;} /*排序*/
for(i=0;i<10;i++) printf("%d ",a[i]); /*去掉一個最高分和最低分*/
for(i=1;i<9;i++) sum+=a[i];
avg=(float)sum/8; /*求平均分*/
printf("平均分是 %f ",avg);
}
以上內容參考:網路-編程
❻ 求解一道編程題(百度面試題)
最後一個球一定是黑球,因此最後只剩下一個黑球的概率為100%.
將白球換成1,黑球換成0,取兩個球比較換成是兩個數做異或。題目就變成將100個0和100個1全部放一起做異或運算。異或運算滿足交換律,因此運算結果與次序無關。分成100個0一組和100個1一組,這兩組的運算結果都為0,相同,因此最後結果為0。
❼ 基礎編程題
LZ想要的是這種答案吧。。。。
//-------------------------------第一題
#include <stdio.h>
#include "e:\myc\zylib\zylib.h"
STRING GetString(STRING prompt);
double GetReal(STRING prompt);
int main()
{
double bookprice;
STRING bookname;
bookname=GetString("請輸入字元串:");
bookprice=GetReal("請輸入實數:");
printf("字元串為:%s\n",bookname);
printf("實數為:%.2f\n",bookprice);
}
STRING GetString(STRING prompt)
{
STRING name;
printf("%s",prompt);
name=GetStringFromKeyboard();
return name;
}
double GetReal(STRING prompt)
{
double price;
printf("%s",prompt);
price=GetRealFromKeyboard();
return price;
}
//-------------------------------------第二題
#include <stdio.h>
#include "e:\myc\zylib\zylib.h"
BOOL IsPrime(int n);
int main()
{
int n;
printf("請輸入一個整數:");
scanf("%d",&n);
if(n>2)
if(IsPrime(n))printf("%d是素數\n",n);
else printf("%d不是素數\n",n);
else printf("數據非法\n");
return 0;
}
BOOL IsPrime(int n)
{
int i;
for(i=2;i<n;i++)
if(n%i= =0) return FALSE;
return TRUE;
}
//--------------------------------第三題
#include <stdio.h>
#define TRUE 1
int gcd(int x,int y);
int main()
{
int m,n,max;
printf("請輸入兩個正整數:");
scanf("%d %d",&m,&n);
max=gcd(m,n);
printf("最大公約數為:%d\n",max);
return 0;
}
int gcd(int x,int y)
{
int r;
while(TRUE)
{
r=x%y;
if(r==0)break;
x=y;
y=r;
}
return y;
}
//--------------------------------第四題
#include <stdio.h>
#include "e:\myc\zylib\zylib.h"
typedef enum{sun,mon,tue,thi,wen,fri,sat}WEEKDAY;//定義枚舉類型
int GetInteger(STRING prompt);//輸入一下整數
int Count(int year,int month);//計算某年某月之前到2007年1月1日的天數
BOOL IsLeapYear(int n);//判斷某年是否是閏年
int month_day(int year,int month);//計算某個月的天數
void print(int year,int month,int total);//列印某年某月的日歷
void print1(WEEKDAY weekday);//列印某月的第1天
int main()
{
int year,month,total;
year=GetInteger("please input year:");
if(year<2007)
PrintErrorMessage(FALSE,"年份小於2007,錯誤\n");
month=GetInteger("please input month:");
total=Count(year,month);
print(year,month,total);
}
int GetInteger(STRING prompt)
{
int t;
printf("%s",prompt);
t=GetIntegerFromKeyboard();
return t;
}
int Count(int year,int month)
{
int s,i;
s=0;
for(i=2007;i<year;i++)
if(IsLeapYear(i))s+=366;
else s+=365;
for(i=1;i<month;i++)
s+=month_day(year,i);
return s;
}
BOOL IsLeapYear(int n)
{
return n%4==0&&n%100!=0||n%400==0;
}
int month_day(int year,int month)
{
int day;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 9:
case 10:
case 12:day=31;break;
case 2:day=28+IsLeapYear(year);break;
default:day=30;
}
return day;
}
void print(int year,int month,int total)
{
WEEKDAY weekday;
const WEEKDAY first=mon;
int i,day;
printf("%d-%d canlendar\n",year,month);
printf("-----------------------------------\n");
printf(" sun mon tue thi wen fri sat\n");
printf("-----------------------------------\n");
day=month_day(year,month);
for(i=1;i<=day;i++)
{
weekday=(WEEKDAY)((total+i+first-1)%7);
if(i==1)print1(weekday);
else if(weekday==sat)
printf("%4d\n",i);
else printf("%4d",i);
}
printf("\n------------------------------------\n");
}
void print1(WEEKDAY weekday)
{
if(weekday==0)printf("%4d",1);
else if(weekday==1)printf("%8d",1);
else if(weekday==2)printf("%12d",1);
else if(weekday==3)printf("%16d",1);
else if(weekday==4)printf("%20d",1);
else if(weekday==5)printf("%24d",1);
else if(weekday==6)printf("%28d\n",1);
}
//---------------------------------------
上面的一些文件路徑你自己改了,唉,其實我自己給你寫的那些演算法更好,。
❽ 編程題 編程將任意輸入的小寫字母轉化成大寫字母並輸出
大寫字母和小寫字母的ASSCII值差32,利用ASSCII值來轉換。小寫字母的ASCII碼比大寫字母的ASCII碼大32。
比如,大寫字母A的ASSCII值是65,那麼小寫a就是65+32=97。依次類推d其他字母。
如果用C++來寫:#include<iostream.h> void main(){ char c,c1; cin>>c;//從鍵盤輸入字母c1=c+32;//轉換cout<<c1;//輸出大寫字母}如果用java來寫就簡單,java自己就帶有這樣功能的函數:toUpperCase()。
(8)百度編程題擴展閱讀:
ASCII 碼使用指定的7 位或8 位二進制數組合來表示128 或256 種可能的字元。標准ASCII 碼也叫基礎ASCII碼,使用7 位二進制數(剩下的1位二進制為0)來表示所有的大寫和小寫字母,數字0 到9、標點符號,以及在美式英語中使用的特殊控制字元 。其中:
0~31及127(共33個)是控制字元或通信專用字元(其餘為可顯示字元),如控制符:LF(換行)、CR(回車)、FF(換頁)、DEL(刪除)、BS(退格)、BEL(響鈴)等;通信專用字元:SOH(文頭)、EOT(文尾)、ACK(確認)等;ASCII值為8、9、10 和13 分別轉換為退格、製表、換行和回車字元。
❾ C語言編程題目
#include<stdio.h>
int fun(int n)
{
int i;
if(n<=0)
{
return -1;
}
else if(n<2)
{
return 1;
}
else
{
for(i=2;i<n;i++)
{
if(n%i==0)
{
return 1;
}
}
return 0;
}
}
int main()
{
int i,sum=0,n,k;
scanf("%d %d",&n,&k);
for(i=n;i>1 && k>0;i--)
{
if(fun(i)==0)
{
printf("%d",i);
sum+=i;
k--;
if(k!=0&&i>2)
{
printf("+");
}
else
{
printf("=%d",sum);
break;
}
}
}
return 0;
}