C语言程序,编程语言

img


编程C语言课,不会
123345668709655211238885

如果是第三题,代码补充如下:

参考链接:



#include <stdio.h>

int main(void){
    
    int i,s,t;
    s=0;  // 存放和的变量,初始为0 
    t=1;   // 每项的符号位,初始为1 
    for(i=1;i<=100;i++){ 
    //    printf("s=%d,t=%d,i=%d,t*i=%d\n",s,t,i,t*i);
        s+=t*i;   //1100之间每一个数乘以其符号位,累加到和中 
        t=t*-1;       // 下一项的符号 为此项乘以-1 
    }
    printf("%d",s); // 打印结果 
    
    return 0;
}

img

上面的还是下面的?

#include <stdio.h>
int main()
{
    int i,s,t;
    s= 0;
    t = 1;
    for(i=1;i<=100;i++)
    {
        s += t*i;
        t = -t;
    }
    printf("%d",s);
}

  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/704581
  • 你也可以参考下这篇文章:快速排序的优化2: 解决所有数据相同时的退化问题,C语言实现
  • 除此之外, 这篇博客: C语言经典编程282例12中的 098 逆序存放数据 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 任意输入5个数据,编程实现将这5个数据逆序存放。

    定义数组b,将数组a的值逆序保存到数组b中。
    、缺点:多定义了一个数组,造成冗余

    ——————————ME——————————————————
    #include<stdio.h>
    #include<math.h>
    #include<time.h>
    #include<stdlib.h>
    #include<string.h>
    
      main()
    {
        int a[5], i, b[5], j;
        
        for(i = 0; i < 5; i++)
        {
        	scanf("%d", &a[i]);
    	}
        
        for(i = 0,j = 4; i < 5; i++, j--)
        {
        	b[i] = a[j];
    	}
    
    	for(i = 0; i < 5; i++)
        {
        	printf("%4d", b[i]);
    	}
    
      	printf("\n");
     }
    

    中心点左右对调,

    ——————————官方——————————————
    #include<stdio.h>
    #include<math.h>
    #include<time.h>
    #include<stdlib.h>
    #include<string.h>
    
      main()
    {
        int a[5], i, temp;
        
        for(i = 0; i < 5; i++)
        {
        	scanf("%d", &a[i]);
    	}
        
        for(i = 0; i < 5; i++)
        {
        	printf("%4d", a[i]);
    	}
    	printf("\n");
     
        for(i = 0; i < 2; i++)
        {
        	temp = a[i];
        	a[i] = a[4 - i];
        	a[4 - i] temp;
    	}
        
    	for(i = 0; i < 5; i++)
        {
        	printf("%4d", a[i]);
    	}
    	 
      	printf("\n");
     }