文档库 最新最全的文档下载
当前位置:文档库 › Fortran95程序设计习题答案

Fortran95程序设计习题答案

Fortran95程序设计习题答案
Fortran95程序设计习题答案

Fortran95程序设计习题答案

第四章 1.program main implicit none write(*,*) "Have a good time." write(*,*) "That's not bad." write(*,*) '"Mary" isn''t my name.' end program 2.program main real, parameter :: PI=3 implicit none.14159

real radius write(*,*) "请输入半径长" read(*,*) radius write(*,"(' 面积='f8. 3)") radius*radius*PI end program 3.program main implicit none real grades write(*,*) "请输入成绩" read(*,*)

grades write(*,"(' 调整后成绩为 'f8.3)") SQRT(grades)*10.0 end program 4.integer a,b real ra,rb a=2 b=3 ra=2.0 rb=3.0 write(*,*) b/a ! 输出1, 因为使用整数计算, 小数部分会无条件舍去 write(*,*) rb/ra ! 输出

1.5 5.program main implicit none type distance real meter, inch, cm end type type(distance) :: d write(*,*) "请输入长度:" read(*,*) d%meter d%cm = d%meter*100 d%inch = d%cm/

2.54 write(*,"(f8.3'米 ='f8.3'厘米

='f8.3'英寸')") d%meter, d%cm, d%inch end program 第五

章 1.program main implicit none integer money real tax write(*,*) "请输入月收入" read(*,*) money if ( money<1000 ) then tax = 0.03 else if ( money<5000) then tax = 0.1 else tax = 0.15 end if write(*,"(' 税金为 'I8)") nint(money*tax) end program 2.program main implicit none integer day character(len=20) :: tv write(*,*) "请输入星期几" read(*,*) day select case(day) case(1,4) tv = "新闻" case(2,5) tv = "电视剧" case(3,6) tv = "卡通" case(7) tv = "电影" case default write(*,*) "错误的输入" stop end select write(*,*) tv end program 3.program main implicit none integer age, money real tax write(*,*) "请输入年龄"

write(*,*) "请输入月收入" read(*,*) money if ( age<50 ) then

read(*,*) age

if ( money<1000 ) then tax = 0.03 else if ( money<5000 )then tax = 0.10 else tax = 0.15 end if else if ( money<1000 ) then tax = 0.5 else if ( money<5000 )then tax = 0.7 else tax = 0.10 end if end if

write(*,"(' 税金为 'I8)") nint(money*tax) end program 4.program main implicit none integer year, days logical mod_4, mod_100, mod_400

write(*,*) "请输入年份" read(*,*) year mod_4 = ( MOD(year,4) == 0 ) mod_100 = ( MOD(year,100) == 0 ) mod_400 = ( MOD(year,400) == 0 ) if ( (mod_4 .NEQV. mod_100) .or. mod_400 ) then days = 366 else days = 365 end if write(*,"('这一年有'I3'天')") days stop end program 第六章

1.program main implicit none integer i do i=1,5 write(*,*) "Fortran" end do stop end program

2.program main implicit none integer i,sum sum = 0 do i=1,99,2 sum = sum+i end do write(*,*) sum stop end program

3.program main implicit none integer, parameter :: answer = 45 integer, parameter :: max = 5 integer weight, i do i=1,max write(*,*) "请输入体重" read(*,*) weight if ( weight==answer ) exit end do if ( i<=max ) then write(*,*) "猜对了" else write(*,*) "猜错了" end if stop end program

4.program main implicit none integer, parameter :: max=10 integer i real item real ans ans = 1.0 item = 1.0 do i=2,max item = item/real(i) ans = ans+item end do write(*,*) ans stop end program

5.program main implicit none integer, parameter :: length = 79 character(len=length) :: input, output integer i,j write(*,*) "请输入一个字串" read(*,"(A79)") input j=1 do i=1, len_trim(input) if

( input(i:i) /= ' ' ) then output(j:j)=input(i:i) j=j+1 end if end do write(*,"(A79)") output stop end program 第七章 1.program main

implicit none integer, parameter :: max = 10 integer i integer ::

a(max) = (/ (2*i, i=1,10) /) integer :: t ! sum()是fortran库函数

write(*,*) real(sum(a))/real(max) stop end program

2.integer a(5,5) ! 5*5=25 integer b(2,3,4) ! 2*3*4=24 integer

c(3,4,5,6) ! 3*4*5*6=360 integer d(-5:5) ! 11 integer e(-3:3, -3:3) ! 7*7=49 3.program main implicit none integer, parameter :: max=10

integer f(max) integer i f(1)=0 f(2)=1 do i=3,max f(i)=f(i-1)+f(i-2) end do write(*,"(10I4)") f stop end program 4.program main implicit none integer, parameter :: size=10 integer :: a(size) = (/

5,3,6,4,8,7,1,9,2,10 /) integer :: i,j integer :: t do i=1, size-1 do j=i+1, size if ( a(i) < a(j) ) then ! a(i)跟a(j)交换 t=a(i)

a(i)=a(j) a(j)=t end if end do end do write(*,"(10I4)") a stop end

5.a(2,2) ! 1+(2-1)+(2-1)*(5) = 7 a(3,3) ! 1+(3-1)+(3-1)*(5) = 13 第八章1.program main implicit none real radius, area write(*,*) "请输入半径长" read(*,*) radius call CircleArea(radius, area) write(*,"(' 面积 =

'F8.3)") area stop end program subroutine CircleArea(radius, area) implicit none real, parameter :: PI=3.14159 real radius, area area = radius*radius*PI return end subroutine 2.program main implicit none

real radius real, external :: CircleArea write(*,*) "请输入半径长" read(*,*) radius write(*,"(' 面积 = 'F8.3)") CircleArea(radius) stop end program real function CircleArea(radius) implicit none real, parameter :: PI=3.14159 real radius CircleArea = radius*radius*PI return

end function 3.program main implicit none call bar(3) call bar(10) stop end program subroutine bar(length) implicit none integer, intent(in) :: length integer i character(len=79) :: string string=" " do i=1,length string(i:i)='*' end do write(*,"(A79)") string return end subroutine 4.program main implicit none integer, external :: add write(*,*)

add(100) end program recursive integer function add(n)

integer, intent(in) :: n if ( n<0 ) then sum=0 return else

result(sum) implicit none

if ( n<=1 ) then sum=n return end if sum = n + add(n-1) return end function 5.program main implicit none integer, external :: gcd

write(*,*) gcd(18,12) end program integer function gcd(A,B) implicit none integer A,B,BIG,SMALL,TEMP BIG=max(A,B) SMALL=min(A,B) do

while( SMALL /= 1 )

TEMP=mod(BIG,SMALL) if ( TEMP==0 ) exit BIG=SMALL SMALL=TEMP end

do gcd=SMALL return end function 6.program main use TextGraphLib implicit none integer, parameter :: maxx=60, maxy=20 real, parameter :: StartX=0.0, EndX=3.14159*2.0 real, parameter :: xinc = (EndX-

StartX)/(maxx-1) real x integer i,px,py call SetScreen(60,20) call SetCurrentChar('*') x=StartX do px=1,maxx py = (maxy/2)*sin(x)+maxy/2+1 call PutChar(px,py) x=x+xinc end docall UpdateScreen() stop end program 第九章 1.program main implicit

none character(len=79) :: filename character(len=79) :: buffer integer, parameter :: fileid = 10 integer count integer :: status = 0 logical alive write(*,*) "Filename:" read (*,"(A79)") filename

inquire( file=filename, exist=alive) if ( alive ) then open(unit=fileid, file=filename, & access="sequential", status="old") count = 0 do

while(.true.) read(unit=fileid, fmt="(A79)", iostat=status ) buffer

if ( status/=0 ) exit ! 没有资料就跳出循环 write(*,"(A79)") buffer

count = count+1 if ( count==24 ) then pause count = 0 end if end do else write(*,*) TRIM(filename)," doesn't exist." end if stop end

2.program main implicit none character(len=79) :: filename

character(len=79) :: buffer integer, parameter :: fileid = 10 integer i integer :: status = 0 logical alive write(*,*) "Filename:" read (*,"(A79)") filename inquire( file=filename, exist=alive) if ( alive ) then open(unit=fileid, file=filename, & access="sequential",

status="old") do while(.true.) read(unit=fileid, fmt="(A79)",

iostat=status ) buffer if ( status/=0 )

exit ! 没有资料就跳出循环 do i=1, len_trim(buffer) buffer(i:i) = char( ichar(buffer(i:i))-3 ) end do write(*,"(A70)") buffer end

do else write(*,*) TRIM(filename)," doesn't exist." end if stop end

3.program main implicit none type student integer chinese, english, math, science, social, total end type type(student) :: s, total integer, parameter :: students=20, subjects=5 integer i

open(10,file="grades.bin",access="direct",recl=1) write(*,"(7A10)") "座号","中文","英文","数学","自然","社会","总分" total =

student(0,0,0,0,0,0) do i=1, students read(10,rec=(i-1)*subjects+1)

s%chinese read(10,rec=(i-1)*subjects+2) s%english read(10,rec=(i-

1)*subjects+3) s%math read(10,rec=(i-1)*subjects+4) s%science

read(10,rec=(i-1)*subjects+5) s%social s%total =

s%chinese+s%english+s%math+s%science+s%social total%chinese =

total%chinese+s%chinese total%english = total%english+s%english

total%math = total%math+s%math total%science = total%science+s%science total%social = total%social+s%social total%total = total%total+s%total write(*,"(7I10)") i, s end do write(*,"(A10,6F10.3)") "平均", & real(total%chinese)/real(students),&

real(total%english)/real(students),&

real(total%math)/real(students),&

real(total%science)/real(students),&

real(total%social)/real(students),& real(total%total)/real(students) stop end 4.program main implicit none character(len=79) :: filename character(len=79) :: buffer integer, parameter :: fileid = 10 integer i integer :: status = 0 logical alive write(*,*) "Filename:" read (*,"(A79)") filename inquire( file=filename, exist=alive) pen(unit=fileid, file=filename, & access="sequential", if ( alive ) then o

status="old") do while(.true.) read(unit=fileid, fmt="(A79)",

iostat=status ) buffer if ( status/=0 ) exit ! 没有数据就跳出循环 do

i=1,

len_trim(buffer) buffer(i:i) = char( ichar(buffer(i:i))-(mod(i-

1,3)+1) ) end do write(*,"(A70)") buffer end do else write(*,*)

TRIM(filename)," doesn't exist." end if stop end 5.module typedef type

student integer :: num integer :: Chinese, English, Math, Natural, Social integer :: total integer :: rank end type end module program main use typedef implicit none integer, parameter :: fileid=10 integer, parameter :: students=20 character(len=80) :: tempstr

type(student) :: s(students) ! 储存学生成绩 type(student) :: total ! 计算平均分数用 integer i, num, error open(fileid,

file="grades.txt",status="old", iostat=error) if ( error/=0 ) then write(*,*) "Open grades.txt fail." stop end if read(fileid, "(A80)") tempstr ! 读入第一行文字 total=student(0,0,0,0,0,0,0,0) ! 用循环读入每位学生的成绩 do i=1,students read(fileid,*) s(i)%num, s(i)%Chinese,

s(i)%English, & s(i)%Math, s(i)%Natural, s(i)%Social ! 计算总分

s(i)%Total = s(i)%Chinese + s(i)%English + & s(i)%Math + s(i)%Natural + s(i)%Social ! 累加上各科的分数, 计算各科平均时使用 total%Chinese = total%Chinese +

s(i)%Chinese total%English = total%English + s(i)%English

total%Math = total%Math + s(i)%Math total%Natural = total%Natural +

s(i)%Natural total%Social = total%Social + s(i)%Social total%Total = total%Total + s(i)%Total end do call sort(s,students) ! 重新输出每位学生成绩 write(*,"(8A7)") "座号","中文","英文","数学","自然","社会","总分","名次" do i=1,students write(*,"(8I7)") s(i) end do ! 计算并输出平圴分数 write(*,"(A7,6F7.1)") "平均", &

real(total%Chinese)/real(students),&

real(total%English)/real(students),&

real(total%Math) /real(students),&

real(total%Natural)/real(students),& real(total%Social)

/real(students),& real(total%Total) /real(students) stop end program subroutine sort(s,n) use typedef implicit none integer n

type(student) :: s(n), t integer i,j do i=1,n-1 do j=i+1,n if

( s(i)%total < s(j)%total ) then t = s(i) s(i)=s(j) s(j) = t end if end do end do forall(i=1:n) s(i)%rank = i end forall end subroutine 第十章 1.integer(kind=4) ::

4 bytes real(kind=4) :: b ! 4 bytes real(kind=8) :: c ! 8 bytes character(len=10) :: a !

str ! 10 bytes integer(kind=4), pointer :: pa ! 4 bytes

real(kind=4), pointer :: pb ! 4 bytes real(kind=8), pointer :: pc ! 4 bytes character(len=10), pointer :: pstr ! 4 bytes type student

integer Chinese, English, Math end type type(student) :: s ! 12 bytes type(student), pointer :: ps ! 4 bytes 2.integer, target :: a = 1 integer, target :: b = 2 integer, target :: c = 3 integer, pointer :: p p=>a write(*,*) p ! 1 p=>b write(*,*) p ! 2 p=>c p=5 write(*,*) c ! 5

3.module linklist type student integer :: num integer :: Chinese, English, Math, Science, Social end type type datalink type(student) :: item type(datalink), pointer :: next end type contains function SearchList(num, head) implicit none integer :: num type(datalink), pointer :: head, p type(datalink), pointer :: SearchList p=>head

nullify(SearchList) do while( associated(p) ) if ( p%item%num==num ) then SearchList => p return end if p=>p%next end do return end function end module linklist program ex1016 use linklist implicit none

character(len=20) :: filename character(len=80) :: tempstr

type(datalink), pointer :: head type(datalink), pointer :: p

type(student), allocatable :: s(:) integer i,error,size write(*,*) "filename:" read(*,*) filename open(10, file=filename, status="old", iostat=error) if ( error/=0 ) then write(*,*) "Open file fail!" stop end if allocate(head) nullify(head%next) p=>head size=0 read(10,

"(A80)") tempstr ! 读入第一行字符串, 不需要处理它 ! 读入每一位学生的成绩do while(.true.) read(10,fmt=*, iostat=error) p%item if ( error/=0 )

exit size=size+1 allocate(p%next, stat=error) ! 新增下一个数据 if

( error/=0 ) then write(*,*) "Out of memory!" stop end if p=>p%next ! 移动到链表的下一个数据 nullify(p%next) end do write(*,"('总共有',I3,'

位学生')") size allocate( s(size) ) p=>head do i=1,size s(i)=p%item

p=>p%next end do do while(.true.) write(*,*) "要查询几号同学的成绩?" read (*,*) i if ( i<1 .or. i>size ) exit ! 输入不合理的座号

write(*,"(5(A6,I3))") "中文",s(i)%Chinese,& "英文",s(i)%English,& "数学",s(i)%Math,& "自然",s(i)%Science,& "社会",s(i)%Social end do write(*,"('座号',I3,'不存在, 程序结束.')") i stop end program 4.module typedef implicit none type :: datalink integer :: i type(datalink), pointer :: next end type datalink end module typedef program ex1012 use typedef implicit none type(datalink) , pointer :: p, head, next

integer :: i,n,err write(*,*) 'Input N:' read(*,*) n allocate( head ) head%i=1 nullify(head%next) p=>head do i=2,n allocate( p%next,

stat=err ) if ( err /= 0 ) then write(*,*) 'Out of memory!' stop end

if p=>p%next p%i=i end do nullify(p%next) p=>head do

while(associated(p)) write(*, "(i5)" ) p%i p=>p%next end do ! 释放链

表的存储空间 p=>head do while(associated(p)) next => p%next

deallocate(p) p=>next end do stop end program 第十一章 1.module

utility implicit none interface area module procedure CircleArea module procedure RectArea end interface contains real function CircleArea(r) real, parameter :: PI=3.14159 real r

CircleArea = r*r*PI return end function real function RectArea(a,b) real a,b RectArea = a*b return end function end module program main use UTILITY implicit none write(*,*) area(1.0) write(*,*) area(2.0,3.0)

stop end program 2.module time_utility implicit none type :: time

integer :: hour,minute,second end type time interface operator(+) module procedure add_time_time end interface contains function

add_time_time( a, b ) implicit none type(time) :: add_time_time

type(time), intent(in) :: a,b integer :: seconds,minutes,carry

seconds=a%second+b%second carry=seconds/60

minutes=a%minute+b%minute+carry carry=minutes/60

add_time_time%second=mod(seconds,60)

add_time_time%minute=mod(minutes,60)

add_time_time%hour=a%hour+b%hour+carry return end function

add_time_time subroutine input( a ) implicit none type(time),

intent(out) :: a write(*,*) " Input hours:" read (*,*) a%hour

write(*,*) " Input minutes:" read (*,*) a%minute write(*,*) " Input seconds:" read (*,*) a%second return end subroutine input subroutine output( a ) implicit none type(time), intent(in) :: a write(*, "(I3,'

hours',I3,' minutes',I3,' seconds')" ) a%hour,a%minute,a%second return end subroutine output end module time_utility program main use

time_utility implicit none type(time) :: a,b,c call input(a) call

input(b) c=a+b call output(c) stop end program main 3.module

rational_utility implicit none private public :: rational, &

operator(+), operator(-), operator(*),& operator(/),

assignment(=),operator(>),& operator(<), operator(==), operator(/=),& output, input type :: rational integer :: num, denom end type rational interface operator(+) module procedure rat__rat_plus_rat end interface interface operator(-)

module procedure rat__rat_minus_rat end interface interface

operator(*) module procedure rat__rat_times_rat end interface

interface operator(/) module procedure rat__rat_div_rat end interface interface assignment(=) module procedure rat_eq_rat module procedure

int_eq_rat module procedure real_eq_rat end interface interface operator(>) module procedure rat_gt_rat end interface interface operator(<) module procedure rat_lt_rat end interface interface operator(==) module procedure rat_compare_rat end interface interface operator(/=) module procedure rat_ne_rat end interface contains

function rat_gt_rat(a,b) implicit none logical :: rat_gt_rat

type(rational), intent(in) :: a,b real :: fa,fb

fa=real(a%num)/real(a%denom)

fb=real(b%num)/real(b%denom) if ( fa > fb ) then rat_gt_rat=.true. else rat_gt_rat=.false. end if return end function rat_gt_rat

function rat_lt_rat(a,b) implicit none logical :: rat_lt_rat

type(rational), intent(in) :: a,b real :: fa,fb

fa=real(a%num)/real(a%denom) fb=real(b%num)/real(b%denom) if ( fb > fa ) then rat_lt_rat=.true. else rat_lt_rat=.false. end if return end function rat_lt_rat function rat_compare_rat(a,b) implicit none

logical :: rat_compare_rat type(rational), intent(in) :: a,b

type(rational) :: c c=a-b if ( c%num == 0 ) then

rat_compare_rat=.true. else rat_compare_rat=.false. end if return

end function rat_compare_rat function rat_ne_rat(a,b) implicit none logical :: rat_ne_rat type(rational), intent(in) :: a,b

type(rational) :: c c=a-b if ( c%num==0 ) then rat_ne_rat=.false.

else rat_ne_rat=.true. end if return end function rat_ne_rat

subroutine rat_eq_rat( rat1, rat2 ) implicit

none type(rational), intent(out):: rat1 type(rational),

intent(in) :: rat2 rat1%num = rat2%num rat1%denom = rat2%denom return end subroutine rat_eq_rat subroutine int_eq_rat( int, rat ) implicit none integer, intent(out):: int type(rational), intent(in) :: rat int = rat%num / rat%denom return end subroutine int_eq_rat subroutine

real_eq_rat( float, rat ) implicit none real, intent(out) :: float

type(rational), intent(in) :: rat float = real(rat%num) /

real(rat%denom) return end subroutine real_eq_rat function reduse( a ) implicit none type(rational), intent(in) :: a integer :: b

type(rational) :: reduse b=gcv_interface(a%num,a%denom) reduse%num =

a%num/b reduse%denom = a%denom/b return end function reduse function

gcv_interface(a,b) implicit none integer, intent(in) :: a,b integer :: gcv_interface if ( min(a,b) .eq. 0 ) then gcv_interface=1 return end if if (a==b) then gcv_interface=a return else if ( a>b ) then

gcv_interface=gcv(a,b) else if ( a

end if return end function gcv_interface recursive function gcv(a,b) result(ans) implicit none integer, intent(in) :: a,b integer :: m integer :: ans m=mod(a,b) select case(m) case(0) ans=b return

case(1) ans=1 return case default ans=gcv(b,m) end select return end function gcv function rat__rat_plus_rat( rat1, rat2 ) implicit none type(rational) :: rat__rat_plus_rat type(rational), intent(in) :: rat1,rat2 type(rational) :: act act%denom= rat1%denom * rat2%denom act%num = rat1%num*rat2%denom + rat2%num*rat1%denom rat__rat_plus_rat = reduse(act) return end function rat__rat_plus_rat function

rat__rat_minus_rat( rat1, rat2 ) implicit none type(rational) ::

rat__rat_minus_rat type(rational), intent(in) :: rat1, rat2

type(rational) :: temp temp%denom = rat1%denom*rat2%denom temp%num =

rat1%num*rat2%denom - rat2%num*rat1%denom rat__rat_minus_rat = reduse( temp ) return end function rat__rat_minus_rat

function rat__rat_times_rat( rat1, rat2 ) implicit none

type(rational) :: rat__rat_times_rat type(rational), intent(in) :: rat1, rat2 type(rational) :: temp temp%denom = rat1%denom* rat2%denom temp%num = rat1%num * rat2%num rat__rat_times_rat = reduse(temp)

return end function rat__rat_times_rat function rat__rat_div_rat( rat1, rat2 ) implicit none type(rational) :: rat__rat_div_rat

type(rational), intent(in) :: rat1, rat2 type(rational) :: temp

temp%denom = rat1%denom* rat2%num temp%num = rat1%num * rat2%denom

rat__rat_div_rat = reduse(temp) return end function rat__rat_div_rat subroutine input(a) implicit none type(rational), intent(out) :: a

write(*,*) "分子:" read(*,*) a%num write(*,*) "分母:" read(*,*)

a%denom return end subroutine input subroutine output(a) implicit none type(rational), intent(in) :: a if ( a%denom/=1 ) then write(*, "(' (',I3,'/',I3,')' )" ) a%num,a%denom else write(*, "(I3)" ) a%num end if return end subroutine output end module rational_utility program main use rational_utility implicit none type(rational) :: a,b,c call input(a) call input(b) c=a+b write(*,*) "a+b=" call output(c) c=a-b

write(*,*) "a-b=" call output(c) c=a*b write(*,*) "a*b=" call output(c)

c=a/b write(*,*) "a/b=" call output(c) if (a>b) write(*,*) "a>b" if

(a

vector_add_vector end interface interface operator(-) module procedure

vector_sub_vector end interface interface operator(*) module procedure real_mul_vector module procedure vector_mul_real module procedure vector_dot_vector end interface interface operator(.dot.) module procedure vector_dot_vector end interface contains type(vector) function

vector_add_vector(a,b) type(vector), intent(in) :: a,b

vector_add_vector = vector(a%x+b%x, a%y+b%y) end function type(vector) function

vector_sub_vector(a,b) type(vector), intent(in) :: a,b

vector_sub_vector = vector(a%x-b%x, a%y-b%y) end function type(vector) function real_mul_vector(a,b) real, intent(in) :: a type(vector), intent(in) :: b real_mul_vector

= vector( a*b%x, a*b%y ) end functiontype(vector) function

vector_mul_real(a,b) type(vector), intent(in) :: a real, intent(in) :: b vector_mul_real = real_mul_vector(b,a) end function real function vector_dot_vector(a,b) type(vector), intent(in) :: a,b

vector_dot_vector = a%x*b%x + a%y*b%y end function subroutine

output(vec) type(vector) :: vec write(*,"('('F6.2','F6.2')')") vec end subroutine end module program main use vector_utility implicit none type(vector) a,b,c a=vector(1.0, 2.0) b=vector(2.0, 1.0) c=a+b call output(c) c=a-b call output(c) write(*,*) a*b end program main

Fortran95习题答案

第四章 1.program main implicit none write(*,*) "Have a good time." write(*,*) "That's not bad." write(*,*) '"Mary" isn''t my name.' end program 2.program main real, parameter :: PI=3 implicit none.14159 real radius write(*,*) "请输入半径长" read(*,*) radius write(*,"(' 面积='f8. 3)") radius*radius*PI end program 3.program main implicit none real grades write(*,*) "请输入成绩" read(*,*) grades write(*,"(' 调整后成绩为'f8.3)") SQRT(grades)*10.0 end program 4.integer a,b real ra,rb a=2 b=3 ra=2.0 rb=3.0 write(*,*) b/a ! 输出1, 因为使用整数计算, 小数部分会无条件舍去write(*,*) rb/ra ! 输出1.5 5.program main implicit none type distance real meter, inch, cm end type type(distance) :: d write(*,*) "请输入长度:" read(*,*) d%meter d%cm = d%meter*100 d%inch = d%cm/2.54 write(*,"(f8.3'米='f8.3'厘米='f8.3'英寸')") d%meter, d%cm, d%inch end program 第五章 1.program main

程序设计基础试题库

练习题一Visual FoxPro 基础 、选择题 1. 关系数据库管理系统应能实现的专门关系运算包括___c __________ A 显示、打印、制表B关联、更新、排序 C 选择、投影、连接D排序、索引、统计 2. 关系是指__b__。 A 属性的集合B元组的集合 C 实例的集合 D 字段的集合 3. 如果把学生看成实体,某个学生的姓名叫“杨波”,则“杨波”应看成是___b ______ 。 A)属性型B )属性值C )记录型D )记录值 4. 关系数据库系统中所使用的数据结构是 _______ d ___ 。 A)图B )树C )表格D )二维表 5. 对表进行水平方向的分割用的运算是 _______ b ___ 。 A)交B )选择C )投影D )连接 6. 下列数据库技术的术语与关系模型的术语的对应关系中_______ d _____ 是正确的。 A)实例与关系 B )字段与元组C )记录与属性 D )记录类型与关系模式 7. 下列关于数据库系统的叙述中,正确的是 _____ c _____ 。 A)数据库系统中数据的一致性是指数据类型一致 B)数据库系统只是比文件系统管理的数据更多 C)数据库系统减少了数据冗余 D数据库系统避免了数据冗余 8. 关系数据模型 ______ d ___ 。 A)只能表示实体间的1:1联系 B)只能表示实体间的1:n C只能表示实体间的m:n D 可以表示实体间的上述三种联系 9. 在一个关系中如果有这样一个属性存在,它的值能惟一地标识关系中的每一个元组,称

这个属性为 _____ a____ 。 A)关键字B )主属性C )数据项D )主属性值 10. 关系数据库管理系统中的元组是______ b ____ 。 A)关系中的垂直方向的列 B )关系中的水平方向的行 C属性或属性的组合 D )以上的答案均不正确 11. 从数据库的整体结构看,数据库系统采用的数据模型有_________ a __ 。 A)层次模型、网状模型和关系模型 B)层次模型、网状模型和环状模型 C)网状模型、链状模型和层次模型 D链状模型、关系模型和层次模型 12. 设有属性A B、C D以下表示中不是关系的是___________ d__。 A)R( A) B )R( A, B)C )R (A, B, C, D) D )R (A X B X C X D) 13. 若实体间联系是M N的,则将联系类型_________ a___ 。 A)也转换为关系模型 B)属性加入任一个关系模式中 C)属性加入N端实体类型相应的关系模式中 D)属性加入M端实体类型相应的关系模式中 14. 数据库系统的构成为数据库、计算机硬件系统、用户和________ a ____ 。 A 数据库管理系统 B 操作系统 C 数据集合 D 文件系统 15. 层次型、网状型和关系型数据库划分原则是________ c ___ 。 A 文件大小 B 记录长度 C 数据之间的联系 D 联系的复杂程度 16. 在数据库设计中用关系模型来表示实体和实体之间的联系,关系模型的结构是 _____ d ___ 。 A 封装结构 B 层次结构 C 网状结构 D 二维表结构 17. 在关系模型中,实现“关系中不允许出现相同的元组”的约束是通过__a ________ 。 A 主键 B 超键 C 外键 D 候选键 18. 层次模型不能直接表示 ______ b __ 关系。 A 1:1 B m:n C 1:m D 1:1 和1:m 19. DBAS旨的是_____ d____ 。

