C language ta question code
Question 8000022012: Calculate the last three digits of an integer to any power.
#include
#include
int main(){ int m,n; scanf("%d %d",&m,&n); int i; int sum = 1; for(i=0;i
1000)sum = sum%1000;sum = sum * m;}printf("%d\n",sum%1000); return 0;}
Question 8000022008 calculate the approximate value of π in the formula
#include
#include
#include
int main(){ double pi = 0; double i = 1.0; do{pi+= 1/i;if(i>0)i = -(i+2);elsei = fabs(i) +2;}while(fabs(1/i)>1e-6);printf("%.6lf\n",4*pi); return 0;}
Question 8000022007 truth-seeking integer part of the number of digits
#include
#include
#include
int main(){double num;scanf("%lf",&num);int count = 0;int number ;number = (int)(fabs(num));while(number){count++;number = number / 10;} printf("%d\n",count); return 0;}
8000022002 obtain the root of the equation by using the bipartite method.
# Include
# Include
# Include
Int main () {double x0, x1 = 0, x2 = 0, fx0, fx1, fx2; // x1, x2 unendpoint, x0 is the midpoint, floating Point Data // determine whether the interval has a solution printf ("Enter the endpoint x1, x2: \ n"); scanf ("% lf", & x1, & x2 ); printf ("x1: % lf \ n", x1); printf ("x2: % lf \ n", x2 ); fx1 = 2 * x1 * x1-4 * x1 * x1 * x1 + 3 * x1-6; fx2 = 2 * x2 * x2-4 * x2 * x2 + 3 * x2-6; if (fx1 * fx2> 0) {printf ("have no ansible \ n"); exit (0) ;}// do {x0 = (x1 + x2) /2; fx0 = 2 * x0 * x0 * x0-4 * x0 * x0 + 3 * x0-6; if (fx0 * fx1 <0) // In this interval {x2 = x0; // adjust the endpoint position fx2 = fx0;} else {x1 = x0; fx1 = fx0 ;}} while (fabs (fx0)> 1e-6 ); // The accuracy here is too small, which may be different from the document answer printf ("root % of the equation. 2lf ", x0); return 0 ;}
Question 8000022001 calculate the square root of an iterative method
#include
#include
#include
int main(){double num;scanf("%lf",&num);double x1,x2=1.0;do{x1 = x2;x2 = 0.5*(x1 + num/x1);}while(fabs(x1-x2)>1e-5);printf("%lf\n",x1); return 0;}
Question 8000022000 questions
# Include
# Include
# Include
Int isCompleteNum (int num) {int I; int ans = num; for (I = 1; I <= num/2; I ++) {if (num % I = 0) ans-= I;} if (ans = 0) return 1; elsereturn 0;} void PrintFactor (int num) {printf ("% d =", num); int I, j = 0; int factor [20]; for (I = 1; I <= num/2; I ++) {if (num % I = 0) factor [j ++] = I;} for (I = 0; I
Question 8000010008 percentile score Conversion
#include
#include
int main(){int grade;scanf("%d",&grade);printf("%c\n",grade);switch(grade/10){case 10:case 9: printf("A\n");break;case 8:printf("B\n");break;case 7:printf("C\n");break;case 6:printf("D\n");break;default:printf("E\n");} return 0;}
Question 8000010007 enter the date to determine the day of the year
#include
#include
int isLeapYear(int year){if((year%4==0&&year%100!=0) ||(year%400==0)){return 1;}else{return 0;}}int main(){int year,month,day;scanf("%d-%d-%d",&year,&month,&day);int dayOfMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};int totalDays = 0,index;for(index=0;index
2)){totalDays++;} printf("%d-%d-%d\n",year,month,day); printf("total days = %d",totalDays); return 0;}