COMP1023 Foundations of C Programming

Assignment 1

1.Run the following program
main()
{
int j = 65;
float f;
scanf(“%c”, ch)
printf(“j = %f, ch = %c”, f, ch);
printf(“%c is the ASCII code of ‘%c’\n”, ch, ch);
ch = j;
printf(“Now ch is the letter ‘%c’\n”, ch);
}
Answer the questions:

•Whenyoubuildthisprogram,whatarethegrammarerrorsandwarnings?Arethereany semantic errors? Why? (put answers as the comments at the end of the program)

•Fix the program by removing all the errors and warnings.

2.Write a program to input an integer and decide if it is multiple of 9 or 7.

3.Write aprogram to inputan integer which isbetween 101 and999 (inclusive). Iftheinteger is out ofthisrange,thenoutputthemessage“Theinputisoutoftherange”;otherwise,reversethe integerandoutputit.Forexample,iftheinputis987,theoutputis789;iftheinputis500,the output is 005; if input is 780, the output is 087.

4.Writeaprogram toreadapositiveinteger anddecideifitisalegal ASCIIcode.Ifitisalegal ASCII code,furtherdecideifitistheASCIIcodeofadigit,anEnglishletter orothercharacter,showthe correspondingmessage.IfitisnotanASCIIcode,giveawarning.Assumetherange ofASCIIcode is from 0 to 127.

发表评论

电子邮件地址不会被公开。 必填项已用*标注