《程序设计基础》试卷B及答案

黄淮学院计算机科学系2007-2008学年度第一学期 期末考试《程序设计基础》B 卷 注意事项:本试卷适用于计科系06级本科计算机科学与技术专业学生。 1.__ ____函数是程序启动时惟一的入口。 2.算法的复杂性包含两方面: 和 。 3.已知 char c= 'a' ; int x=2,k; 执行语句k=c&&x++ ; 则x 为 ,k 为 。 4.数值0x34对应的十进制为 。 5.已知int a ; 则表达式”(a=2*3 , 3*8), a*10”的结果为_ _ ____,变量a 的值为___ ___。 6.面向对象程序开发步骤为: 、 和面向对象实现。 1.下列程序设计语言中( )是面向对象语言。 A. FORTRAN B. C 语言 C. C++ D. 汇编语言 2.下列关于注释的说法哪个是错误的( )。 A. 注释不是程序中的可执行语句 B. 注释对于程序的执行有很重要的意义 C. 注释将在程序的编译阶段被编译器剔除 D. 编程时在程序中添加适当的注释是一个良好的编程风格 3.算法设计应该遵守( )的设计原则。 A. 自底向上,逐步求精 B. 自顶向下,逐步求精 C. 自底向上,同步扩展 D. 自顶向下,同步扩展 4.下列语句执行后a 的值为( )。 int a=4, &z=a, k=3; a=k; z+=2; k++; A. 0 B. 4 C. 1 D. 5 5.以下程序执行后,屏幕输出为( )。 #include “iostream.h ” void fun(int d) {d++;} void main() { int d=3; fun(d); d++; cout<=’a ’)&&(d<=’z ’) B. ‘a ’<=d<=’z ’ C. (d>=’a ’)||(d<=’z ’) D. ‘A ’<=d<=’Z ’ 8.已知:int k=7, x=12; 则执行语句( )后x 的值为0。 A. x+=k-x%5; B. x+=(x-k%5); C. x%=(k-=5); D. (x-=k)-(k+=5); 9.运行下列程序,其输出结果为( )。 #include “iostream.h ” void main() { int x(5),y(5),z(5); y--&&++x&&z--||y++; cout<

