944,125 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2959
  • C++ RSS
Jun 27th, 2005
0

help needed in floating point

Expand Post »
I have 2 problems in C regarding floating point, please help :

Q1
Output of the following code- C.
C++ Syntax (Toggle Plain Text)
  1. main()
  2. {
  3. float a=0.7;
  4. if(a<0.7)
  5. printf("C");
  6. else
  7. printf("C++);
  8. }
  9.  
But if we change the if condition from a<0.7 to a<0.7f we get output- C++.

Q2
The following code gives runtime error- Floating point formats not linked. When does this error occur in a program.
C++ Syntax (Toggle Plain Text)
  1. main()
  2. {
  3. struct emp
  4. {
  5. char name[20];
  6. float sal;
  7. };
  8. struct emp e[10];
  9. int i;
  10. for(i=0;i<=9;i++)
  11. scanf("%s %f",e[i]name,&e[i].sal);
  12. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
akshayabc is offline Offline
15 posts
since Jun 2005
Jun 27th, 2005
0

Re: help needed in floating point

This looks curiously like homework...
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Jun 27th, 2005
0

Re: help needed in floating point

C++ Syntax (Toggle Plain Text)
  1. #include <stdio.h>
  2.  
  3. #define BUFSZ 255
  4.  
  5. struct lala
  6. {
  7. char name[BUFSZ];
  8. unsigned age; // for example :-)
  9. } student[10];
  10.  
  11. int main(void)
  12. {
  13. for(int i=0; i < 10; i++)
  14. scanf("%s %d", &student[i].name, &student[i].age);
  15.  
  16. // Using scanf() for reading strings is in general not a good idea.
  17. // Look at fgets(). It is more precise and can prevent overflows.
  18.  
  19. return 0;
  20. }
<< moderator edit: added [code][/code] tags >>
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
freemind is offline Offline
62 posts
since Jun 2005
Jun 27th, 2005
0

Re: help needed in floating point

Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jun 27th, 2005
0

Re: help needed in floating point

definitly homework then - lol
Reputation Points: 10
Solved Threads: 1
Newbie Poster
oboler is offline Offline
13 posts
since Jun 2005
Jun 28th, 2005
0

Re: help needed in floating point

No its not a homework, i found these questions in an indian author book- "Test your C skills" by Yashwant Kanitker. Answers were given but not reasons for that answers.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
akshayabc is offline Offline
15 posts
since Jun 2005

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: coding problem
Next Thread in C++ Forum Timeline: Linking Error...





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


Follow us on Twitter


© 2011 DaniWeb® LLC