c语言基础程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
uppercase
lowercase
A
FBaidu Nhomakorabea
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.
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.
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");
{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:
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++)
{
for(k=1;k<=4-i;k++)
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.
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
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:
#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)
{
printf(" ");
}
for(j=1;j<=i+(i-1);j++)
{
printf("*");
}
printf("\n");
}
for(l=1;l<=3;l++)
{
for(m=1;m<=l;m++)
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>
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.
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:
lowercase
A
FBaidu Nhomakorabea
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.
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.
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");
{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:
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++)
{
for(k=1;k<=4-i;k++)
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.
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
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:
#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)
{
printf(" ");
}
for(j=1;j<=i+(i-1);j++)
{
printf("*");
}
printf("\n");
}
for(l=1;l<=3;l++)
{
for(m=1;m<=l;m++)
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>
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.
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: