0

Good day everyone,

Hope you could help me on this one

The program is running but the result is far from what I want please help me... TIA

Like this one:

Input:
------------------------------------
Enter first number: 7
Enter second number: 45
------------------------------------


Output:

------------------------------------
7.45
7.00
------------------------------------


which should be my target output is:
------------------------------------
7.45
7.45
------------------------------------

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
   char str1[80],str2[80];
   int num1, num2;
   float num3;

   clrscr();

   printf("Enter first number: ");
   scanf("%d",&num1);
   printf("Enter second number: ");
   scanf("%d",&num2);

   sprintf(str1,"%d.",num1);
   sprintf(str2,"%d",num2);

   strcat(str1,str2);
   printf("%s\n",str1);

   num3 = atoi(str1);
   printf("%.2f",num3);

   getch();
}

Thanks in advanced again!:)

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

lines 17 and 18 can be combined sprintfstr1,("%d.%d", num1, num2); , then delete line 20 which calls strcat(), and delete str2 because it is not needed.

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.