#include <stdio.h>
int main()
{
int a,b,c,n,q,i;
scanf("%d%d",&n,&q);
char ar[n];
for(i=0;i<n;i++)
scanf("%c",&ar[i]);
for(i=0;i<q;i++)
{
scanf("%d%d",&a,&b);
if(a==1)
{
if(ar[b-1]=='1')
ar[b-1]='0';
else
ar[b-1]='1';
}
else
{
scanf("%d",&c);
if(ar[c-1]=='1')
printf("ODD\n");
else
printf("EVEN\n");
}
}
return 0;
}
Asked by: bandaram_Sumanth on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.
Input given in this question are the numbers either 0 or 1 , but these numbers are separated by SPACE ,since you are taking input as character ,space will also be stored in your input array since space is also character. So you must always take input in integer array for SPACE seperated integer.
scanf("%c",&ar[i]); ->this part of your code is causing the error.
This happens beacuse %c also reads the '\n' (new line character) when you hit enter.
To fix this just put a space before %c i.e scanf(" %c",&ar[i]);
be careful while taking char/string input in c.
you may go thorough this article to know more about the cause of the error:
https://gsamaras.wordpress.com/code/caution-when-reading-char-with-scanf-c/