程序设计基础试题和答案解析二

《程序设计基础》考试试卷二 1.1966年,Bohra和Jacopini提出的三种基本程序设计结构是:________ A.if、while和for; B. switch、do-while和for; C.while、do-while和for; D.顺序结构、分支结构和循环结构。 2.算法的特征不包括:______。 A.有穷性 B.可行性 C.确定性 D.有1个或者多个输入。 3.C语言源程序的基本组成单位是______。 A.函数 B. 语句 C. 声明和语句 D. 文件 4.下列标识符中,只有______是合法的。 A.if B. 3ab C. Int D. A-4 5.下列常量中,只有______是合法的。 A.3e-0.3 B. ‘abc’ C. 02a1 D. ‘\377’ 6.下列说法中正确的是:______。 A.C语言中的for语句的三个表达式都可以省略,而且分号也可以省略。 B.宏替换比函数调用的执行速度慢。 C.实质上,C语言中的指针就是一个变量的地址。 D.C语言中的任何函数都可以由程序员命名。 7.C语言中,运算对象必须是整型的运算符是_______。 A./ B. % C. + D. - 8.以下叙述中错误的是_______。 A.C语句必须以分号结束 B.复合语句在语法上被看作一条语句 C.空语句出现在任何位置都不会影响程序运行 D.赋值表达式末尾加分号就构成赋值语句 9.以下叙述中正确的是_______。 A.调用printf函数时,必须要有输出项 B.使用putchar函数时,必须在之前包含头文件stdio.h C.在C语言中,整数可以以十二进制、八进制或十六进制的形式输出 D.调用getchar函数读入字符时,可以从键盘上输入字符所对应的ASCII码10.以下关于函数的叙述中正确的是_______。 A.每个函数都可以被其它函数调用(包括main函数) B.每个函数都可以被单独编译 C.每个函数都可以单独运行 D.在一个函数内部可以定义另一个函数 11.有以下程序段typedef struct NODE{ int num; struct NODE *next;

程序设计基础练习题(全答案版)

《程序设计基础——C#.NET》练习 参考答案: 一、选择题 https://www.wendangku.net/doc/7c8667916.html,的目的就是将____A____作为新一代操作系统的基础,对互联网的设计思想进行扩展。A.互联网 B. Windows C. C# D. 网络操作系统 2.假设变量x的值为10,要输出x值,下列正确的语句是__C__。 A.System.Console.writeline(“x”) B. System.Cosole.WriteLine(“x”) C. System.Console.WriteLine(“x={0}”,x) D. System.Console.WriteLine(“x={x}”) 3.要退出应用程序的执行,应执行下列的_A___语句。 A. Application.Exit(); B. Application.Exit; C. Application.Close(); D. Application.Close; 4.关于C#程序的书写,下列不正确的说法是__D________。 A.区分大小写 B.一行可以写多条语句 C.一条语句可以写成多行 D.一个类中只能有一个Main()方法,因此多个类中可以有多个Main()方法 5. 在C#语言中,下列能够作为变量名的是__C__。 A.if B. 3ab C. b_3a D. a-bc 7. 能正确表示逻辑关系“a≥5或a≤0”的C#语言表达方式是__D__。 A.a>=5 or a<=0 B. a>=5|a<=0 C. a>=5&&a<=0 D. a>=5||a<=0 8. 以下程序的输出结果是___C_____。 A. 5 B. 4 C. 6 D. 不确定 9. If语句后面的表达式应该是__A___。 A.逻辑表达式 B. 条件表达式 C. 算术表达式 D. 任意表达式10.有如下程序:

计算机程序设计基础习题册(含答案)

《计算机程序设计基础》 习 题 册

班级学号姓名成绩一、单选题 1.C++源程序文件的默认扩展名为A。 A) cpp B) exe C) obj D) lik 2.由C++源程序文件编译而成的目标文件的默认扩展名为C。 A) cpp B) exe C) obj D) lik 3.由C++目标文件连接而成的可执行文件的默认扩展名为B。 A) cpp B) exe C) obj D) lik 4.编写C++程序一般需经过的几个步骤依次是B。 A)编译、编辑、连接、调试 B)编辑、编译、连接、调试 C)编译、调试、编辑、连接 D)编辑、调试、编辑、连接 5.程序中主函数的名字为 A 。 A) main B) MAIN C) Main D) 任意标识符 6.下面四个选项中,均是不合法的用户标识符的选项的是C。 A) A p_o do B)float lao _A C)b-a goto int D)_123 temp INT 7.下列变量名中合法的是C。 A) B)C)Tom B) 3a66 C) _6a7b D) $ABC 8.存储以下数据,占用存储字节最多的是 D 。 A) 0 B) ‘0’ C) “0” D) 0.0 9.在C++语言中,字符型数据在内存中的存储形式是D。 A) 补码 B) 反码 C) 原码 D) ASCII码 10.若有说明语句:char c =’\072’;则变量c A。 A) 包含1个字符 B) 包含2个字符 C) 包含3个字符 D) 说明不合法,变量的值不确定 二、填空题 1.C++头文件和源程序文件的扩展名分别为.h和.cpp 。 2.C++语言规定,标识符只能由字母、数字、下划线三种字符组成,而且第一个字符必须是字母或下划线。 3.一条表达式语句必须以__分号_;___作为结束符。 4.用于从键盘上为变量输入值的标准输入流对象是___cin____;用于输出表达式值的标准输出流对象是__cout____。 5.在一个C++程序文件中,若要包含另外一个头文件或程序文件,则应使用以_#include___标识符开始的预处理命令

计算机程序设计基础习题册含答案

《计算机程序设计基础》 计算机程序设 计基础_基础知识(一) 班级 学号 姓名 成 绩 一、 单选题 习题册

1.C++源程序文件的默认扩展名为A。 2.A) cpp B) exe C) obj D) lik 3.由C++源程序文件编译而成的目标文件的默认扩展名为C。 4.A) cpp B) exe C) obj D) lik 5.由C++目标文件连接而成的可执行文件的默认扩展名为B。 6.A) cpp B) exe C) obj D) lik 7.编写C++程序一般需经过的几个步骤依次是B。 8.A)编译、编辑、连接、调试 B)编辑、编译、连接、调试 C)编译、调试、编辑、连接 D)编辑、调试、编辑、连接9.程序中主函数的名字为 A 。 10.A) main B) MAIN C) Main D) 任意标识 符 11.下面四个选项中,均是不合法的 用户标识符的选项的是 C。 12.A) A p_o do B)float lao _A C)b-a goto int D)_123 temp INT 13.下列变量名中合法的是 C。 14.A) B)C)Tom B) 3a66 C) _6a7b D) $ABC 15.存储以下数据,占用存储字节最 多的是 D 。 16.A) 0 B) ‘0’

C) “0” D) 17.在C++语言中,字符型数据在内存中的存储形式是D。 18.A) 补码 B) 反码 C) 原码 D) ASCII码 19.若有说明语句:char c =’\072’;则变量c A。 20.A) 包含1个字符 B) 包含2个字符 C) 包含3个字符 D) 说明不合法,变量的值不确定 二、填空题 1.C++头文件和源程序文件的扩展名分别为.h和.cpp 。 2.C++语言规定,标识符只能由字母、数字、下划线三种字符组成,而且第一个字符必须是字母或下划线。 3.一条表达式语句必须以__分号_;___作为结束符。 4.用于从键盘上为变量输入值的标准输入流对象是___cin____;用于输出表达式值的标准输出流对象是__cout____。 5.在一个C++程序文件中,若要包含另外一个头文件或程序文件,则应使用以_#include___标识符开始的预处理命令 计算机程序设计基础_基础知识(二) 班级学号姓名成绩 一、单选题 1.下列哪一个是C++语言中合法的变量 C A) 8ZSe B) ±A0 C) X0_2 D) ’x0’2.已知ch是字符型变量,下面不正确的赋值语句是A 3.A) ch='a+b' B) ch='\0'

程序设计基础试题_03_答案.doc

学院领导 审批并签名 A / B卷 广州大学 学年第学期考试卷 课程高级语言程序设计考试形式(开/闭卷,考试/查)学院系专业班级学号姓名 分数 评分 一:选择题(每题3分,共60分) (1)若有以下定义: char a; int b; float c; double d; 则表达式a*b+d-c值的类型为(A)

