×

c语言编程例题

C语言编程题目?c语言程序设计例题

admin admin 发表于2022-05-18 11:19:49 浏览103 评论0

抢沙发发表评论

C语言编程题目


#include 《stdio.h》
#include 《string.h》

void sum(char *sum, char *a, char *b)
{
char *s_short, *s_long;
int i_short, i_long, i_result;

i_short = strlen(a) - 1;
i_long = strlen(b) - 1;

if(i_long 》= i_short )
{
s_short = a;
s_long = b;
i_result = i_long + 1;
}
else
{
s_long = a; 
s_short = b;
i_result = i_short;
i_short = i_long;
i_long = i_result;
i_result ++;
}
for(; i_short 》= 0; i_short --, i_long --, i_result --)
{
sum[i_result] += s_short[i_short]- ’0’  + s_long[i_long] - ’0’;
sum[i_result - 1] = sum[i_result] / 10;
sum[i_result] %= 10;
sum[i_result] += ’0’;
}
for(; i_long 》= 0; i_long --, i_result --)
{
sum[i_result] += s_long[i_long] - ’0’ ;
sum[i_result - 1] = sum[i_result] / 10;
sum[i_result] %= 10;
sum[i_result] += ’0’;
}
if(sum) sum += ’0’;
else
{
i_result = strlen(sum + 1);
memmove(sum, sum + 1, i_result);
sum[i_result] = 0;
}
}
int main(int argc, char **argv)
{
char a = {0}, b = {0}, r = {0};
int i, j = 0;

scanf(“%d“, &i);
while(j ++《 i)
{
memset(r, 0, sizeof(r));
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
scanf(“%s%s“, a, b);

sum(r, a, b);
printf(“Case %d:\n“, j);
printf(“%s + %s = %s\n“, a , b, r);
if(j 《 i) printf(“\n“);
}
return 0;
}

c语言程序设计例题


题目1
#include “stdio.h“
void main(void)
{
int n=5,m=10,i=1;
long sum=1;
for(;i《=n;i++)
{
sum*=i;
}
printf(“\n5!=%d“,sum);
for(i=1;i《=10;i++)
{
sum*=i;
}
printf(“\n10!=%d“,sum);
}
题目2
#include “stdio.h“
#include “string.h“
struct Student
{
char s_Name;
long n_Code;
int n_English;
int n_Math;
int n_Computer;
}student_1,student_2;
void main(void)
{
printf(“\nStudent1:\nName:“);
scanf(“%s“,&student_1.s_Name);
printf(“StudentNum:“);
scanf(“%d“,&student_1.n_Code);
printf(“English Score:“);
scanf(“%d“,&student_1.n_English);
printf(“Math Score:“);
scanf(“%d“,&student_1.n_Math);
printf(“Computer Score:“);
scanf(“%d“,&student_1.n_Computer);

printf(“\nStudent2:\nName:“);
scanf(“%s“,&student_2.s_Name);
printf(“StudentNum:“);
scanf(“%d“,&student_2.n_Code);
printf(“English Score:“);
scanf(“%d“,&student_2.n_English);
printf(“Math Score:“);
scanf(“%d“,&student_2.n_Math);
printf(“Computer Score:“);
scanf(“%d“,&student_2.n_Computer);

printf(“\nStudent1:\nName:%s\nStudent Number:%d\nEnglish Score:%d\nMath Score:%d\nComputer Score:%d\n“,student_1.s_Name,student_1.n_Code,student_1.n_English,student_1.n_Math,student_1.n_Computer);
printf(“\nStudent2:\nName:%s\nStudent Number:%d\nEnglish Score:%d\nMath Score:%d\nComputer Score:%d\n“,student_2.s_Name,student_2.n_Code,student_2.n_English,student_2.n_Math,student_2.n_Computer);

}

c语言编程题目及答案


#include 《stdio.h》
#include 《math.h》
void main(void)
{
double a;

double b;

double c;/* 以上三个变量分别对应三边 */

double sin_c;/* c边对应角的正玄值 */

double cos_c;/*c边对应角的余玄值*/

double cos_a;

double area; /* 三角形的面积 */

printf(“输入a,b,c:“);

scanf(“%lf, %lf, %lf“, &a, &b, &c);

if(((a+b)》c) && (a-b)《c)
{
printf(“三边能够成三角形\n.“);

cos_c = (a*a + b*b -c*c)/(2*a*b);

cos_a = (b*b + c*c - a*a)/(2*b*c);

if ((cos_c 》 0) && (cos_a 》0))
{
printf(“三角形是锐角三角形。\n“);
}

else if ((cos_c 《 0) || (cos_a 《 0))
{
printf(“三角形是钝角三角形\n“);
}
else
{
printf(“三角形是直角三角形\n“);
}

sin_c = sqrt(1- cos_c*cos_c);

area = a*b*sin_c/2;

printf(“三角形的面积是%f.\n“,area);
}
else
{
printf(“三边不能构成三角形\n“);
}
}
-c语言编程例题