C Primer Plus Chapter two review questions and programming questions

Source: Internet
Author: User






1. Answer: function






2. syntax errors in C is the wrong program, such as int a=5 No semicolon is a syntax error



3. semantic error is written code is not wrong, but it is not the same as what you want to achieve, for example, we want to calculate how much is written in 1-1 is a semantic error



4. This code is riddled with bugs. If you ask my opinion, I will say to him: ' Brother promising!!



Include Stdio.h
int main (void)
(
int s;
s;=56;
Print (there is S week in a year.);
return 0;
)



After modification to



#include <stdio.h>
int main (void)
{



int s;
s=56;
printf ("There is%d week in a year.", s);
return 0;



}






5. answer: A bea bea Black sheep.have you any wool?



b begone!



0 Creature of Loads!



c What?



No/nbonzo?



D 2+2=4






6. Answer: Char and int






7. printf ("There were%d words and%d lines", words,lines);






8. a=5 b=2



A=5 b=5



A=5 b=5






Programming questions



1. Write a program that calls the printf () function to output your first and last name on a single line, and then call the printf () function once in two separate
Output your first and last name on the line, and then call a pair of printf () functions to output your first and last name on a single line. The output should look like this (of course
To be replaced by your name):
Anton Bruckner
Anton
Bruckner
Anton Bruckner
First OUTPUT statement
A second output statement
is still the second output statement
Third and fourth output statements



#include <stdio.h>
int main (void)
{
printf ("Huang ergou\n");
printf ("huang\nergou\n");
printf ("Huang");
printf ("Ergou");



return 0;
}






2. Write a program to output your name and address.



#include <stdio.h>
int main (void)
{
printf ("name:huangergou\n");
printf ("address:china\n");



}






3. Write a program that converts your age to days and displays the values of both. Don't worry about common year (fractional
year) and leap year (leapyear) issues.



#include <stdio.h>
int main (void)
{
int age;



age=20;
printf ("age=%d day=%d", 20,age*365);
}






4. Write a program that produces the following output:
For he ' s a jolly good fellow!



For he ' s a jolly good fellow!



For he ' s a jolly good fellow!
Which nobody can deny!
In addition to the main () function, the program uses two user-defined functions: one to output the above compliment message once: the other
Used to output the last line once.



#include <stdio.h>
void F1 (void)
{
printf ("For he ' s a jolly Good fellow!\n");
}
void F2 (void)
{
printf ("Which nobody can deny!\n");
}
int main (void)
{
F1 ();
F1 ();
F1 ();
F2 ();
}






5. Write a program that creates an integer variable named toes. Let the program set the toes to 10. Then let the program calculate two toes and
and the toes squared. The program should output all 3 values and identify them separately.



#include <stdio.h>



int main (void)
{
int toes=10;
int toes_add=toes+toes;
int toes_square=toes*toes;
printf ("toes=%d toes_add=%d toes_squere=%d", toes,toes_add,toes_square);
}






6. Write a program that produces the following output:
Smile! Smile! Smile
Smile! Smile!
Smile!
Define a function in the program that can display the string smile once, and use the function when needed.



#include <stdio.h>
void display (void)
{
printf ("smile!");
}
int main (void)
{
Display ();
Display ();
Display ();
printf ("\ n");
Display ();
Display ();
printf ("\ n");
Display ();
}






7. Write a program in which you call a function called One_three (). The function is to display the word "one" in a row, and then call the
() function, and then display the word "three" in another line. function one () should be able to display the word "one" in one line. The main () function should
The phrase "Starting" is displayed before calling the One_three () function.
Now: "After the function call to display" done! "O this way, the final output should look like this:
Starting now
One
Both
Three
Done!









#include <stdio.h>
void One_three (void)
{
printf ("one\n");
}
void (void)
{
printf ("two\n");
}
int main (void)
{
printf ("Starting now:\n");
One_three ();
Both ();
printf ("three\n");
printf ("done!");
}






C Primer Plus Chapter two review questions and programming questions


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.