A) double B) float C) int D) char (2)设a=1,b=2,c=3,d=4,则表达式:a=10 or a<=0 B)a>=10│a<=0 C)a>=10││a<=0 D)a>=10 ││ a<=0 (7)下列可 作为C语言赋值语句的是(C) A) x=3,y=5 B) a=b=6 C) i--; D) y=int(x); (8)设i是int型变量,f是float型变量,用下面的语句给这两个变量输 入值: scanf(i=%d,f=%f,&i,&f); 为了把100和765.12分别赋给i和f,则正确的输入为(A) A) 100765.12 B) i=100,f=765.12 C) 100765.12 D) x=100y=765.12 (9)给出以下定义: char x[ ]=abcdefg;

Fortran95 简介-全文版

Fortran95简介-全文版 By陈鲸太FORTRAN的演进 FORTRAN的起源,要追溯到1954年IBM公司的一项计划。由JOHN BACKUS 领导的一个小组,尝试着在IBM 704计算机上面发展一套程序,它可以把使用接近数学语言的文字,翻译成机械语言。这个计划在刚开始并不被大家看好,但他们在1957年交出了成果,也就是第一套FORTRAN编译器,FORTRAN语言也就因此诞生了。FORTRAN语言的执行效率普遍的令各界满意,它证明了这项计划的可行性,也成为第一个被广泛使用的高级语言。FORTRAN的名字来自于英文的FORMULA TRANSLATOR这两个字,而这两个字恰是数学公式翻译器的意思。 旧版的FORTRAN77是在1978年由美国国家标准局(ANSI)所正式公布的,之后改版有1992年提出的FORTRAN90以及1997年的FORTRAN95,本文是为了FORTRAN 95所撰写。 编译器简介 1、VISUAL FORTRAN VISUAL FORTRAN一开始是起源于MICROSOFT的FORTRAN POWERSTATION 4.0,这套工具后来卖给DIGITAL公司来继续发展,下一个版本称为DIGITAL VISUAL FORTRAN 5.0,DIGITAL后来被COMPAQ合并,所以接下来的6.0及6.5版就称为COMPAQ VISUAL FORTRAN。而COMPAQ目前又跟HP合并,也许下一个版本会称为HP VISUAL FORTRAN。 VISUAL FORTRAN被整合在一个叫作MICROSOFT VISUAL STUDIO的图形接口开发环境中,VISUAL STUDIO提供一个统一的使用接口,这个接口包括文书编辑功能,PROJECT的管理、除错工具等等,所以在使用上其实跟上学期的VISUAL C++满类似的,同学们上课用过VISUAL C++,对 VISUAL FORTRAN应该不会陌生。 VISUAL FORTRAN 6.5除了完全支持FORTRAN 95的语法外,扩充功能方面提供完整的WINDOWS程序开发工具,专业版还内含IMSL数值链接库。 另外它还可以和VISUAL C++直接互相连结使用,也就是把FORTRAN和C 语言的程序代码混合编译成同一执行档案。 2、在工作站使用FORTRAN 学校计中工作站也提供FORTRAN COMPILER,使用方式很简单,只需要在存放FORTRAN档案的目录下面输入下面叙述即可:

程序设计基础试题(附答案)

程序设计基础复习题 一、单选 1、一个完整的计算机系统应该包括() A、系统软件和应用软件 B、计算机及其外部设备 C、硬件系统和软件系统 D、系统硬件和系统软件 2、“裸机”的概念是指() A、正在进行设计还没有组装好的计算机 B、已经组装好但还没有安装任何软件的计算机 C、仅安装了操作系统的计算机系统 D、安装了文字处理软件但没有安装专用数据处理系统的计算机 3、世界上第一台电子数字计算机研制成功的时间是() A、1936年 B、1946年 C、1956年 D、1970年 4、CASE的含义是() A、计算机辅助设计 B、计算机辅助制造 C、计算机辅助教学 D、计算机辅助软件工程5、当前广泛使用的微型计算机是() A、第一代 B、第二代 C、第三代 D、第四代 6、当代计算机的体系结构称为是() A、冯·诺依曼机 B、非冯·诺依曼机 C、图灵机 D、比尔盖茨机 7、硬盘是() A、输入设备 B、输出设备 C、存储设备 D、计算设备 8、下面4句话中,最准确的表述是() A、程序=算法+数据结构 B、程序是使用编程语言实现算法 C、程序的开发方法决定算法设计 D、算法是程序设计中最关键的因素

9、计算机能直接执行的语言是() A、机器语言 B、汇编语言 C、高级语言 D、目标语言 10、解释程序的功能是() A、将高级语言程序转换为目标程序 B、将汇编语言程序转换为目标程序 C、解释执行高级语言程序 D、解释执行汇编语言程序 11、下面4种程序设计语言中,不是面向对象式语言的是() A、JAVA B、Object Pascal C、Delphi D、C 12、不是C语言的基本数据类型是() A、int B、double C、char D、bool 13、在C语言中,为了求两个整数相除之后得到的余数,可以使用运算符() A、/ B、% C、* D、++ 14、数据的逻辑结构分为() A、纯属结构和非线性结构 B、顺序结构和非顺序结构 C、树型结构和图型结构 D、链式结构和顺序结构 15、用链表表示纯属表的优点是() A、便于随机存取 B、便于插入和删除操作 C、花费的存储空间较顺序存储少 D、元素的物理顺序与逻辑顺序相同 16、栈的最主要特点是() A、先进先出 B、先进后出 C、两端进出 D、一端进一端出 17、下面4句结论只有一句是错误的,它是()

FORTRAN程序设计复习题及答案

FORTRAN程序设计复习题 一、选择题 B (1)下列各FORTRAN表达式中合法的是 A) S+T*2P >= B) .NOT. (A*B+C) C) A2+B2/(C+D) <= D) (A+B).NOT.A*B.GT.(.NOT.只跟一个表达式) C (2)数学式(3/5)ex+y的FORTRAN表达式是 A) 3*EXP(X+Y)/5 B) 3*E* *(X+Y)/ C) (3/5)*EXP(X+Y)D) EXP(X+Y) D (3)下列FORTRAN77表达式中不合法的是 A) A.GT.B.EQV.C.GT.D B) A.AND.B.AND.C.AND.D C) .NOT.(X.LE.D) A.LT.B.LT.C.LT.D D(4)下列叙述中不正确的是 A) FORTRAN子程序可以单独编译 B) 对一个FORTRAN源程序进行编译和连接无误后可生成可执行文件 C) 即使编译和连接都正确无误,FORTRAN程序运行时仍可能出错 D) FORTRAN连接的主要任务是把函数库中的函数翻译成机器指令(正确描述:主要任务为连接目标文件) B (5)在下列FORTRAN77运算符中,优先级最高的是 A) .AND. B) .NOT. C) .OR. D) .EQ. B (6)FORTRAN表达式"6/5+9/2**3/2"的值为 A) 33 B) 1 C) 5 D) 3 A (7)下列FORTRAN77表达式中,合法的是: A) .AND.. B) 10.0 C) D) 提示:A)相当于 .AND.(.NOT.()) D (8)关于编译一个FORTRAN源程序文件,下列说法中错误的是 A) 允许编译只有一个主程序而没有子程序的源文件 B) 允许编译有多个子程序的源文件 C) 允许编译只有一个子程序而没有主程序的源文件 D) 允许编译有多个主程序的源文件 C (9)在FORTRAN77源程序中,续行标志符必须放在 A) 第1列 B) 第1-6列C) 第6列D) 第5列 D (10)下列关于"SUBROUTIN E MAP(X,Y)"语句行的叙述中,不正确的是 A) 这是子程序的第一个语句 B) 字符串"MAP"是子程序名 C) 变量X是子程序的形参D) 子程序执行后,MAP将返回整型数据 提示:子程序无返回值,自定义函数才有) A (11)FORTRAN表达式"2/4+"的值是 A) B) 1 C) D) 0 提示:2/4默认等于整型,=》 D (12)FORTRAN表达式"MOD,"的值是 A) B)0.0 C) D) A (13下列FORTRAN运算符中,优先级最低的是 A)逻辑运算符.AND. B)算术运算符*

