Table of any given number in C language
Mistakes:-
1.) I put "if" instead of "for" loop which led to a huge error in the beginning.
if loop:-
- if (condition) {
// Code to be executed if the condition is true
}
**for loop:-
- for (initialization; condition; update){
}
-initializes a value once then tests the condition after each iteration,
-stops when condition is false.
2.) after putting the loop control statement, i forgot to put { }
// Table of any given number upto 10.
#include <stdio.h>
int main() {
// Declare the variables num, n
int num, n;
// User enters the value of any given number
printf("Enter the value:- ");
scanf("%d", &num);
//Shows which table is being printed
printf("\nThe table of %d", num);
for (n = 1;n <= 10; n++) // for is initialization, condition, increment
{
// Prints the table upto 10
printf("\n%d x %d = %d", num, n, num*n);
}
return 0;
}
No comments:
Post a Comment