任务七 C语言综合训练(练习题)-湖北省计算机技能高考操作(应会)考纲技能通
|
2份
|
10页
|
102人阅读
|
0人下载
内容正文:
湖北省计算机类技能高考实操练习题
一.程序设计题
1.套餐A:30元(主菜+饮料+甜点),套餐B:20元(主菜+饮料),套餐C:15元(主菜+甜点),总共预算300元,要点15份餐,且甜点总数比饮料多5份,问每种套餐各点多少份?
#include<stdio.h>
void main( )
{
int i,j,k;
/*******space*******/
for(i=0;i<=10;i++){
for(j=0;j<=15;j++){
for(k=0;k<=20;k++){
if(i+j+k==15 && 30*i+20*j+k*15==300 && k-i==5){
printf("A套餐=%d份,B套餐=%d份,C套餐=%d份",i,j,k);
}
}
}
}
/*******space*******/
printf("套餐A的份数=%d,套餐B的份数=%d,套餐C的份数=%d",i,j,k);
}
2.定义一个函数用于输出指定行数的金字塔图形,输入行数 ,调用函数输出金字塔
#include <stdio.h>
#include <stdlib.h>
void triangle(int lines){
int i,j;
/*******space*******/
for(i=1;i<=lines;i++){
for(j=1;j<=lines-i;j++){
printf(" ");
}
for(j=1;j<=2*lines-1;j++){
printf("*")
}
printf("
");
}
/*******space*******/
}
int main(){
int lines;
printf("输入金字塔的行数:");
scanf("%d",&lines);
triangle(lines);
system("pause");
return 0;
}
3.将一个正整数分解质因数。例如:输入60,打印出60=2*2*3*5
#include<stdio.h>
#include <stdlib.h>
int main() {
int n,i;
printf("请输入一个正整数:");
scanf("%d",&n);
printf("%d=",n);
/*******space*******/
i=2;
while(n!=1){
if(n%i==0){
printf("%d*",i);
n=n/i;
}
else{
i++;
}
}
printf("\b")
/*******space*******/
system("pause");
return 0;
}
4.编写函数rtrim,用来删除字符串尾部的空格,首部和中间的空格不删除,例如:字符串为" A BC DEF ",
删除后的结果是" A BC DEF",要求函数形参采用指针变量。
#include <stdio.h>
#include <string.h>
void main()
{
void rtrim(char *p);
char s[100];
gets(s);
rtrim(s);
puts(s);
}
void rtrim(char *p)
{
int i;
/*******space*******/
int len = strlen(p);
for(i = len - 1; i >= 0; i--)
{
if(p[i] != ' ')
{
p[i + 1] = '\0';
break;
}
}
/*******space*******/
}
5.父亲今年30岁,儿子6岁,问多少年后父亲年龄是儿子的两倍
#include <stdio.h>
void main() {
int father,son,year=0;
/*******space*******/
father=30,son=6;
while(1){
if(father/son==2){
break;
}
year++;
father++;
son++;
}
printf("%d年后父亲年龄是儿子的两倍",year);
/*******space*******/
}
6.编写程序,完成下列图形
#include<stdio.h>
#include<math.h>
void main(){
int i,j,k;
/*******space*******/
for(i=-3;i<=3;i++){
for(j=1;j<=abs(i);j++){
printf(" ")
}
for(j=1;j<=7-2*abs(i);j++){
printf("*")
}
printf("
");
}
/*******space*******/
}
7.编写一个函数,将整数进行反序输出
int reverse(){
/*******space*******/
while(num != 0){
reversed = reversed * 10 + num % 10;
num = num / 10;
}
/*******space*******/
}
void main(){
int number;
scanf("%d",&number);
number=reverse(number);
printf("%d",number);
}
8.编写程序将数组a[10]中的整数进行排序
#include <stdio.h>
void main()
{
int array[10];
int i,j,t;
for(i=0;i<10;i++) scanf("%d",&array[i]);
/*******space*******/
for(i = 0; i < 9; i++)
{
for(j = 0; j < 9 - i; j++)
{
if(array[j] > array[j + 1])
{
t = array[j];
array[j] = array[j + 1];
array[j + 1] = t;
}
}
}
/*******space*******/
}
9.打印出100~1000之间所有各位数之和是6的倍数的数字
#include<stdio.h>
int fun(int n);
main(){
int i,temp,a,sum=0;
/*******space*******/
for(i=100;i<1000;i++){
temp=i;
sum=0;
while(temp!=0){
a=temp%10;
sum=sum+a;
temp=temp/10;
}
if(sum%6==0){
printf(“%d”,i);
}
}
/*******space*******/
}
10.程序将字符串开始和末尾的连续空格删除,同时将字符串中间的多个空格删减只剩1个空格,例如输入字符串" this is a program ", 要求输出"this is a program"。
#include<stdio.h>
void getnewstr(char a[])
{
int isbegin,front,back;
isbegin=1;
front=0;
back=0;
/*******space*******/
while(a[back] != '\0'){
if(a[back] == ' '){
if(!isbegin && a[back - 1] != ' ')
{
a[front++] = ' ';
}
}
else{
a[front++] = a[back];
isbegin = 0;
}
back++;
}
/*******space*******/
if(a[front-1]==' ')
--front;
a[front]='\0';
}
int main()
{
char a[] = " hello how are you ";
getnewstr(a);
printf("\"%s\"
",a);
return 0;
}
原创精品资源学科网独家享有版权,侵权必究!
学科网(北京)股份有限公司
$
湖北省计算机类技能高考实操练习题
一.程序设计题
1.套餐A:30元(主菜+饮料+甜点),套餐B:20元(主菜+饮料),套餐C:15元(主菜+甜点),总共预算300元,要点15份餐,且甜点总数比饮料多2份,问每种套餐各点多少份?
#include<stdio.h>
void main( )
{
int i,j,k;
/*******space*******/
/*******space*******/
printf("套餐A的份数=%d,套餐B的份数=%d,套餐C的份数=%d",i,j,k);
}
2.定义一个函数用于输出指定行数的金字塔图形,输入行数 ,调用函数输出金字塔
#include <stdio.h>
#include <stdlib.h>
void triangle(int lines){
int i,j;
/*******space*******/
/*******space*******/
}
int main(){
int lines;
printf("输入金字塔的行数:");
scanf("%d",&lines);
triangle(lines);
system("pause");
return 0;
}
3.将一个正整数分解质因数。例如:输入60,打印出60=2*2*3*5
#include<stdio.h>
#include <stdlib.h>
int main() {
int n,i;
printf("请输入一个正整数:");
scanf("%d",&n);
printf("%d=",n);
/*******space*******/
/*******space*******/
system("pause");
return 0;
}
4.编写函数rtrim,用来删除字符串尾部的空格,首部和中间的空格不删除,例如:字符串为" A BC DEF ",
删除后的结果是" A BC DEF",要求函数形参采用指针变量。
#include <stdio.h>
#include <string.h>
void main()
{
void rtrim(char *p);
char s[100];
gets(s);
rtrim(s);
puts(s);
}
void rtrim(char *p)
{
int i;
/*******space*******/
/*******space*******/
}
5.父亲今年30岁,儿子6岁,问多少年后父亲年龄是儿子的两倍
#include <stdio.h>
void main() {
int father,son,year=0;
/*******space*******/
/*******space*******/
}
6.编写程序,完成下列图形
#include<stdio.h>
void main(){
int i,j,k;
/*******space*******/
/*******space*******/
}
7.编写一个函数,将整数进行反序输出
int reverse(){
/*******space*******/
/*******space*******/
}
void main(){
int number;
scanf("%d",&number);
number=reverse(number);
printf("%d",number);
}
8.编写程序将数组a[10]中的整数进行排序
#include <stdio.h>
void main()
{
int array[10];
int i,j,t;
for(i=0;i<10;i++) scanf("%d",&array[i]);
/*******space*******/
/*******space*******/
}
9.打印出100~1000之间所有各位数之和是6的倍数的数字
#include<stdio.h>
int fun(int n);
main(){
int i,temp,a,sum=0;
/*******space*******/
/*******space*******/
}
10.程序将字符串开始和末尾的连续空格删除,同时将字符串中间的多个空格删减只剩1个空格,例如输入字符串" this is a program ", 要求输出"this is a program"。
#include<stdio.h>
void getnewstr(char a[])
{
int isbegin,front,back;
isbegin=1;
front=0;
back=0;
/*******space*******/
/*******space*******/
if(a[front-1]==' ')
--front;
a[front]='\0';
}
int main()
{
char a[] = " hello how are you ";
getnewstr(a);
printf("\"%s\"
",a);
return 0;
}
原创精品资源学科网独家享有版权,侵权必究!
学科网(北京)股份有限公司
$