Print table of a number entered by user

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 28
Reputation: seo2005 is an unknown quantity at this point 
Solved Threads: 0
seo2005 seo2005 is offline Offline
Light Poster

Print table of a number entered by user

 
0
  #1
Nov 3rd, 2009
Hi,

I would like to print the table of a number entered by the user like

2 *1=2
2*2=4
2*3=6

The code is


  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. main()
  5.  
  6. {
  7.  
  8. int i,num;
  9.  
  10. printf("Enter any number");
  11. scanf("%d",&num);
  12.  
  13. for(i=1;i<=num;i++)
  14.  
  15. printf("%d*%d=%d",num,i,num*i);
  16.  
  17. getch();
  18.  
  19. }

But this code is generating errors.
Last edited by peter_budo; Nov 4th, 2009 at 5:09 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 358
Reputation: dkalita will become famous soon enough dkalita will become famous soon enough 
Solved Threads: 56
dkalita's Avatar
dkalita dkalita is offline Offline
Posting Whiz
 
0
  #2
Nov 3rd, 2009
1> 28 posts and still no code tag

2> Try to practice int main(){} not just main() or void main()

3> Post the exact error that u are getting.
The code seems to be ok I think.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 67
Reputation: Iam3R is an unknown quantity at this point 
Solved Threads: 3
Iam3R Iam3R is offline Offline
Junior Poster in Training
 
0
  #3
Nov 3rd, 2009
The code is perfect and no errors execpt few things that shuold be avoided.
may be you want to print from

5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
:
:
5 * 10 = 50

here is your code with slight modifications and proper posting:
follow this next time
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int i, num;
  6. printf( " Enter any number " );
  7. scanf( "%d", &num );
  8. for( i=1 ;i <=10; i++ )
  9. printf( " \t %d * %d = %d \n ", num, i, num*i ) ;
  10. return 0;
  11. }
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 307 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC