I wrote a c program and it arent work correctly

+3 votes
asked Mar 4 by Mohannad Alnono (150 points)
I've made a program to make arrays and their summations, it works but the outputs are not arranged! I wondered what is the problem ?!

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main() {

        int numbers1[3],numbers2[3],results[3];
        int x,y,z,a,b;
        int c;

        for ( x=0,y=0,z=0  ;  x<=3,y<=3,z<=3  ;  x++,y++,z++ ){
            a,b=0;
            printf("enter your %d number in the first array: ",x+1);
            scanf("%d",&a);
            printf("enter your %d number in the secod array: ",y+1);
            scanf("%d",&b);

            numbers1[x]= a;
            numbers2[x]= b;
            results[x]= a + b;
             printf("============================================================");
              printf("%d + %d = %d \n", numbers1[x], numbers2[x], results[x]);

        }

        for( c=0 ; c<=3 ; c++){

            printf("%d + %d = %d \n", numbers1[c], numbers2[c], results[c]);

        }

system("PAUSE");

    return 0;
}

4 Answers

0 votes
answered Mar 4 by anonymous
#include <conio.h>

int main() {

        int numbers1[3],numbers2[3],results[3];
        int x,y,z,a,b;
        int c;

        for ( x=0;x<3;x++){
            
            printf("enter your %d number in the first array: ",x+1);
            scanf("%d",&a);
            printf("enter your %d number in the secod array: ",x+1);
            scanf("%d",&b);

            numbers1[x]= a;
            numbers2[x]= b;
            results[x]= a + b;
             printf("============================================================");
             printf("%d + %d = %d \n", numbers1[x], numbers2[x], results[x]);

        }

        for( c=0 ; c<3 ; c++){

            printf("%d + %d = %d \n", numbers1[c], numbers2[c], results[c]);

        }
}
0 votes
answered Mar 4 by khurshid (140 points)
///use this one

#include <conio.h>

int main() {

        int numbers1[3],numbers2[3],results[3];
        int x,y,z,a,b;
        int c;

        for ( x=0;x<3;x++){
            
            printf("enter your %d number in the first array: ",x+1);
            scanf("%d",&a);
            printf("enter your %d number in the secod array: ",x+1);
            scanf("%d",&b);

            numbers1[x]= a;
            numbers2[x]= b;
            results[x]= a + b;
             printf("============================================================");
             printf("%d + %d = %d \n", numbers1[x], numbers2[x], results[x]);

        }

        for( c=0 ; c<3 ; c++){

            printf("%d + %d = %d \n", numbers1[c], numbers2[c], results[c]);

        }
}
0 votes
answered Mar 5 by wyattbiker (240 points)
Hint: Your arrays declaration is wrong.
0 votes
answered Mar 5 by Srikanth
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int a[2][2],b[2][2],c[2][2],i,j;
    cout<<"Enter elements for the first matrix"<<endl;
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            cin>>a[i][j];
        }
    }
    cout<<"Enter elements for the second matrix"<<endl;
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            cin>>b[i][j];
        }
    }
    cout<<"The sum of the two matrix is : "<<endl;
    for(i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            c[i][j]=0;
            c[i][j]=a[i][j]+b[i][j];
        }
    }
    for(i=0;i<2;i++)
    {
        cout<<"\n";
        for(j=0;j<2;j++)
        {
            cout<<c[i][j]<<"\t";
        }
    }
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...