Write a program which give table of any number using ‘c language’ .

 

Hello friend’s

Today We make a programme which give table of any number using ‘c language’ ,we are make this programme by all three method means we are make this programme using loop (while , do-while, for)

First we are take a integer ‘i’ and initialise it equal to 1 and give condition less or equal to 10 then increament it and in this programme we take input for user so take another integer ‘n’ and scan it ( mean we are use ‘scanf’ and take input from user) and then modify our programe accordingly.

Now we are write our programme



Using While loop

Sintex for while loop


while (/* condition */)
{
    /* code */
}

 Source Code (while loop)

#include<stdio.h>
int main(){
  int n,i=1;
  printf("table of n=");
  scanf("%d",&n);
 while(i<=10){
  printf("%d*%d=%d\n",n,i,n*i);
  i++;
    }
    return 0;
}

OUTPUT:-

table of n=7

7*1=7

7*2=14

7*3=21

7*4=28

7*5=35

7*6=42

7*7=49

7*8=56

7*9=63

7*10=70

 

 Using do-while loop

Sintex for do-while loop


do
{
    /* code */
while (/* condition */);

Source Code (do-while loop)

   #include<stdio.h>
int main(){
  int n,i=1;
  printf("table of n=");
  scanf("%d",&n);
   do{
   printf("%d*%d=%d\n",n,i,n*i);
   i++;
   }while(i<=10);
    return 0;
}

OUTPUT:-

table of n=23

23*1=23

23*2=46

23*3=69

23*4=92

23*5=115

23*6=138

23*7=161

23*8=184

23*9=207

23*10=230


Using for loop

Sintex for ‘for’ loop


for (size_t i = 0; i < count; i++)
{
    /* code */
}

Source Code (for loop)

#include<stdio.h>
int main(){
  int n,i;
  printf("table of n=");
  scanf("%d",&n);

  for(i=1;i<=10; i++){
  printf("%d*%d=%d\n",n,i,n*i);
    }

  return 0;
}

OUTPUT:-

table of n=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

__________*****__________

0 Comments