944,059 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1917
  • C RSS
Nov 3rd, 2009
0

Print table of a number entered by user

Expand Post »
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)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
seo2005 is offline Offline
28 posts
since Jun 2009
Nov 3rd, 2009
0
Re: Print table of a number entered by user
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.
Reputation Points: 121
Solved Threads: 61
Posting Pro in Training
dkalita is offline Offline
402 posts
since Sep 2009
Nov 3rd, 2009
0
Re: Print table of a number entered by user
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. }
Reputation Points: 34
Solved Threads: 4
Junior Poster
Iam3R is offline Offline
110 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: 32 bits/64 bits case
Next Thread in C Forum Timeline: read e-mail attachment with POP3





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC