123ayanjit
BAN USERIn this code, you have to omit giving the '?' in the end. I forgot about that while writing.
- 123ayanjit August 31, 2019In the input string, only two characters are important: The firsr and the 2nd last character (provided the last character is '?'). Consider the following cases:
1)If the first and the second last characters are equal, then we the output can be either of the other two letters. But we need the character which comes first in alphabetical order. So if the first character is 'a', then the output will be 'b', in all other cases it will be 'a'.
2) If the first and the second last characters are unequal, then we will have to give the remaining character as output. Eg. if the first and second last characters are 'a' and 'c' are unequal, then 'b' will be the output. So I have written the following code. It uses a bitwise XOR operator, see if it helps you:
#include<stdio.h>
void main()
{
char str[100];
int i;
scanf("%s", str);
for(i=0; str[i]!='\0'; i++);
i=(str[0]^str[i-1]);
printf("The character is=");
if(i==0)
{
if(str[0]=='a')
printf("b");
else
printf("a");
}
else
printf("%c", 96+i);
}
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i, j, *arr, c=0, s=0;
printf("Enter the number of elements: ");
scanf("%d", &i);
arr=(int *)malloc(i*sizeof(int));
for(j=0; j<i; j++)
{
printf("Enter the element no. %d: ", j+1);
scanf("%d", &arr[j]);
}
for(j=0; j<i; j++)
{
if(arr[j]<arr[j+1])
c++;
else
{
if(c>s)
s=c;
c=0;
}
}
printf("The largest sequence is: %d", s+1);
}
see if this works
- 123ayanjit April 15, 2019Are your characters only alphabets?
- 123ayanjit April 15, 2019
Can you give me an example of an output?
- 123ayanjit August 31, 2019