(完整版)程序设计基础试题_10_答案

广州大学学年第学期考试卷 课程高级语言程序设计考试形式(开/闭卷,考试/查) 学院系专业班级学号姓名 一、填空题(每空1分,共10分) 1.C源程序的基本单位是(函数)。 2.一个C源程序中至少应包含一个(main()函数)。 3.若a和b均是int型变量,且a和b的初值均为5,则计算表达式a+=b++ 后,a的值为(10 ),b的值为( 6 )。 4.若a、b和c均是int型变量,则计算表达式a=(b=4)+(c=2)后,b值为( 4 ),c 值为( 2 )。 5.表达式8.2-2/3 的计算结果是(8 )。 6.在C语言中,整数可用三种数制表示,它们分别是(十进制)、(八进制)和(十六进制)。 二、程序计算题(每小题5分,共15分) 1. # define f(a) printf(“%d”,a) main() { int i,b[]={1,2,3,5,7,9,11,13,15},*p=5+b; for(i=3;i;i--) switch(i) { case 1: case 2: f(*p++); break;

case 3: f(*(--p)); } } 2. main() { int arr_sum(int arr[],int n); int a[3][4]={1,3,5,7,9,11,13,15,17,19,21,23}; int *p,total; int (*pt)( int arr[],int n); pt=arr_sum; p=a[0]; total=(*pt)(p,12); printf(“total=%d\n”,total); } arr_sum(int arr[],int n) { int i,sum=0; for(i=0;i

西交大《程序设计基础》试题及答案

西交大《程序设计基础》试题及答案 一、单项选择题(本大题共20小题,每小题2分,共40分) 1.int a[10];合法的数组元素的最小下标值为()。A:10 B:9 C:1 D:0 答案:D 2.以下运算符中优先级最低的是()。A:&& B:& C:|| D:| 答案:C 3.若使用一维数组名作函数实参,则以下正确的说法是()。A:必须在主调函数中说明此数组的大小B:实参数组类型与形参数组类型可以不匹配C:在被调用函数中,不需要考虑形参数组的大小D:实参数组名与形参数组名必须一致答案:A 4.已知函数的调用形式:fread(buffer,size,count,fp);其中buffer 代表的是()。 A:一个整数,代表要读入的数据项总数B:一个文件指针,指向要读的文件C:一个指针,指向要读入数据的存放地址D:一个存储区,存放要读的数据项答案:C 5.对以下说明语句int a[10]={6,7,8,9,10}; 的正确理解是()。A:将5个初值依次赋给a[1]至a[5] B:将5个初值依次赋给a[0]至a[4] C:将5个初值依次赋给a[6]至a[10] D:因为数组长度与初值的个数不相同,所以此语句不正确答案:B 6.下列程序的输出结果是()。main() { int x=1,y=0,a=0,b=0; switch(x) { case 1:switch(y) { case case } case 2:a++;b++;break; case 3:a++;b++;break; } printf(\} A:a=1,b=0 B:a=2,b=1 C:a=1,b=1 D:a=2,b=2 答案:B 7.下列程序的输出结果为()。main() {int m=7,n=4; float a=38.4,b=6.4,x; x=m/2+n*a/b+1/2; printf(\ 0:a++;break; 1:b++;break; } A:27.000000 B:27.500000 C:28.000000 D:28.500000 答案:A 8.若k为int型变量,则以下程序段的执行结果是()。k=-8567; printf(\A:格式描述符不合

Fortran95简介-全文版

Fortran95簡介-全文版 By陳鯨太FORTRAN的演進 FORTRAN的起源,要追溯到1954年IBM公司的一項計畫。由JOHN BACKUS 領導的一個小組,嘗試著在IBM 704電腦上面發展一套程式,它可以把使用接近數學語言的文字,翻譯成機械語言。這個計畫在剛開始並不被大家看好,但他們在1957年交出了成果,也就是第一套FORTRAN編譯器,FORTRAN語言也就因此誕生了。FORTRAN語言的執行效率普遍的令各界滿意,它證明了這項計畫的可行性,也成為第一個被廣泛使用的高階語言。FORTRAN的名字來自於英文的FORMULA TRANSLATOR這兩個字,而這兩個字恰是數學公式翻譯器的意思。 舊版的FORTRAN77是在1978年由美國國家標準局(ANSI)所正式公布的,之後改版有1992年提出的FORTRAN90以及1997年的FORTRAN95,本文是為了FORTRAN 95所撰寫。 編譯器簡介 1、VISUAL FORTRAN VISUAL FORTRAN一開始是起源於MICROSOFT的FORTRAN POWERSTATION 4.0,這套工具後來賣給DIGITAL公司來繼續發展,下一個版本稱為DIGITAL VISUAL FORTRAN 5.0,DIGITAL後來被COMPAQ合併,所以接下來的6.0及6.5版就稱為COMPAQ VISUAL FORTRAN。而COMPAQ目前又跟HP合併,也許下一個版本會稱為HP VISUAL FORTRAN。 VISUAL FORTRAN被整合在一個叫作MICROSOFT VISUAL STUDIO的圖形介面開發環境中,VISUAL STUDIO提供一個統一的使用介面,這個介面包括文書編輯功能,PROJECT的管理、除錯工具等等,所以在使用上其實跟上學期的VISUAL C++滿類似的,同學們上課用過VISUAL C++,對VISUAL FORTRAN應該不會陌生。 VISUAL FORTRAN 6.5除了完全支援FORTRAN 95的語法外,擴充功能方面提供完整的WINDOWS程式開發工具,專業版還內含IMSL數值程式庫。另外它還可以和VISUAL C++直接互相連結使用,也就是把FORTRAN和C語言的程式碼混合編譯成同一執行檔案。 2、在工作站使用FORTRAN 學校計中工作站也提供FORTRAN COMPILER,使用方式很簡單,只需要在存放FORTRAN檔案的目錄下面輸入下面敘述即可: ccsun33 [u8623033/fortran]% f77 filename.for

C程序设计基础_复习题

c语言规定,任何非0的数像1 -1等都被认为是真,而0被认为是假 1>1为假 试题一、单选题 1. 已知int k,m=1;执行语句k=-m++;后,k的值是_____。【知识点:难度:正确答案:A】 A.-1 B.0 C.1 D.-2 2. 已知定义int m; float k; 正确的语句是。【知识点:难度:正确答案:D】 A.(int k)%m B.int(k)%m C.int(k%m)D.(int)k%m 3. 当k的值不为0时,在下列选项中能够将k的值赋给变量m,n的是______。【知识点:难度: 正确答案:B】 A.m=k=n B.(m=k)&&(n=m) C.(m=k)||(n=k)D.(n=m)&&(m=k) 4. 已知int x=5; 表达式6>x>1值是_____。【知识点:难度:正确答案:A】 A.0 B.1 C.5 D.表达式语法错 表达式6>x>1 ,先 判断6>x 为0,再 判断0>1,所以值 为0。 (6>x 为1 ,再判 断1>1,所以值为 0。) 5. 下列程序段执行后c值为_____。【知识点:难度:正确答案:D】 int k=7, c=0; while(--k) if (k%3) continue; else c++; A.5 B.4 C.3 D.2 6. 已知字母a的ASCII码为十进制数97,且ch为字符型变量,则执行语句ch=…a?+…D?-…A?;后,ch 中的值为_____。【知识点:难度:正确答案:C】 A.d B.c C.100 D.不确定 7. 设m,n已正确定义,执行语句{for(m=0, n=10; m,能使puts(s)语句正确输出ABCDE字符串的程序 段是______。【知识点:难度:正确答案:C】 A.char s[5] = {"ABCDE"}; puts(s) B.char s[5] = {…A?,?B?,?C?,?D?,?E?}; puts(s); C.char *s; s = "ABCDE"; puts(s); D.char *s; scanf(“%s”,s); puts(s); 《C程序设计基础及实验》

FORTRAN 95 语法速查

FORTRAN 95 语法速查 ----------白云、李学哲、陈国新、贾波编著《FORTRAN95程序设计》读书笔记 目录:一、应用程序的创建与运行/FORTRAN 95所用的字符/ 变量类型及其声明,常量声明/表达式与运算符 二、输入与输出:表控、有格式 三、选择语句与结构:IF语句、CASE结构 四、DO循环结构 五、数组:数组的声明,数组的引用,数组的算术运算,数组的输入、输出,给数组赋初值, 动态数组,WHERE、FORALL语句 六、子程序:语句函数,内部子程序,调用子程序时的虚实结合:形参为数组、非定界数组、子 程序名、星号,递归子程序,外部子程序,纯子程序,逐元子程序 七、派生数据类型与结构体 八、指针与动态链表 九、文件:存取方式,基本操作语句,各类文件的读写操作 十、接口、模块 十一、公用区、存储关联、数据块子程序 十二、绘图:坐标系、设置图形颜色、创建图形程序/ 常用过程:设置线型、绘一像素点、设置当前位置、绘直线、绘弧线、绘矩形、绘多边形、绘制扇形(圆、椭圆)/ 文字信息的显示 附/录:标准函数与标准子例行程序 一、基础部份 1-1 FORTRAN 95 应用程序的创建与运行 创建或运行FORTRAN 95程序必须在Microsoft Developer Studio平台上进行。尽管程序文本及相关文件的编辑可以在任一文本编辑器上进行,然后再拷到Studio的文档窗口中。但最好还是一开始就进入Studio环境。创建FORTRAN 95 程序的步骤大致如下: 1)启动Microsoft Developer Studio 可以通过不同方式运行dfdev.exe程序以启动Microsoft Developer Studio [开始] \ Compaq Visual Fortran 6 \ Developer Studio \ dfdev.exe:或 ……\CVF66 \https://www.wendangku.net/doc/7c8667916.html,\MSDEV98\dfdev.exe Microsoft Developer Studio的界面如下图所示: 文档窗口 工作空间窗口 输出窗口

程序设计基础试题一知识讲解

山东科技大学200 —200 学年第学期 《程序设计基础》考试试卷一 班级姓名学号____________ 一、选择题(20分) 1.算法具有五个特性,以下选项中不属于算法特性的是B (A)有穷性(B)简洁性(C)可行性(D)确定性 2.以下选项中可作为C语言合法常量的是A (A)-80. (B)-080 (C)-8e1.0 (D)-80.0e 3.以下叙述中正确的是C (A)用C语言实现的算法必须要有输入和输出操作 (B)用C语言实现的算法可以没有输出但必须要有输入 (C)用C程序实现的算法可以没有输入但必须要有输出 (D)用C程序实现的算法可以既没有输入也没有输出 4.以下不能定义为用户标识符是D (A)Main (B) _0 (C) _int (D) sizeof 5.以下选项中,不能作为合法常量的是B (A)1.234e04 (B)1.234e0.4 (C)1.234e+4 (D)1.234e0 6.数字字符0的ASCII值为48,若有以下程序 main() {char a='1',b='2'; printf("%c,",b++); printf("%d\n",b-a);} 程序运行后的输出结果是C (A)3,2 (B)50,2 (C)2,2 (D)2,50

7.有以下程序 main(){ int m=12,n=34; printf("%d%d",m++,++n); printf("%d%d\n",n++,++m);}程序运行后的输出结果是A (A)12353514 (B)12353513 (C)12343514 (D)12343513 8.有以下语句:int b;char c[10];,则正确的输入语句是B A)scanf("%d%s",&b,&c); B) scanf("%d%s",&b,c); (C)scanf("%d%s",b,c); D)scanf("%d%s",b,&c); 9.有以下程序 main(){ int m,n,p; scanf("m=%dn=%dp=%d",&m,&n,&p); printf("%d%d%d\n",m,n,p); } 若想从键盘上输入数据,使变量M中的值为123,N中的值为456,P中的值为789,则正确的输入是A A)m=123n=456p=789 B)m=123 n=456 p=789 C)m=123,n=456,p=789 D)123 456 789 10.有以下程序 main(){ int a,b,d=25; a=d/10%9;b=a&&(-1); printf("%d,%d\n",a,b); } 程序运行后的输出结果是B A)6,1 B)2,1 C)6,0 D)2,0 11.有以下程序 main(){ int i=1,j=2,k=3; if(i++==1&&(++j==3||k++==3)) printf("%d %d %d\n",i,j,k);}程序运行后的输出结果是D (A)1 2 3 (B)2 3 4 (C)2 2 3 (D)2 3 3

