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

Q1
Output of the following code- C.

main()
{
  float a=0.7;
  if(a<0.7)
   printf("C");
  else 
   printf("C++);
}

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.

main()
{
   struct emp
   {
   char name[20];
   float sal;
   };
   struct emp e[10];
   int i;
   for(i=0;i<=9;i++)
   scanf("%s %f",e[i]name,&e[i].sal);
}

This looks curiously like homework...

#include <stdio.h>

#define BUFSZ 255

struct lala
{
    char         name[BUFSZ];
    unsigned   age;                  // for example :-)
} student[10];

int main(void)
{
       for(int i=0; i < 10; i++)
           scanf("%s %d", &student[i].name, &student[i].age);

           // Using scanf() for reading strings is in general not a good idea.
           // Look at fgets(). It is more precise and can prevent overflows.

   return 0;
}

<< moderator edit: added [code][/code] tags >>

definitly homework then - lol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.