Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C Help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ManOnMoon
Cheater
Reputation: 0

Joined: 17 Mar 2009
Posts: 26

PostPosted: Wed Feb 03, 2010 1:13 pm    Post subject: C Help Reply with quote

So I am currently taking CSC101 at my university as a required course for EE. However, some parts have really really confused me since I don't know how to approach problems. I was wondering if anyone here could help me with my current lab. I just need to be steered in the right direction as to how I should approach it.

Code:
Laboratory Exercises
In this lab you will write a program, times which generates multiplication tables up to a value given
by the user. I will only give you the specification for the program’s behavior, not tell you how to
design the program.
In the three parts of this lab, you will generate the program in three stages:
1. Design
Since I said above I wouldn’t tell you how to write the program, the first thing you have to do
is to design it to meet the requirements below.
Your program generate an integer multiplication table from 1 to max where the integer max
is read from the user. The program should read max, then show the product of all pairs of
integers from 1 to max, lined up in neat columns, as shown in the following example:
% times
Enter the Maximum: 10
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Feb 03, 2010 5:39 pm    Post subject: Reply with quote

Code:
#include <stdio.h>

int main() {
  int i, k = 1;

  printf("Enter the maximum: ");
  scanf("%d", &i);

  for( int j = 1; k <= i; j++ ) {
    printf("%d ", j*k);

    if( ( j % i ) == 0 ) {
      k++;
      j = 0;
      printf("\n");
    }
  }

  scanf("%d", &i);
  return 0;
}


untested
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Feb 04, 2010 2:53 am    Post subject: Reply with quote

Slugsnack wrote:
untested


You know, they have these amazing new things called "nested for loops". Astounding!

ManOnMoon: This is what you are looking for. Chances are your school doesn't have a C99 compliant compiler, so you may have to move the loop variables to the start of main.

Code:
#include <stdio.h>

int main()
{
   int max;

   printf("Enter the Maximum: ");
   scanf("%d", &max);

   for(int i = 1; i <= max; ++i) {
      for(int j = 1; j <= max; ++j) {
         printf("%3d ", i * j);
      }
      printf("\n");
   }

   return 0;
}
Back to top
View user's profile Send private message
ManOnMoon
Cheater
Reputation: 0

Joined: 17 Mar 2009
Posts: 26

PostPosted: Fri Feb 05, 2010 2:29 am    Post subject: Reply with quote

Thanks a lot guys I will probably look into it tomorow since I have been putting this off. My question is why it works for some reason it just does not make sense to me.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites