Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
C++
#include<stdio.h>               
  int main()
  {
  int l;
 l=(int *)malloc(1000);
  int a[l][l],c,d,n,i,j,q1=0,q2=0,q3=0,q4=0,will=1,b[20][20],k=0;
  char p;
  //printf("enter the number of co ordinate");
  scanf("%d",&n);
  for(i=0;i<n;i++)>
  for(j=0;j<2;j++)
  scanf("%d",&a[i][j]);
  void quadrant(int temp1,int temp2)
  {
                   
         if(temp1>=0&&temp2>=0)
        q1++;
      else if(temp1>=0&&temp2<=0)
        q2++;
      else if(temp1<0&&temp2<0)
        q3++;
      else if(temp1<=0&&temp2>=0)
         q4++;
 
   }
//printf("enter no of operations");
scanf("%d",&will);
                
while(will>0)
{

p=getchar();
scanf("%c",&p);
switch(p)
{
case 'x': 
                scanf("%d %d",&c,&d);
                  for(i=c-1;i<d;i++)>
                  a[i][1]=-(a[i][1]);break;
case 'y': 
                scanf("%d %d",&c,&d);
                for(i=c-1;i<d;i++)>
                a[i][0]=-(a[i][0]);break;
case 'c':       scanf("%d %d",&c,&d);
                for(i=0;i<=n-1;i++)
                {
                 int temp1,temp2;
                 temp1=a[i][0];
                 temp2=a[i][1];
              
                 quadrant(temp1,temp2);
                } 
               b[k][0]=q1;
               b[k][1]=q2 ;
               b[k][2]=q3;
               b[k][3]=q4; 
             
                  k=k+1; 
    q1=0;
    q2=0;
    q3=0;
    q4=0; 

                 
                  break;
case 'p':   printf(" the co-ordinates are:\n");
               for(i=0;i<n;i++)>
               {
                 for(j=0;j<2;j++)
                {
              printf("%d   ",a[i][j]);
                 }
                printf("\n");
                 } 
                 break;                               
     
default: printf("enter the correct choice\n");break;
}
if(will==1)
for(i=0;i<k;i++)>
{
printf("%d %d %d %d\n",b[i][0],b[i][1],b[i][2],b[i][3]);

}
will--;
}
}</stdio.h>
Posted
Updated 5-Sep-11 2:56am
v4
Comments
Wendelius 5-Sep-11 8:44am    
And the error would be...
CPallini 5-Sep-11 8:59am    
What is the 'simple error'?
kesavahariprasad 5-Sep-11 9:07am    
i have to allocate memory for array in my program using malloc function
[no name] 5-Sep-11 9:02am    
What it dose ""? look at the bottom of your code snippets.
kesavahariprasad 5-Sep-11 9:09am    
my problem is i have toallocte memory for my array using malloc

"my problem is i have toallocte memory for my array using malloc"
Then I would start with declaring a pointer...
C#
int l;
l=(int *)malloc(1000);
Becomes
C#
int* l;
l=(int *)malloc(1000);
After that, we need to know what the error message or similar is...
 
Share this answer
 
Comments
Chuck O'Toole 6-Sep-11 2:24am    
his next statement was "int a[l][l]" which will earn him a big compile error on using a variable in this way. I think it was hidden by the fact that, in this font, the lower case letter 'l' is visually similar to the number '1' so the statement looked OK.
#include<stdio.h>
#include <stdlib.h>

int q1, q2, q3, q4;
  void quadrant(int temp1,int temp2)
  {

         if(temp1>=0&&temp2>=0)
        q1++;
      else if(temp1>=0&&temp2<=0)
        q2++;
      else if(temp1<0&&temp2<0)
        q3++;
      else if(temp1<=0&&temp2>=0)
         q4++;

   }

  int main()
  {
  /*int l;
 l=(int *)malloc(1000);*/
  int a[1000][2],c,d,n,i,j,will,b[20][20],k=0;
  char p;
  printf("enter the number of co ordinate");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  for(j=0;j<2;j++)
  scanf("%d",&a[i][j]);
  printf("enter no of operations");
scanf("%d",&will);

while(will>0)
{

p=getchar();
scanf("%c",&p);
switch(p)
{
case 'x':
                scanf("%d %d",&c,&d);
                  for(i=c-1;i<d;i++)
                  a[i][1]=-(a[i][1]);break;
case 'y':
                scanf("%d %d",&c,&d);
                for(i=c-1;i<d;i++)
                a[i][0]=-(a[i][0]);break;
case 'c':       scanf("%d %d",&c,&d);
                for(i=0;i<=n-1;i++)
                {
                 int temp1,temp2;
                 temp1=a[i][0];
                 temp2=a[i][1];

                 quadrant(temp1,temp2);
                }
               b[k][0]=q1;
               b[k][1]=q2 ;
               b[k][2]=q3;
               b[k][3]=q4;

                  k=k+1;
    q1=0;
    q2=0;
    q3=0;
    q4=0;


                  break;
case 'p':   printf(" the co-ordinates are:\n");
               for(i=0;i<n;i++)
               {
                 for(j=0;j<2;j++)
                {
              printf("%d   ",a[i][j]);
                 }
                printf("\n");
                 }
                 break;

default: printf("enter the correct choice\n");break;
}
if(will==1)
for(i=0;i<k;i++)
{
printf("%d %d %d %d\n",b[i][0],b[i][1],b[i][2],b[i][3]);

}
will--;
}
}
 
Share this answer
 
v2
Comments
Chuck O'Toole 6-Sep-11 2:27am    
I'm not sure how re-posting the program will help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900