How do you loop a program to display your name however times you want it to.

And to display " Hello %s!! Do you want to try again [Y/N]? "

Showing Answers 1 - 9 of 9 Answers

Insert your name. input the number of times you want to display the name.Use any loop and display the name that number of times

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. main()

  4. {

  5. int i,n;

  6. char name[100];

  7. clrscr();

  8. printf("enter name:");

  9. scanf("%s",name);

  10. printf("how many times you want to display your name:");

  11. scanf("%d",&n);

  12. for(i=1;i<=n;i++)

  13. printf("%s

  14. ",name);

  15. getch();

  16. }

  Was this answer useful?  Yes

Rajath

  • Aug 5th, 2011
 

Read the name from the user and until his choice becomes 0 keep printing his input name through the while loop

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3.  

  4. int main()

  5. {

  6.     int i,n;

  7.     char name[100];

  8.     int a=1;

  9.     printf("enter name:");

  10.     scanf("%s",name);

  11.     while(a!=0)

  12.     {

  13.         printf("%s",name);

  14.         printf("

  15. Do you want to continue [1] or not[0]?

  16. ");

  17.         scanf("%d",&a);

  18.     }

  19. }

  20.  

  Was this answer useful?  Yes

jyothisudi

  • Aug 6th, 2011
 

Here is the code

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. void main()

  4. {

  5. int i,n;

  6. char name[100],ch;

  7. do

  8. {

  9. printf("enter your name");

  10. scanf("%s",&name);

  11. printf("enter the number of times you want to repeat the loop");

  12. scanf("%d",&n);

  13. for(i=0;i<n;i++)

  14. printf("%s",name);

  15. printf("Hello %s!!! do you want to try again Y/N",name);

  16. getchar(ch);

  17. }

  18. while(ch=='Y')

  19. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions