0
[SOLVED] What's wrong with this code?
//This code is not working. 😢 //Expected output: 15 1000 abc (in different line) #include <stdio.h> int main(){ int a=10,b=5; float salary = 1000.00; char name = 'abc'; int c=a+b; printf ("%d \n", c); printf ("%f \n", salary); printf ("%c \n", name); return 0; }
2 Antworten
+ 5
Because you can only store one character in char value.
What you can do is to use an array.Like this:
char name[]="abc"//remember the quotation must be in double quote.
Then print the name as string.
printf("%s",name);
If you don't want the additional 00 in the end of the salary you can declare the salary to int or you can use printf("0.0f \n",salary);//but it will round the salary to the nearest int.
Here's the code:
https://code.sololearn.com/csA3AaojYYM2
Next time please try this:
https://www.sololearn.com/post/75089/?ref=app
+ 1
Thank you very much 😇