Wednesday, 19 June 2019
Anagram or not.
Question:
Approach:
Step 1: Check Both the String For Equal Length.
if equal then continue, else print Not Anagram.
Step 2: Take A Array for All the Alphabets
And Calculate the no of times that present in the both String
Step 3: Comparing the Array if equal then Anagram
Else not Anagram.
Solution:
#include<stdio.h>
int main()
{
char a[10],b[10];
int i,j,k,m,n,z[26]={0},y[26]={0},flag,c,d;
printf("enter the 2 string");
scanf("%s %s",a,b);
if(strlen(a)!=strlen(b))
printf("not an anagram");
else
{
k=0;
while(k!=26)
{
n=1;
m=1;
for(i=0;i<strlen(a);i++)
{
c=(int)a[i]-97;
d=(int)b[i]-97;
if(k==d)
{
y[k]=m++;
}
if(k==c)
{
z[k]=n++;
}
}
k++;
}
for(j=0;j<26;j++)
{
if(z[j]!=y[j]){
printf("Not anagram");
return 0;
}
}
printf("Anagram");
}
return 0;
}
Approach:
Step 1: Check Both the String For Equal Length.
if equal then continue, else print Not Anagram.
Step 2: Take A Array for All the Alphabets
And Calculate the no of times that present in the both String
Step 3: Comparing the Array if equal then Anagram
Else not Anagram.
Solution:
#include<stdio.h>
int main()
{
char a[10],b[10];
int i,j,k,m,n,z[26]={0},y[26]={0},flag,c,d;
printf("enter the 2 string");
scanf("%s %s",a,b);
if(strlen(a)!=strlen(b))
printf("not an anagram");
else
{
k=0;
while(k!=26)
{
n=1;
m=1;
for(i=0;i<strlen(a);i++)
{
c=(int)a[i]-97;
d=(int)b[i]-97;
if(k==d)
{
y[k]=m++;
}
if(k==c)
{
z[k]=n++;
}
}
k++;
}
for(j=0;j<26;j++)
{
if(z[j]!=y[j]){
printf("Not anagram");
return 0;
}
}
printf("Anagram");
}
return 0;
}
//Credits Rakshita.
Tuesday, 18 June 2019
Monday, 17 June 2019
Sunday, 16 June 2019
Saturday, 15 June 2019
Friday, 14 June 2019
Thursday, 13 June 2019
Wednesday, 12 June 2019
Tricky Interview#1 Solution
Question:
W A C Program That Prints All The vowels Given In String Without Using IF and Break Statements In program?
Solution:
//Credits Gaurav and Swathi H I
#include<stdio.h>
#include<stdlib.h>
main(){
char str[10];
scanf("%s",str);
int i=0;
while(str[i]!='\0'){
(str[i]=='a'|str[i]=='e'|str[i]=='i'|str[i]=='o'|str[i]=='u')? printf("%c",str[i]):printf("");
i++;
}
}
Alternative Solution:
//JavaAbhigyan
#include<stdio.h>
#include<stdlib.h>
main()
{
char str[10],c;
scanf("%s",str);
int i=0;
while((c=str[i])!='\0')
{
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("%c",c);
}
i++;
}
}
Tuesday, 11 June 2019
Aptitude Hack#108(11-6-19)
Question:
A drinks machine offers three selections - Tea, Coffee or Random but the machine has been wired up wrongly so that each button does not give what it claims. If each drink costs 50p, how much minimum money do you have to put into the machine to work out which button gives which selection?
(A) 5 rupees
(B) 10 rupees
(C) 25 rupees
(D) Infinity
A drinks machine offers three selections - Tea, Coffee or Random but the machine has been wired up wrongly so that each button does not give what it claims. If each drink costs 50p, how much minimum money do you have to put into the machine to work out which button gives which selection?
(A) 5 rupees
(B) 10 rupees
(C) 25 rupees
(D) Infinity