fortran课后习题答案

第一章 FORTRAN程序设计基础第15页 1、2 1.简述程序设计的步骤。 “程序设计”:反映了利用计算机解决问题的全过程,通常要经过以下四个基本步骤:(1)分析问题,确定数学模型或方法;(2)设计算法,画出流程图;(3)选择编程工具,编写程序;(4)调试程序,分析输出结果。 2. 什么是算法?它有何特征?如何描述算法? 解决问题的方法和步骤称为算法。 算法的五个特征:(1) 有穷性。 (2) 确定性。 (3) 有效性。 (4) 要有数据输入。(5) 要有结果输出。 算法的描述有许多方法,常用的有:自然语言、一般流程图、N-S图等。 第二章顺序结构程序设计 第29页 1、2、3、4、5、6、7、8、9 1.简述符号常量与变量的区别? 符号常量在程序运行过程中其值不能改变。变量在程序运行过程中其值可以改变。 2. 下列符号中为合法的FORTRAN 90标识符的有哪些? (1) A123B (2) M%10 (3) X_C2 (4) 5YZ (5) X+Y (6) F(X) (7) COS(X) (8) A.2 (9) ‘A’ONE (10) U.S.S.R. (11) min*2 (12) PRINT 3. 下列数据中哪一些是合法的FORTRAN常量? (1) 9,87 (2) .0 (3) 25.82(4) -356231 (5) 3.57*E2 (6) 3.57E2.1 (7) 3.57E+2(8) 3,57E-2 4. 已知A=2,B=3,C=5(REAL);且I=2,J=3(INTEGER),求下列表达式的值: (1) A*B+C 表达式的值: 11 (2) A*(B+C) 表达式的值: 16 (3) B/C*A 表达式的值: 1.2 (4) B/(C*A) 表达式的值: 0.3 (5) A/I/J 表达式的值: 0.33 (6) I/J/A 表达式的值: 0 (7) A*B**I/A**J*2 表达式的值: 4.5 (8) C+(B/A)**3/B*2. 表达式的值: 7.25 (9) A**B**I 表达式的值: 512 5. 将下列数学表达式写成相应的FORTRAN表达式: (1) 1E-2 (2)(-B+SQRT(B*B-4*A*C)/(2*A) (3) 1+X+X*X/2+X**3/2/3 (4) COS(ATAN((A**3+B**3)**(1.0/3)/(C*C+1))) (5) EXP(A*X**2+B*X+C) (6) COS(X*Y/SQRT(X*X+Y*Y))**3 6. 用FORTRAN语句完成下列操作: (1) 将变量I的值增加1。I=I+1 (2) I的立方加上J,并将结果保存到I中。 I=I**3+J (3) 将E和F中大者存储到G中。G=Max(E,F) (4) 将两位自然数N的个位与十位互换,得到一个新的数存储到M中(不考虑个位为0的情况) M=MOD(N,10)*10+N/10 第三章选择结构程序设计第43页 1、2、3、5、6、7、9 1.分析下列程序运行结果 (1) LOGICAL P INTEGER I,I1,I2,I3 P=.FALSE. READ*,I I1=MOD(I,10) I2=MOD(I/10,10) I3=I/100

相关文档