Printf returned no. of character receive .
scanf return no of variable to be inputed according to format specifier . eg:
i=printf("thisisc") printf("%d",i); //i=7 j=scanf("dd",&a,&b,&c,&d); printf("%d",j);
IT IS MOST APPROPRIATE ANSWER FOR THIS Q .......... PLZ DO Practically............
scanf() (see "man 3 scanf") returns an integer signifying how many items were matched and read. It has the side effect of actually doing the reading and assigning of these values.
The return type of scanf() is an int that indicates how many fields were processed or the value EOF that indicates that end-of-file was encountered.
int printf (const char *fmt, ...)orint scanf (const char *fmt, ...)
#include<stdio.h> #include<conio.h> void main() { int a,b,c; int Result; printf("enter the value of a:"); scanf("%d", &a); printf("enter the value of b"); scanf("%d", &b); printf("enter the value of c"); scanf("%d", &c); Result=a*b*c; printf("%d", Result); getch(); }
#include<stdio.h> int main(){ int a[10],i,n,m,c=0; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements of the array: "); for(i=0;i<=n-1;i++){ scanf("%d",&a[i]); } printf("Enter the number to be search: "); scanf("%d",&m); for(i=0;i<=n-1;i++){ if(a[i]==m){ c=1; break; } } if(c==0) printf("The number is not in the list"); else printf("The number is found"); return 0; }
#include<stdio.h> #include<conio.h> #include<math.h> void main() { float len,bre,area; clrscr(); printf("\n\n\t\tEnter the length of the rectangle=\t"); scanf("%d",&len); printf("\n\n\t\tEnter the breadth of the rectangle=\t"); scanf("%d",&bre); printf("\n\n\t\tArea of the rectangle=\t%3f",area=l*b); getch(); }
..use do{} while{}..for example..#includemain(){int choose;double a,b,c;printf("Enter 7 if you want to use the calculator. Otherwise,type any character.\n");scanf("%d",&choose);do{if (choose==7){printf("Press 1 for addition.\n");printf("Press 2 for subtraction.\n");printf("Press 3 for multiplication.\n");printf("Press 4 for division.\n");scanf("%d",&choose);if (choose==1){printf("Enter the addends\n");scanf("%lf %lf", &a,&b);c=a+b,printf("The sum of %lf and %lf is %lf.\n",a,b,c);}else if(choose==2){printf("Enter the minuend and subtrahend\n");scanf("%lf %lf", &a,&b);c=a-b,printf("The difference of %lf and %lf is %lf.\n",a,b,c);}else if(choose==3){printf("Enter the multipliers\n");scanf("%lf %lf", &a,&b);c=a*b,printf("The product of %lf and %lf is %lf.\n",a,b,c);}else if(choose==4){printf("Enter the dividend and divisor\n");scanf("%lf %lf", &a,&b);c=a/b,printf("The quotient of %lf and %lf is %lf.\n",a,b,c);}else{printf("You have entered an invalid digit.\n");}printf("If you want to continue,press 7 and choose again from 1 to 4.\n");printf("Do you want to exit? Enter any key.\n");scanf("%d",&choose);}}while(choose==7);}
well major difference between scanf and printf is that scanf is an input statment and printf is an output stament scanf is used to take data in from the user and printf is used to display the result on the screen Regards
Yes: double d; printf ("scanf's just returned %d\n", scanf ("%lf", &d));
int printf (const char *fmt, ...)orint scanf (const char *fmt, ...)
No, they are variadic.
Printf prints something to the standard output stream, and scanf inputs something from the standard input stream.
do statement; while (condition);ordo { statements } while (condition);
#include<stdio.h> #include<conio.h> void main() { int a,b,c; int Result; printf("enter the value of a:"); scanf("%d", &a); printf("enter the value of b"); scanf("%d", &b); printf("enter the value of c"); scanf("%d", &c); Result=a*b*c; printf("%d", Result); getch(); }
#include<stdio.h> int main(){ int a[10],i,n,m,c=0; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements of the array: "); for(i=0;i<=n-1;i++){ scanf("%d",&a[i]); } printf("Enter the number to be search: "); scanf("%d",&m); for(i=0;i<=n-1;i++){ if(a[i]==m){ c=1; break; } } if(c==0) printf("The number is not in the list"); else printf("The number is found"); return 0; }
#include<stdio.h> #include<conio.h> #include<math.h> void main() { float len,bre,area; clrscr(); printf("\n\n\t\tEnter the length of the rectangle=\t"); scanf("%d",&len); printf("\n\n\t\tEnter the breadth of the rectangle=\t"); scanf("%d",&bre); printf("\n\n\t\tArea of the rectangle=\t%3f",area=l*b); getch(); }
#include <stdio.h> #include <ctype.h> #define n[] int main() { int n, result , answer; int a[n], b[n]; printf("Enter number of terms you would like to use :"); scanf("%d", &n); printf("Enter first vector:\n"); scanf("%d", &a[n]); printf("Enter second vector:\n"); scanf("%d", &b[n]); printf("The dot product is \n" ); return 0; }
..use do{} while{}..for example..#includemain(){int choose;double a,b,c;printf("Enter 7 if you want to use the calculator. Otherwise,type any character.\n");scanf("%d",&choose);do{if (choose==7){printf("Press 1 for addition.\n");printf("Press 2 for subtraction.\n");printf("Press 3 for multiplication.\n");printf("Press 4 for division.\n");scanf("%d",&choose);if (choose==1){printf("Enter the addends\n");scanf("%lf %lf", &a,&b);c=a+b,printf("The sum of %lf and %lf is %lf.\n",a,b,c);}else if(choose==2){printf("Enter the minuend and subtrahend\n");scanf("%lf %lf", &a,&b);c=a-b,printf("The difference of %lf and %lf is %lf.\n",a,b,c);}else if(choose==3){printf("Enter the multipliers\n");scanf("%lf %lf", &a,&b);c=a*b,printf("The product of %lf and %lf is %lf.\n",a,b,c);}else if(choose==4){printf("Enter the dividend and divisor\n");scanf("%lf %lf", &a,&b);c=a/b,printf("The quotient of %lf and %lf is %lf.\n",a,b,c);}else{printf("You have entered an invalid digit.\n");}printf("If you want to continue,press 7 and choose again from 1 to 4.\n");printf("Do you want to exit? Enter any key.\n");scanf("%d",&choose);}}while(choose==7);}
#include <stdio.h> #include<string.h> main() { char s[80]; int d; clrscr(); printf("enter the month of your birthday: "); gets(s); if(!(strcmp(s, "january"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=19) printf("\n CAPRICORN"); else printf("\n AQUARIUS"); } if(!(strcmp(s, "february"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=18) printf("\n AQUARIUS"); else printf("\n PISCES"); } if(!(strcmp(s, "march"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=20) printf("\n PISCES"); else printf("\n ARIES"); } if(!(strcmp(s, "april"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=19) printf("\n ARIES"); else printf("\n TAURUS"); } if(!(strcmp(s, "may"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=20) printf("\n TAURUS"); else printf("\n GEMINI"); } if(!(strcmp(s, "june"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=20) printf("\n GEMINI"); else printf("\n CANCER"); } if(!(strcmp(s, "july"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=22) printf("\n CANCER"); else printf("\n LEO"); } if(!(strcmp(s, "august"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=22) printf("\n LEO"); else printf("\n VIRGO"); } if(!(strcmp(s, "september"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=22) printf("\n VIRGO"); else printf("\n LIBRA"); } if(!(strcmp(s, "october"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=22) printf("\n LIBRA"); else printf("\n SCORPIO"); } if(!(strcmp(s, "november"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=21) printf("\n SCORPIO"); else printf("\n SAGITTARIUS"); } if(!(strcmp(s, "december"))) { printf("\n enter the date of your birthday: "); scanf("%i", &d); if(d<=21) printf("\n SAGITTARIUS"); else printf("\n CAPRICORN"); } getch(); }