They do different things, read the manual/help for details.
Here is a program that would calculate the change of a dollar: #include <stdio.h> int main(); { float total=0; float bill=0; float pay=0; printf("How much do you have to pay: "); scanf("%f", &bill); printf("How much did you give out: "); scanf("%f", &pay); total = bill - pay; printf("Your change is: %.2f", total); /*.2 meant 2 digits after the decimal*/ getchar(); getchar(); /*I use getchar(); to pause the program till you press 'enter'*/ return 0; } Here is the program running: How much many do you have to pay: 5.64 /*5.64 is user input*/ How much many did you give out: 4.72 /*You can redo the questions if need be*/ Your change is: 0.92 /*This is where you press 'enter' to close the program from the getchar();*/ I hope this helped :D
Use the scanf() function from the C standard library.
Certainly. That's what sequence %s is good for.
gets()Reads characters from stdin and stores them as a string into str until a newline character ('\n') or the End-of-File is reached.The ending newline character ('\n') is not included in the string.getchar()Returns the next character from the standard input (stdin).It is equivalent to getc with stdin as its argument. === ===
cause getchar only read a character and scanf read only word before first space but not other words and letters.
#include,stdio.h>main(){char string1[20],string2[20]printf("enter the first string");scanf("%s",string1);// reading the string1printf("enter the second string");scanf("%s", string2);// reading the the string2printf( "the first string is %s",string1);// printing the string1printf("the second string is %s",string2);// printing the string2}the problem of using scanf is that it does not take space. so we can use gets for it.ie instead of scanf("%s",string1); we can use gets(string1); .
Yes,we can compile our program without header file without any error,but we can not use any predefine functions like printf,scanf.
in c simply add three lines in the begining of your program: int x; printf("enter the size of the array to be entered :"); scanf("%d",&x); after that use x as your maximum limit of array in your program. in c++ just replace above printf & scanf statements by cout<<"enter the size of the array to be entered :"; & cin>>x; respectively and do not use brackets.
Yes: double d; printf ("scanf's just returned %d\n", scanf ("%lf", &d));
scanf is a function, not a statement. Example: int a; char name[12]; scanf ("%d %s", &a, &name[0]);
Use '%s', eg: char name[64]; scanf ("%s", name);
Because of how the program is written you need to use punctuation instead of spaces.