WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
What is FASM G
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
 

looking for a bit of jazzing up direction, factoring numbers , but code is boring

gruffy
Quote Post


New Member
*

Group: Members
Posts: 12
Member No.: 43493
Joined: 25-April 11


Hey all, code peeps . Before we start, I have created this, yes actually wrote it, with the very appreciated assistance book "The C Programming Language, 2nd ed". however, i have been trawling the net a little to see if there is anything a bit special i could maybe try on it, only to my surprise........... this code, almost to the letter seems to be plastered everywhere, now im a beginner and firmly believe in learning they way i do, which somoetimes involves BOOKS, now i also have a bloody good idea that the net is a genius resource for beginners to veterans to MVP`s and alike. AND TO BE HONEST I PROBABLY SHOULD OF JUST GOOGLED IT AND DONE THE COPY AND PASTE SHUFFLE (*dont think i would understand as well, but thats just me i think, and anyway, why take the highroad, when the can get a move on when the road is predominantly downhill, no inferences intended here etc )
Anyway, in my inimitable long winded stylee, i just wanted to ask...
...DOES ANYBODY KNOW OF A CLEVER, INSIGHTFUL ROUTE I MIGHT TAKE WITH INSTIGATING A FACTOR FUNCTION IN C ?
Im not good at c yet by a long shot but do like to enjoy the high road*
and just wondered if there was a , dare I say it, next level approach.
Please feel free to tell me to just be happy i got somewhere with it etc....
but if not , im all ears
CODE

#include<stdio.h>
void findfactor(int num)
{
int i;
for(i=1;i<num;i++)
{
if(num%i==0)
printf("Factor for %d is %d\n",num,i);
}
}
main()
{
int a;
printf("\nEnter a number:");
scanf("%d",&a);
findfactor(a);
}
:o

Sponsored Links
PMEmail Poster
Top
gruffy
Quote Post


New Member
*

Group: Members
Posts: 12
Member No.: 43493
Joined: 25-April 11


hi all , just noticed double figured views but no replies, ANY TAKERS ?
ANYTHING TO POINT OUT REGARDING HOW POST IS DELIVERED OR ANYTHING LIKE THAT ?

cool if not, but thought someone might have something up there sleeves etc

Thaks for reading
Gruffy

*UPDATE*
well anyway, i have carried on regardless and come up with this as my conclusive factorising program , hope this helps any people there outwho need a place to start

Gruffy

CODE

/*Gareth Wright 2011,UOP @ South Devon College*/
/*This is free for distribution and expermentation for anyone interested in having a go*/
#include <math.h>                                          // std include header std mathematics
#include <stdlib.h>                                         // std include header std library
#include <stdio.h>                                          // std include header std input/output
#include <windows.h>                                     // std include header for Windows specifics
/*begin function*/
void find_factor(int num)                               // declare function find_factor
{
int i;                                                          // declare variable i
   for(i=1;i<num;i++)                                      // for i = 1 variable & (num) is less than 1, increment i
       {
           if(num%i==0)                                  //  if } % of (var num) == 0
           printf("A factor of %d is %d\n",num,i); // print each factor of inpuutted number
       }
   }/*end function*/

/*begin main program*/
int main()
   {
   char choice;
   int f_num;                                                 // declare variable a
   do{
   system("cls");                                             //(MS_DOS com) Clear screen
   fflush(stdin);                                              // clear input buffer

/*Screen calls*/
   printf("Welcome to the Factoriser ");                // Print to screen (welcome message)
   printf("\nEnter a number here: ");                   // Print to screen (Enter a number)
   scanf("%d",&f_num);                                   // scan key in ("%d")integer input
   find_factor(f_num);                                     // invoke find_factor function on input number

   printf("\nwould you like to use the FACTORISER again\n ");   //Print to screen- use again ?
   printf("\n...Y to have another go\n ");                              //Print to screen- y to repeat
   printf("\nPRESS ANY OTHER KEY TO EXIT THE FACTORISER ");//Print to screen -any other key to exit
   fflush(stdin);                                              //clear std input buffer/remove last var- choice
   scanf("%c", &choice);                                   //scan key for char choice


} while(choice == 'y' || choice == 'Y');                    //do end if choice = y or Y

system("cls");                                                  //(MS_DOS com) Clear screen
printf("\n\nGoodbye, and thanks for using  \n");      //Print to screen- Goodbye message
printf("\n\n\n\n** ** ** ** ** ** ** ** ** **");
printf("\n*************THE*************");
printf("\n*********FACTORISER!*********");
printf("\n**  **  **  **  **  **  ** **\n\n\n\n\n");

   return 0;                                                      //satisfy main program function by returning 0
} //end main program


LIKE I SAID HOPE IT HELPS SOMEONE WITH LEARNING OR SOMETHING ALONG THOSE LINES, LOL...MAYBE EVEN HOW NOT TO DO IT :D
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google