C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 2nd, 2012, 12:15 PM
balvinder87 balvinder87 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 3 balvinder87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 35 m 54 sec
Reputation Power: 0
Prime fibonacci program

A C program that inputs a number and check if it is prime and also belongs to fibonacci

Reply With Quote
  #2  
Old September 2nd, 2012, 01:11 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 19 h 21 m 53 sec
Reputation Power: 1774
OK, so where is YOUR attempt at an answer?

You can't just wander in and start issuing demands for answers on a plate with no effort on your part.
homework

And when you do post some code, please make sure it has [code][/code] tags.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old September 2nd, 2012, 01:14 PM
artheus artheus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Location: Stockholm
Posts: 9 artheus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 38 sec
Reputation Power: 0
Quote:
Originally Posted by balvinder87
A C program that inputs a number and check if it is prime and also belongs to fibonacci


Are you asking for one?

Maybe you could use these links for creating one yourself? :

# Check if number is prime or not
http://www.programmingsimplified.com/c/source-code/c-program-for-prime-number

# Function for creating N fibonacci numbers
http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-c

For checking if the number is NOT a fibonacci number you could just run the sequence until the fibonacci number is more than the number you are checking.

May be a good idea to cache the numbers too, maybe to a file, so you don't have to calculate the numbers every time you're checking a number.

Cheers,
Artheus

Reply With Quote
  #4  
Old September 2nd, 2012, 02:12 PM
balvinder87 balvinder87 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 3 balvinder87 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 35 m 54 sec
Reputation Power: 0
my code is like this can you give the error

#include<stdio.h>
main()
{
int n, c = 2,k,result;

printf("Enter a number to check if it is prime and fibonacci\n");
scanf("%d",&n);

for ( c = 2 ; c <= n - 1 ; c++ )
{
if ( n%c == 0 )
{
printf("%d is not prime.\n", n);
break;
}
}
if ( c == n )
k=n;
;
fibonacci(k);

return 0;
}


int fibonacci(int n)
{
int a = 0;
int b = 1;
int sum;
int i;
while(sum<n)
{
sum = a + b;
a = b;
b = sum;
if (sum==n)
printf("%d",sum);
}
return 0;
}

Reply With Quote
  #5  
Old September 2nd, 2012, 02:58 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,141 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 23 h 51 m 26 sec
Reputation Power: 1974
Your first error is that you did not use code tags as you had been instructed to do!

Code:
#include<stdio.h>
 main()
{
   int n, c = 2,k,result;
 
   printf("Enter a number to check if it is prime and fibonacci\n");
   scanf("%d",&n);
 
   for ( c = 2 ; c <= n - 1 ; c++ )
   {
      if ( n%c == 0 )
      {
         printf("%d is not prime.\n", n);
	 break;
      }
   }
   if ( c == n )
       k=n;
       ;
       fibonacci(k);
 
   return 0;
}

 
int fibonacci(int n)
{
int a = 0;
int b = 1;
int sum;
int i;
while(sum<n)
{
 sum = a + b;
    a = b;
    b = sum;
    if (sum==n)
    printf("%d",sum);
    }
    return 0;
    }

Your second error is that you did not tell us why you think that there's any error. If you get sick and go you see a doctor, do you refuse to describe your symptoms to him? Of course you wouldn't, so why play that stupid guessing game with us?

Are you getting error messages when you compile? What about warnings, which are even more important than error messages? For that matter, if you have not turned warnings on, then you need to do so immediately and always. And you need to not only tell us that that's what happens, but also you need to tell us what the messages are.

Or does the program compile but you get unexpected results when you run it? In that case, you need to tell us what happens. Does the program crash? Does it ignore your input and/or produce no output? Is the output different than what you expected? In that case, you need to tell us what it had output, what you expected, and what input(s) you had given the program to produce that output.

A third obvious error is that you failed to provide a prototype for the fibonacci function. Also, since that function does not provide any meaningful return value and main ignores it anyway, there is no need for fibonacci to be declared as returning int. Explain why you did that.

Reply With Quote
  #6  
Old September 2nd, 2012, 04:26 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,384 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 48 m 49 sec
Reputation Power: 383
Here are some prime numbers also Fibonacci computed in j http://www.jsoftware.com
Code:
   (1 p: ])Filter (, [: +/ _2&{.)^:40(0 1)
2 3 5 13 89 233 1597 28657 514229
   


Use them as test values---also use numbers that are different than these but between---like 90 or 28000---as test cases. Oh---

Filter=: (#~`)(`:6)

(in plain language: "copy those that satisfy the condition")
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Prime fibonacci program

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap