C language loops | do while loop 2

Question:6
C Program to take input for 3 numbers, check and print the lowest number. Add the continue condition?
Sol:

#include <stdio.h>

int main()
{
   int a,b,c,m;
   char ch;
   do
   {
       printf("Enter 3 nos ");
       scanf("%d %d %d",&a,&b,&c);
       if(a<b && a<c)
        m=a;
       else
        if(b<c)
        m=b;
       else
        m=c;
       printf("Min no = %d\n",m);

       printf("Like to cont ... (y/n) ");
       fflush(stdin);
       scanf("%c",&ch);
   }while(ch=='y' || ch=='Y');

    return 0;
}

Output:

Enter 3 nos 14
95
6
Min no = 6
Like to cont … (y/n) y
Enter 3 nos 26
35
85
Min no = 26
Like to cont … (y/n) n

Question:7
C Program to take input for a number and print its table, add the continue condition?
Sol:

#include <stdio.h>

int main()
{
   int n,i,t;
   char ch;
   do
   {
       printf("Enter any no ");
       scanf("%d",&n);
       for(i=1;i<=10;i++)
       {
           t=n*i;
           printf("%d * %d = %d\n",n,i,t);
       }

       printf("Like to cont ... (y/n) ");
       fflush(stdin);
       scanf("%c",&ch);
   }while(ch=='y' || ch=='Y');

    return 0;
}

Output:

Enter any no 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
Like to cont … (y/n) n

Question:8
C Program to take input for a number and print its factorial, add the continue condition?
Sol:

#include <stdio.h>

int main()
{
   int n,i,f;
   char ch;
   do
   {
       printf("Enter any no ");
       scanf("%d",&n);
       f=1;
       for(i=1;i<=n;i++)
       {
           f=f*i;
       }
       printf("fact = %d\n",f);

       printf("Like to cont ... (y/n) ");
       fflush(stdin);
       scanf("%c",&ch);
   }while(ch=='y' || ch=='Y');

    return 0;
}

Output:

Enter any no 4
fact = 24
Like to cont … (y/n) y
Enter any no 5
fact = 120
Like to cont … (y/n) n

Question:9
C Program to calculate the value of x to the power y. By taking input of base and power. Add the continue condition?
Sol:

#include <stdio.h>

int main()
{
   int b,p,r,i;
   char ch;
   do
   {
       printf("Enter values of base and power ");
       scanf("%d %d",&b,&p);
       r=1;
       for(i=1;i<=p;i++)
       {
           r=r*b;
       }
       printf("result  = %d\n",r);

       printf("Like to cont ... (y/n) ");
       fflush(stdin);
       scanf("%c",&ch);
   }while(ch=='y' || ch=='Y');

    return 0;
}

Output:

Enter values of base and power 2
3
result = 8
Like to cont … (y/n) y
Enter values of base and power 2
5
result = 32
Like to cont … (y/n) n

C Language Programming Tutorial

C Language Tutorial Home     Introduction to C Language     Tokens     If Condition      goto statement and Labelname     Switch Statements     For loop     While Loop     Do while loop     break and continue     Functions     Recursion     Inbuild Functions     Storage Classes     Preprocessor     Arrays     Pointers     Structures and Unions     File Handling     Projects