c语言基础程序

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
}
Write a Cprogramthat canaccept user-inputthe one-dimensional arrayandsort array and displayon your screen.(The array has 20 elements)
编写一个C程序,可以接受用户输入的一维数组和数组排序并显示在屏幕上。(数组有20种元素)
Write a program to determine whether a input number is greater than 100 and less than 200 and divisible by 7 or not,please print theappropriatemessage on the screen.
#include<stdio.h>
main()
{
int n,grade,sum,c;
n=1;
sum=0;
while(n<=999)
{
printf("please input a grade\n");
scanf("%d",&grade);
if(grade==999)
break;
if(grade>0&&grade<100)
Write a C program tocreate the following figure:
*
***
*****
*******
*****
***
*
#include<stdio.h>
main()
{
int i,j,k,l,m,n;
for(i=1;i<=4;i++)
{Baidu Nhomakorabea
for(k=1;k<=4-i;k++)
printf(" ");
}
}
Write a Cprogramthat will accept user-input text and just transform all the letterstothe next character.(Other non-letter characters remain unchanged)
{
printf(" ");
}
for(j=1;j<=i+(i-1);j++)
{
printf("*");
}
printf("\n");
}
for(l=1;l<=3;l++)
{
for(m=1;m<=l;m++)
printf(" ");
for(n=1;n<6-2*(l-1);n++)
printf("*");
printf("\n");
编写一个 C 程序,将接受用户输入的文本并不仅仅是变换到下一个字符的所有字母。(其他非字母字符保持不变)
#include<stdio.h>
main()
{
int i;
char st1[8];
printf("input a string:\n");
scanf("%s",st1);
for(i=0;i<8;i++)
{sum=sum+grade;
n=n+1;
printf("sum=%d\n",sum);
}
else
printf("an invalid grade has been entered\n");
}
c=sum/n;
printf("average=%d\n",c);
}
4.MoreTests Withfor:
less than 60 E
#include<stdio.h>
main()
{
int marks,index;
printf("please input a mark\n");
scanf("%d",&marks);
index=marks/10;
switch(index)
{
case 10:
case 9:
printf("grade=A\n");
break;
case 8:
printf("grade=B\n");
break;
case 7:
printf("grade=C\n");
break;
case 6:
printf("grade=D\n");
break;
default:
printf("grade=E\n");
break;
}
}
1.Some Tests Withif–else:
#include<stdio.h>
main()
{
int i,j,a[20],b;
for(i=0;i<20;i++)
{
printf("\n请输入第%d个数:",i+1);
scanf("%d",&a[i]);
}
printf("\n排序前数组为\n");
for(i=0;i<20;i++)
{
printf("%d",a[i]);
main()
{
int a;
printf("input a number\n");
scanf("%d",&a);
if(a>100&&a<200&&a%7==0)
printf("true");
else
printf("false");
}
3.SomeTests Withgetchar() and putchar:
printf(" ");
}
for(i=0;i<20;i++)
{
for(j=i;j<20;j++)
{
if(a[i]>a[j])
{
b=a[i];
a[i]=a[j];
a[j]=b;
}
}
}
printf("\n从小到大排序后数组为:\n");
for(i=0;i<20;i++)
{
printf("%d",a[i]);
if(st1[i]>=65&&st1[i]<=122)
st1[i]++;
printf("%s\n",st1);
}
Numerical gradeletter grade
greater than or equal to90A
less than 90 but greater than or equal to 80 B
less than 80 but greater than or equal to 70 C
less than 70 but greater than or equal to 60 D
Writea Cprogram that can convertcapital lettertolowercase.Example: input‘A’,then the screen output‘a’.
When you are sure your program is working correctly,use it to complete the following table.
uppercase
lowercase
A
F
G
K
R
Y
#include<stdio.h>
main()
{
char ch;
printf("please input a char");
ch=getchar();
ch=ch+32;
putchar(ch);
}
1. Some Tests Withwhile:
Write a C program that continuously requests a grade to be entered.If the grade is less than 0 or greater than 100,your program should print an appropriate message informing the user that an invalid grade has been entered,else the grade should be added to total.When a grade of 999 is entered the program should exit the repetition loop and compute and display the average of the valid grades entered.
Document the output for your report. You don't have to write all the sections in the report. Just paste the program and its output in a word file.
#include<stdio.h>
4.SomeTests Withswitch-case:
A student’s letter grade is calculated according to the following schedule.Write a C program with switch that accepts a students numerical grade.and displays the letter grade.
相关文档
最新文档