當前位置:首頁 » 編程軟體 » 簡單的編程題

簡單的編程題

發布時間: 2022-07-13 01:33:37

『壹』 c語言簡單編程題,由提示編寫程序,謝謝大神的幫助!!十分感激!!

#include <stdio.h>


int max(int a[], int n) {

int i = 0,m;

m = a[0];

for(i = 1;i < n;i++)

if(a[i] > m) m = a[i];

return m;

}


void show(int a[],int n) {

int i;

for(i = 0; i < n; ++i)

printf("%d ",a[i]);

printf(" ");

}


int main() {

int a[] = {21,23,10,65,8,7,90,11,49,60,33,54,22,91,39,87,66,58,39,80};

int n = sizeof(a)/sizeof(a[0]);

printf("數組為: ");

show(a,n);

printf("最大元素為:%d ",max(a,n));

return 0;

}

『貳』 c語言程序設計簡單編程題

#include <stdio.h>
#include <string.h>
int main()
{
char iword;
char oword;

while(iword = getchar())
{
if(iword == '\n')
break;
oword = (iword - 95) % 26 + 97;
printf("%c",oword);
}
printf("\n");

return 0;
}
輸入:abcdefxyz
輸出:cdefghzab
此程序僅限輸入小寫字母。

『叄』 簡單的編程題

#include<stdio.h>
int main()
{
char str[30];
int i,length=0;
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
{
length++;
}
printf("長度是%d\n",length);
return 0;
}

『肆』 幫我解這條簡單編程題

按照題目要求編寫的計算加油費的C語言程序如下

#include<stdio.h>

int main(){

float a,sum=0;

int b;

char c;

scanf("%f %d %c",&a,&b,&c);

switch(b){

case 90:sum=6.95*a;break;

case 93:sum=7.44*a;break;

case 97:sum=7.93*a;break;

default:printf("輸入汽油品種錯誤");return 0;

}

if(c=='m'){

sum=sum*(1-0.05);

}else if(c=='e'){

sum=sum*(1-0.03);

}else{

printf("輸入服務類型錯誤");

return 0;

}

printf("%.2f",sum);

return 0;

}

『伍』 c語言簡單編程題

這個編程題目主要考慮的是對c語言中循環的理解。如果你清楚c語言中的for循環的用法只要按照題目要求寫是很好寫的。

『陸』 求幾道簡單C語言編程題答案

1.
#include
<stdio.h>
int
main()
{
int
y0,
m0,
d0,
y1,
m1,
d1,
age;
while
(
scanf("%d%d%d%d%d%d",
&y0,
&m0,
&d0,
&y1,
&m1,
&d1
)
){
age
=
y1
-
y0
-
1;
if
(
m1
>
m0
||
m1
==
m0
&&
d1
>=
d0
)
++age;
printf("年齡為:%d周歲!\n",
age);
}
return
0;
}
4.
#include
<stdio.h>
#include
<memory.h>
int
main()
{
char
p[500];
int
i,
count;
while
(
scanf("%s",
&p)
){
count
=
0;
for
(
i
=
0;
i
!=
strlen(p);
++i
)
if
(
p[i]
>=
'a'
&&
p[i]
<=
'z'
)
++count;
printf("%d\n",
count);
}
return
0;
}
2.
#include
<stdio.h>
int
main()
{
int
n;
while
(
scanf("%d",
&n)
){
if
(
(
n
&
1
)
==
0
)
printf("%d是偶數!\n",
n);
else
printf("%d,是奇數!\n",
n);
}
return
0;
}
第三題(用EFO結束)?EOF吧?EOF已經是文件尾,怎樣輸出結果?

『柒』 一個很簡單的編程題目~~

VC++6.0運行通過:
字元數組:
#include<stdio.h>
#include<iostream.h>
void main()
{char s1[100],s2[100];
int i=0,j=0;
gets(s1);
while(s1[i]!='\0')
{i++;
j++;}
cout<<"字元串長度為:"<<j<<endl;
for(i=0;i<j;i++)
s2[i]=s1[i];
cout<<"字元串s2為:";
for(i=0;i<j;i++)
cout<<s2[i];
cout<<endl;
}

字元指針:
#include<stdio.h>
#include<iostream.h>
void main()
{char *p,*q,s1[100],s2[100];
int i=0,j=0;
p=s1;
q=s2;
gets(p);
while(*(p+i)!='\0')
{i++;
j++;}
cout<<"字元串長度為:"<<j<<endl;
for(i=0;i<j;i++)
*(s2+i)=*(s1+i);
cout<<"字元串s2為:";
for(i=0;i<j;i++)
cout<<*(s2+i);
cout<<endl;
}

『捌』 一道簡單的java編程題

import java.text.ParseException;

import java.text.SimpleDateFormat;
//日期類
public class Date {
private String year;
private String month;
private String day;

public Date(String year, String month, String day) {
this.year = year;
this.month = month;
this.day = day;
}
public void format(){
System.out.println(day + "/" + month + "/" + year);
}

public void calculate(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
java.util.Date startDate = sdf.parse(year + "/" + "01" + "/" + "01");
java.util.Date inputDate = sdf.parse(year + "/" + month + "/" + day);
long resultDay = (inputDate.getTime() - startDate.getTime())/(24 * 1000 * 60 * 60);
System.out.println("第" + (resultDay + 1) + "天");
} catch (ParseException e) {
e.printStackTrace();
}
}
}
//測試類
public class Test {
public static void main(String[] args) {
Date date1 = new Date("2020","04","11");
Date date2 = new Date("2020","01","02");
date1.format();
date1.calculate();
date2.format();
date2.calculate();
}
}

『玖』 幾道簡單的C語言編程題,請高手幫忙

1、求1-3+5-7+……-99+101的值。
#include <stdio.h>
void main()
{
int i,element,sum=0;
for(i=1;i<=101;i+=2)
{
element=-i;sum=sum+element;sum=-sum;
}
printf("%d\n",sum);
}

2、編寫程序,判斷一個數是否是素數。
6n+1,6n-1法代碼
#include<stdio.h>
int main()
{
int data[5]={2,3,5,7};
int n;
scanf("%d",&n);
if(n==2||n==3||n==5||n==7)
{
printf("%d是素數\n",n);
}
else
{
if((n+1)%6==0||(n-1)%6==0)//n等於6k+1或6k-1
{
if(n%5&&n%7)
{
printf("%d是素數\n",n);
}
}
else printf("%d不是素數\n",n);
}
return 0;
}
3、輸入三個整數,求其中的最大值並輸出。
#include<stdio.h>
void main()
{
int a,b,c;
printf("輸入三個數:");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
printf("最大值為:%d",a);
else if(b>a&&b>c)
printf("最大值為:%d",b);
else
printf("最大值為:%d",c);

『拾』 一道簡單的c語言編程題

#include int main(){ double j,s=1,n=1; int a=0,b=1; printf("請輸入精度:"); scanf("%lf",&j); while(n>=j) { a+=1; b+=2; n=n*a/b; s=s+n; } printf("π≈%lf\n",2*s);} 不過輸入0.001的輸出和你的例子不一樣。僅供參考。你的代碼修改如下: #include int main(){ float pi,t,s,i,j; i=1;s=1;t=0;pi=1; scanf("%f",&t); while(s>=t) { s=s*i/(2*i+1); pi=pi+s; i=i+1; } printf("%7f",pi*2); return 0;} pi1和pi2沒有實際作用。

熱點內容
如何下載油猴腳本並安裝 發布:2025-02-08 15:02:12 瀏覽:595
硬體哪個配置性價比高 發布:2025-02-08 14:47:07 瀏覽:146
如何去掉僅限自動配置 發布:2025-02-08 14:37:55 瀏覽:708
壓縮空氣有啥 發布:2025-02-08 14:26:01 瀏覽:704
python輸入一個數 發布:2025-02-08 14:26:00 瀏覽:451
普惠e卡最初密碼是多少 發布:2025-02-08 14:21:57 瀏覽:477
亞索後q腳本 發布:2025-02-08 14:21:06 瀏覽:325
官方源碼 發布:2025-02-08 14:09:25 瀏覽:438
python過濾器 發布:2025-02-08 14:05:06 瀏覽:618
火山幣演算法 發布:2025-02-08 14:04:49 瀏覽:670