Table of any Number
/***************************************************** Table of any Number ******************************************************/ #include< stdio.h> #include< conio.h> void main() { int i,no,table=1; clrscr(); printf("Enter any number : "); scanf("%d",&no); clrscr(); printf("Table of %d ",no); for(i=1;i< =10;i++) { table=no*i; printf(" \n %d",table); printf("\n"); } getch(); }
Output
Enter any number : 5 Table of 5 5 10 15 20 25 30 35 40 45 50
Explanation of Program
for(i=1;i< =10;i++) { table=no*i; printf(" \n %d",table); printf("\n"); }
In the above Code execute for loop from 1 to 10, and given number is multiplyby 1 and next itteration number is multiply by 2 and at third itteration number is multiply by 3,........10. and there results are print on screen
Table of any Number using while loop
/*************************************************************** Table of any Number ***************************************************************/ #include< stdio.h> #include< conio.h> void main() { int a=1,no,table=1; clrscr(); printf("enter any no. = "); scanf("%d",&no); while(a< =10) { table=a*no; printf("%d",table); printf("\n"); a++; } getch(); }
Output
Find Table of any Number using Recursion
/*********************************************************** Table of any Number ************************************************************/ #include< stdio.h> #include< conio.h> void main() { int table(int,int); int n,i; clrscr(); printf("Enter any num = "); scanf("%d",&n); for(i=1;i< =10;i++) { printf(" %d*%d= %d\n",n,i,table(n,i)); } getch(); } int table(n,i) { int t; if(i==1) { return(n); } else { return(table(n,i-1)+n); } }
Output
No comments:
Post a Comment