C Do While Loop

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

#include<stdio.h>
#include<conio.h>
int main()
{
   
    int choice;
    system("cls");
  do
{
    printf("\n------------------Menu-----------------------");
    printf("\n 1.Factorial\n 2.Reverse \n 3. Power \n 4.Exit");
    printf("\n-----------------------------------------------");
    printf("\nEnter your choice");
    scanf("%d",&choice);
    switch(choice)
    {
        case 1: 
        {
              int n,f=1;
              printf("\nEnter a number");
              scanf("%d",&n);
              while(n!=0)
              {
                f=f*n;
                n--;
              }
              printf("\nFactorial is %d",f);
              break;
        }
        case 2: 
        {
            int n,r,s=0;
            printf("\nEnter a number");
            scanf("%d",&n);
            while(n!=0)
            {
                r=n%10;
                s=s*10+r;
                n=n/10;
            }
            printf("Reverse is %d",s);
            break;
        }
        case 3: 
        {
            int n,s=1,p;
            printf("\nEnter a number: ");
            scanf("%d",&n);
            printf("\n Enter power: ");
            scanf("%d",&p);
            while(p!=0)
            {
                s=s*n;
                p--;
            }
            printf("Result is %d",s);
            break;
        }   
       case 4: break;  
    }
}while(choice!=4);
   






//    int n;
//    do
//    {
//       printf("\n Enter a number for exit press 0");
//       scanf("%d",&n);
//    } while(n!=0);

    // int i=15;
    // do
    // {
    //     printf("%d\n",i);
    //     i++;
    // } while(i<=10);
    return 0;

}

 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *