Anonymous
Anonymous
And it will compile
Jhagrut
And it will compile
I did it mam and it compiled I also had done mistake in variable so I changed them to convenient ones but 1 why was it showing error pointing out the precision 2 now that it has successfully compiled It is showing wrong answer
Jhagrut
#include<stdio.h> #include<stdlib.h> int main() { int w; float ab,c; //printf("write your withdraw amount"); scanf("%d\n", &w); //printf("write your bank balance"); scanf("%.2f\n", &ab); //.2f is for points of precision c=w+0.5; if (ab>c && w%5==0) { printf("%.2f\n", ((ab-w)-0.5) ) ; //new balance on successful transaction } else{ printf("%.2f\n", ab) ; } return 0; }
Jhagrut
You normally do not put precision in a scanf
If for example user provides an input with precision upto 5 digits and I want to perform an operation based on only two digit decision then what to do in that case
Jhagrut
What would be the right answer and what's the program's answer?
#include<stdio.h> int main() { int w; float t; scanf("%d%f",&w,&t); if(w+0.5>t) { printf("%f",t); } else if(w%5!=0) { printf("%f",t); } else { printf("%f",t-w-0.5); } return 0 ; }
Jhagrut
This answer has been accepted by the program given by some other user
C.
In the printfs you put %.2f
C.
Just not in the scanf
Jhagrut
Just not in the scanf
Tyvm sir my answer got accepted
Jhagrut
i'm having issue to Concatenate the strings
vps Pro
Hey gays .l am begging to learn C , and i need tiny ide to compile code (*.exe) . thanks
C.
Put your code in pastebin.
vps Pro
Jhagrut
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { int i = 4; double d = 4.0; char s[] = "HackerRank "; int j; float k; char l[100]; scanf("%d%f", &j,&k); for (int m=0;m<100;m++) scanf("%c\n", &l[i]); printf("%d\n", i+j); // Print the sum of the double variables on a new line. printf("%.1f\n", d+k); // Concatenate and print the String variables on a new line // The 's' variable above should be printed first. printf("%c", s); for(int o=0;o<100;o++) printf("%c", l[o]); return 0; }
Jhagrut
Task Complete the code in the editor below. The variables , , and are already declared and initialized for you. You must: Declare variables: one of type int, one of type double, and one of type String. Read lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your variables. Use the operator to perform the following operations: Print the sum of plus your int variable on a new line. Print the sum of plus your double variable to a scale of one decimal place on a new line. Concatenate with the string you read as input and print the result on a new line. Note: If you are using a language that doesn't support using for string concatenation (e.g.: C), you can just print one variable immediately following the other on the same line. The string provided in your editor must be printed first, immediately followed by the string you read as input. Input Format The first line contains an integer that you must sum with . The second line contains a double that you must sum with . The third line contains a string that you must concatenate with . Output Format Print the sum of both integers on the first line, the sum of both doubles (scaled to decimal place) on the second line, and then the two concatenated strings on the third line.
Jhagrut
Sample Input 12 4.0 is the best place to learn and practice coding! Sample Output 16 8.0 HackerRank is the best place to learn and practice coding!
Jhagrut
printf("%s", s); for(int o=0;o<100;o++) printf("%c", l[o]);
Jhagrut
sir if i remove this for loop how to print the second string to be input by the stdin
C.
With %s
Jhagrut
printf("%s", s); printf("%s", l); return 0;
Jhagrut
Your Output (stdout) HackerRank Expected Output HackerRank is the best place to learn and practice coding!
Jhagrut
sir can u pls tell me how to correct this i have to attach user input of character string
Jhagrut
scanf("%s", l); printf("%s", s); printf("%s", l); return 0; Your Output (stdout) HackerRank is expected HackerRank is the best place to learn and practice coding!
Jhagrut
here i removed the first loop and tried to run but it is printing only 1 word not the sentence
Jhagrut
for (int m=0;m<100;m++) { getchar(); ch=getchar(); l[i]=ch; } printf("%s", s); for (int n=0;n<100;n++) printf("%c", l[n]);
Jhagrut
Jhagrut
tried getchar but got this as output
Jhagrut
pls help me out
Anonymous
https://pastebin.com/wFLtG0XT
Anonymous
why does it start a new line in this code, when i print out the data inputed in fgets
Jarvis .....
Hello world
Anonymous
std::cout << “Sup” << std::endl;
Ибраги́м
std::cout << “Sup” << std::endl;
That's exactly how NOT to do it!
Anonymous
sorry no endl
Anonymous
\n
Ибраги́м
Ибраги́м
NOT >>
Anonymous
cin
C.
cin
Cin >> Cout <<
Anonymous
sorry
Anonymous
lol
Anonymous
all fixed now
C.
Lol
Anonymous
been a while
C.
write(1, "Heyo!/n", 6);
Ибраги́м
all fixed now
Still failing to build
Anonymous
https://pastebin.com/wFLtG0XT
can some help me with this
C.
Still failing to build
Skxhbdksnsks missing main?
C.
can some help me with this
I'm not home rn
Ибраги́м
Anonymous
not equal ?
Ибраги́м
not equal ?
You clearly need proper learning.
Anonymous
when using fgets in C, and then using printf, how do you get it to not start a new line
C.
True
Anonymous
Anonymous
ok ...
C.
Look at the quotations
Anonymous
Disappear with '/n'
https://pastebin.com/wFLtG0XT
C.
After receiving the input you can either truncate it (awful choice. Never do this) Or you can find the character and change it to "end of the string" character ('/0').
Anonymous
i just updated telegram , didnt realize they have a dark mode
Anonymous
In the string
can you provide some syntax
Anonymous
\n
did you see the pastebin
I_Interface
did you see the pastebin
nope, but it can't be "/n" for the new line certainly