雙行道編程題
㈠ 兩道C++編程題
#include <iostream>
using namespace std;
int main()
{   
    int i=1,a,b,c,d,e,f;
 for (i=1;i<=30;i++)
 {
 a=i+1;
 b=a+2;
 c=b+3;
 d=c+4;
 e=d+5;
 f=e+6;
    if (i+a+b+c+d+e+f==105)
    cout <<"號碼為"<<i <<a <<b <<c <<d <<e <<f <<endl;
    }
 return 0;
}
㈡ 兩道java編程題
題一、
package Test;
import java.util.Scanner;
public class FirstOne {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("請輸入a");
		while (scanner.hasNext()) {
			double x = 0;
			double y = 0;
			// System.out.println("請輸入a");
			int a = scanner.nextInt();
			System.out.println("請輸入b");
			int b = scanner.nextInt();
			System.out.println("請輸入c");
			int c = scanner.nextInt();
			System.out.println("請輸入d");
			int d = scanner.nextInt();
			System.out.println("請輸入e");
			int e = scanner.nextInt();
			System.out.println("請輸入f");
			int f = scanner.nextInt();
			int tep = a * d - b * c;
			if (tep == 0) {
				System.out.println("方程無解");
			} else {
				double x1 = e * d - b * f;
				double y1 = a * f - e * c;
				x = x1 / tep;
				y = y1 / tep;
				System.out.println("x=" + x);
				System.out.println("y=" + y);
			}
			System.out.println("如果還要計算,請輸入a");
		}
	}
}
題二、可以用遞歸,但是我著急回家寫的bug就換了一種有點麻煩的,等回家給你追加遞歸的。
package Test;
import java.util.Scanner;
public class NextOne {
public static void main(String[] args) {
		
		Scanner  scanner=new Scanner(System.in);
		System.out.println("請輸入展示行數n");
		int n=scanner.nextInt();
		System.out.println("i\t\tm(i)");
		for (int i = 1; i <=n; i++) {
			System.out.println(i + "\t\t" + getNum(i));
		}
		
	}
	
	public static double num(int n){
			return  n/(double)(n+1);
	}
	
	public static double getNum(int n){
		double sum=0;
		for (int i = 1; i <= n; i++) {
			sum+=num(i);
		}
		return sum;
	}
}
㈢ 兩道C語言編程題,運行結果有問題或者不能運行,求高手指出!!謝謝!
while(s)
{
           a[i++]=s%10;s/=10;
} 
第一次循環結束後a[0]=5,s=0,i=1,然後退出循環列印a[0]=5,還有什麼不清楚的么?
 
