为什么数组联合打印无限次 [英] Why the union of array is printing infinite times

查看:129
本文介绍了为什么数组联合打印无限次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决,为什么我的代码工作不正常

它是两个数组的联合



我尝试过:



solve, why my code is not working properly
Its the union of two arrays

What I have tried:

#include<stdio.h>
int main()
{
    int a[5],b[5],c[10];
    printf("ENTER THE VALUES FOR ARRAY 1 ");
    int i,j,k=0,l,m;
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("ENTER THE VALUE FOR ARRAY 2 ");
    for(i=0;i<5;i++)
    {
        scanf("%d",&b[i]);
    }
    printf("THE VALUES STORED AT ARRAY 1 IS = ");
    for(i=0;i<5;i++)
    {
      printf("%d ",a[i]);

    }
       printf("\n");
    printf("THE VALUE STORED AT ARRAY 2 IS = ");
    for(i=0;i<5;i++)
    {
        printf("%d ",b[i]);
    }
    printf("\n");
    for(i=0;i<5;i++)
    {
        c[i]=a[i];

    }
    for(i=0;i<5;i++)
    {
        for(j=0;j<5;j++)
        {
            if (b[i]!=a[j])
              {

               ++k;
               m=i;}


        }
        if(k==5)
        {
         l=l+1;

        c[5+l]=b[m];
    }}

    printf("the union of both arrays is = ");
    for(i=0;i<=(5+l);i++)
    {
        printf("%d ",c[i]);
    }
    return 0;
}

推荐答案

您尚未初始化'l',但您已使用该值:

l = l + 1;
You have not initialized 'l' but you have used the value:
l = l + 1;


这篇关于为什么数组联合打印无限次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