create a login program that ask username and password. if you
input username or password 3 times wrong, the program will
terminate else the program will prompt a message
"congratulations"
Answers were Sorted based on User's Feedback
Answer / lokesh ketha
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char u[10],p[10],user[]="lokesh",pas[]="spiderman";
int n=0;
clrscr();
printf("\n press enter and enter username and password(only
3 attempts)");
while(n<=2)
{
printf("\n Username: ");
scanf("%s",&u);
printf("\n Password: ");
scanf("%s",&p);
if(strcmp(user,u)==0 && strcmp(pas,p)==0)
{
printf("\n Congratulations!");
break;
}
else
{
n++;
printf("\n the username or password is incorrect. only %d
trials left. press enter", 3-n);
}
}
if(n==3)
{
printf("\n you have used maximum attempts(3). please try
later.");
}
getch();
}
| Is This Answer Correct ? | 31 Yes | 19 No |
how can i search an element in an array
2 Answers CTS, Microsoft, ViPrak,
#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }
int a=1; printf("%d %d %d",a++,a++,a); need o/p in 'c' and what explanation too
main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }
int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p
can u give me the c codings for converting a string into the hexa decimal form......
Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }
void main() { int const * p=5; printf("%d",++(*p)); }
3 Answers Infosys, Made Easy, State Bank Of India SBI,
#include<stdio.h> int main() { int x=2,y; y=++x*x++*++x; printf("%d",y); } Output for this program is 64. can you explain how this output is come??
char *someFun1() { char temp[ ] = “string"; return temp; } char *someFun2() { char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’}; return temp; } int main() { puts(someFun1()); puts(someFun2()); }
Under linux environment can u please provide a c code for computing sum of series 1-2+3-4+5......n terms and -1+2-3+4-5...n terms..
void main() { int i=i++,j=j++,k=k++; printf(“%d%d%d”,i,j,k); }