码迷,mamicode.com
首页 > 其他好文 > 详细

ex3

时间:2021-04-16 12:04:07      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:开始   三次   lib   16px   日期   技术   lse   告诉   加强   

task1

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5
 int main(){
 	
   int x, n;
   
   srand(time(0));
   
   for(n=1 ; n<=N; n++){
   	     x = rand() % 100;
   	     printf("%3d",x);
   }
   
   printf("\n");
   
   return 0 ;
   
   }

  技术图片task2

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 1
 int main(){
 	
   int random , n , x, i;
   
   srand(time(0));
   
   for(n=1 ; n<=N; n++){
   	
   	     random = rand() % 30 + 1;
			 	     
   }
   
   printf("猜猜2021年五月哪一天是你的幸运日\n只有三次机会哦,开始吧:\n");
   
 
   
   for(i=1; i<=3 ;i++){
   
     scanf("%d",&x);
     
   if(x < random)
   
   	printf("日期早咯,luck day跑到后面了\n");
   	
   else if(x == random) 
	   return 0 ;
	     
   else if(x > random)
     printf("日期晚了,lucky day在前面欸\n"); 
   
   }

   printf("\n");

   printf("对不起,次数用光咯,你没找到你的幸运日欸\n告诉你吧,是%d哦\n",random);
   
   return 0 ;
   
   }

  技术图片

task3

#include<stdio.h>

int main(){
	
	long x ;
	int y , n, N;
	
	printf("enter you number:");
	
    while(scanf("%d", &x) != EOF){

	
	printf("new number is:");
	
	while(x > 0){
		
		y = x % 10;
		
		if(y%2 == 1)
		  printf("%d", y);
		
		x = x/10 ;  
	}

}

return 0 ;

}

  技术图片

task4

#include <math.h>
#include <stdio.h>

void solve(double a, double b, double c);

int main() {
double a, b, c;

  printf("Enter a, b, c: ");
  
  while(scanf("%lf%lf%lf", &a, &b, &c) != EOF) {
    solve(a, b, c); 
    
  printf("Enter a, b, c: ");
}
return 0;
}


void solve(double a, double b, double c) {
double x1, x2;
double delta, real, imag;
  if(a == 0)
     printf("not quadratic equation.\n");
  else {
    delta = b*b - 4*a*c;
      if(delta >= 0) {
         x1 = (-b + sqrt(delta)) / (2*a);
         x2 = (-b - sqrt(delta)) / (2*a);
       printf("x1 = %.2f, x2 = %.2f\n", x1, x2);
}

  else {
         real = -b/(2*a);
         imag = sqrt(-delta) / (2*a);
         printf("x1 = %.2f + %.2fi, x2 = %.2f - %.2fi\n", real, imag, real, imag);
}
}
}

  技术图片

task5

#include <stdio.h>

double fun(int n); 
int main() {
int n;
double s;
printf("Enter n(1~10): ");
while(scanf("%d", &n) != EOF) {
s = fun(n); 
printf("n = %d, s= %f\n\n", n, s);
printf("Enter n(1~10): ");
}
return 0;
}

double fun(int n) {
int i,m=1,q=1;
double item,s=0;
 
 for(i=1; i <= n; i++){
 
    q=q*i;
 	item = m*1.0/q;
 	s = s + item;
 	m = -m;
 }
 
 return s ;
 
}

  技术图片

task6

#include<stdio.h>
#include<stdlib.h>
int isprime(int x);
int main(){

int i,n=0;
int line=0;
for(i=101;i<=200;i++){
	
	if(isprime(i)){
	printf("%6d",i);
    n++;
    line++;
    if(line == 5){
    	printf("\n");
    	line = 0;
	}
    }
}
printf("100-200之间的素数为:%d\n", n );

return 0 ;
}

int isprime(int x){
	int m;

	for(m=2; m<x ;m++)
	
	    if(x%m == 0) break;
	    
     if(m >= x)return 1;
	 else return 0;
}

  技术图片

这次确实有点麻烦了,很多小细节注意不到使代码不正确,还是要加强实验理解。

ex3

标签:开始   三次   lib   16px   日期   技术   lse   告诉   加强   

原文地址:https://www.cnblogs.com/lddsbk/p/14664109.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!