第2個你范的錯誤是不要用「,」作為分隔符啊。scanf里沒有指定用","做分隔符你拿這個做什麼輸入分隔符啊
㈣ 兩道C語言編程題,求答案。。。求幫忙
//第一題
#include <stdio.h>
#include <string.h>
int main(void)
{
char f_name[24];
char str[100];
printf("please enther the file name:");
scanf("%s",str);
sprintf(f_name,"%s.txt",str);
FILE *fp=fopen(f_name,"w+");
printf("please enther the string:");
scanf("%s",str);
fprintf(fp,"%s%d",str,strlen(str));
return 0;
}
//第二題 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
int num;
char name[20];
int math;
int chin;
int eng;
int avg;
}student;
void cal_avg(student *stu)
{
int i=0;
for (i;i<5;i++)
{
stu[i].avg=(stu[i].chin+stu[i].math+stu[i].eng)/3;
}
}
int output(student *stu)
{
FILE *fp=fopen("stud.txt","w+");
if (fp==NULL)
{
printf("can't open file!");
return -1;
}
fwrite(stu,sizeof(student),5,fp);
return 1;
}
void input(student *stu)
{
int i=0;
for (i;i<5;i++)
{
stu[i].num=i+1;
printf("please enther the %dth student's name:",i+1);
scanf("%s",stu[i].name);
printf("please enther the %dth student's math grade:",i+1);
scanf("%d",&stu[i].math);
printf("please enther the %dth student's chin grade:",i+1);
scanf("%d",&stu[i].chin);
printf("please enther the %dth student's eng grade:",i+1);
scanf("%d",&stu[i].eng);
printf("/********************************************/\n");
}
}
int main(void)
{
student stu[5];
input(stu);
cal_avg(stu);
output(stu);
return 0;
}
㈤ 求這道編程題的過程。輸入有兩行。第1行是一個整數n(2≤n≤100000),表示一共有n個同學。
#include<bits/stdc++.h>
usingnamespacestd;
intn,a[200001];
intmain(){
scanf("%d",&n);
for(inti=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+n+1);
for(inti=1;i<=n;i++)printf("%d",a[i]);
}
㈥ 兩道編程題
作業都是一樣的?,改改類名和類成員名吧還有,前面有一個有同問了
publicclassTest1{
	publicstaticvoidmain(String[]args){
		//----TreeSet--------------
		Set<Student>set=newTreeSet<Student>();
		addTestData(set);
		printData(set);
		//---HashSet-----------
		set=newHashSet<Student>();
		addTestData(set);
		printData(set);
	}
	publicstaticvoidaddTestData(Setset){
		Students1=newStudent("d_name1",30);
		Students2=newStudent("a_name2",20);
		Students3=newStudent("c_name3",26);
		Students4=newStudent("b_name4",24);
		Students5=newStudent("c_name1",30);
		Students6=newStudent("c_name1",30);
		System.out.println(set.add(s1)==true?"加入":"重復");
		System.out.println(set.add(s2)==true?"加入":"重復");
		System.out.println(set.add(s3)==true?"加入":"重復");
		System.out.println(set.add(s4)==true?"加入":"重復");
		System.out.println(set.add(s5)==true?"加入":"重復");
		System.out.println(set.add(s6)==true?"加入":"重復");
	}
	publicstaticvoidprintData(Setset){
		for(Iterator<Student>iterator=set.iterator();iterator.hasNext();){
			Studentstudent=iterator.next();
			System.out.println(set.getClass().getName()+"姓名:"+student.name
					+"年齡:"+student.age);
		}
	}
}
{
	intage;
	Stringname;
	Student(Stringname,intage){
		this.age=age;
		this.name=name;
	}
	publicbooleanequals(Objectobj){
		//TODOAuto-generatedmethodstub
		Students=(Student)obj;
		return(age==s.age&&name.equals(s.name));
	}
	publicinthashCode(){
		//TODOAuto-generatedmethodstub
		returnage*name.hashCode();
	}
	publicintcompareTo(Objectobj){
		Studentstu=(Student)obj;
		//先按年齡排,後按姓名排
		intnum=newInteger(this.age).compareTo(newInteger(stu.age));
		returnnum==0?this.name.compareTo(stu.name):num;
	}
}publicclassTest3{
	publicstaticvoidmain(String[]args){
		try{
			SimpleDateFormatsf=newSimpleDateFormat("yyyy-MM-dd");
			printDate(sf.parse("2013-05-13"),sf.parse("2013-08-13"));
		}catch(ParseExceptione){
			System.out.println("輸入的日期格式錯誤");
		}
	}
	publicstaticvoidprintDate(Dated1,Dated2){
		CalendarstartDate=Calendar.getInstance();//開始日期
		startDate.setTime(d1);
		CalendarminDate=Calendar.getInstance();//允許的最小日期
		minDate.setTime(d2);
		minDate.add(Calendar.MONTH,-3);
		if(d2.getTime()>System.currentTimeMillis()){
			System.out.println("結束時間不能大於當前時間");
			return;
		}elseif(d1.getTime()>d2.getTime()){
			System.out.println("開始時間不能大於結束時間");
			return;
		}
		if(startDate.getTimeInMillis()<minDate.getTimeInMillis()){
			System.out.println("開始日期與結束日期不能超過3個月");
			return;
		}
		System.out.println("在范圍內");
	}
}
㈦ 關於兩道C語言編程題
#include
"stdio.h"
#include
"conio.h"
#define
N(n)
(1+(n))*(n)/2
//第一題
#define
Max(a,b)
(a)>(b)?(a):(b)
//第二題
//這種題目是要你注意給宏加(),防止使用代數式時出錯吧
int
main()
{
int
a,b;
int
n;
scanf("%d",&n);
printf("Add
form
1
to
%d
==%d\n",n,N(n));
printf("Please
Input
Two
Number\n");
scanf("%d",&a);
scanf("%d",&b);
printf("Max
Number
You
Input
Is:
%d\n",Max(a,b));
getch();
return
0;
}
㈧ 求大神幫我做兩道C語言編程習題~~
1#include<stdio.h>
#include<math.h>
void main()
{
	double x,y,z;
	printf("請輸入x的值:");
	scanf("%lf",&x);
	printf("請輸入y的值:");
	scanf("%lf",&y);
	if(x>0&&y>0)
		z=log(x)+log(y);
	else if(x<0&&y>0)
		z=sin(x)+sin(y);
	else if(x<0&&y<0)
		z=exp(2*x)+exp(3*y);
	else
		z=tan(x+y);
	printf("z=%lf\n",z);
}
2、#include<stdio.h>
   void main()
{
        float  money=0;
         int  year=1;
        printf("請輸入本金:");
        scanf("%f",&money);
    f:    printf("請輸入期限:");
        scanf("%d",&year);
       while(year<1)
           goto f;
        switch(year)
{
          case 1:money=money+money*12*0.063;break;
          case 2:money=money+money*24*0.066;break;
          case 3:money=money+money*36*0.069;break;
          case 4:money=money+money*48*0.069;break;
          case 5:money=money+money*60*0.075;break;
          case 6:money=money+money*72*0.075;break;
          case 7:money=money+money*84*0.075;break;
          case 8:money=money+money*96*0.084;break;
         default:money=money+money*12*year*0.084;break;
        }
         printf("您能得到的利息和本金合計為%f",money);
}
㈨ C語言中兩道編程題求救!
第一題:
#include<stdio.h>
//定義一個結構,記錄一個學生的信息
typedef struct{
char num[10];
char name[10];
int score[3];
} STUDENT;
int main()
{
FILE* file; //文件指針,用於打開文件和將數據寫入文件的一個介面
STUDENT student[5]; //5個學生
int i,j;
double ave[3]; //計算各門課平均分用的
printf("請依次輸入5個學生的信息:\n");
for (i=0; i<5; i++) //輸入信息
{
    scanf("%s%s",student[i].num,student[i].name);
    for (j=0; j<3; j++) scanf("%d",&student[i].score[j]);
}
for (i=0; i<3; i++) ave[i]=0;
for (j=0; j<5; j++)
   for (i=0; i<3; i++) ave[i]=ave[i]+student[j].score[i]; //先計算總分
for (i=0; i<3; i++) ave[i]=ave[i]/5.0; //算平均分
file=fopen("ZK1","w"); //打開一個文件,文件名叫ZK1
//下面使用fprintf將信息寫入磁碟文件中
for (i=0; i<5; i++)
{
    fprintf(file,"%s %s ",student[i].num,student[i].name);
    for (j=0; j<3; j++) fprintf(file,"%d ",student[i].score[j]);
    fprintf(file,"\n");
}
//寫入三門課的平均成績
fprintf("三門課的平均成績分別是:");
for (i=0; i<3; i++) fprintf(file,"%lf ",ave[i]);
fclose(file); //關閉,保存文件
return 0;
}
至於第二題的程序
第22行,你寫的是  scanf("%f',&s[i].avgcj); 
你把%f後面的雙引號打成單引號了
另外還有倒數第二行,你寫的是 printf("sname=%s sum=%f",s[j].sname sum); 
在s[j].sname和sum中間,你忘記打個逗號了
另外,你的struct定義寫得不對,應該這樣寫:
        typedef struct
        {
                int sno;
                char sname[20];
                float ywcj;
                float sxcj;
                float yucj;
                float avgcj;
        }student;
        student s[5];
