int printf (const char *fmt, ...)
or
int scanf (const char *fmt, ...)
main() { char firstname[10], middlename[10],lastname[20]; clrscr(); printf("\nEnter First Name :"); scanf("%s", firstname); printf("\nEnter Middle Name :"); scanf("%s", middlename); printf("\nEnter Last Name :"); scanf("%s", lastname); printf("\n%c. %c. %s",firstname[0],middlename[0],lastname); getch(); } I did it just for sake of time pass.............
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............
#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(); }
#include <stdio.h> main() { FILE *a; int sno,tm,em,mm,scm,sm,hm; char sname[20],any[1]; clrscr(); a=fopen("student.dat","a"); do { printf("Enter Student Number : "); scanf("%d",&sno); printf("Enter Student Name : "); scanf("%s",sname); printf("Enter Telugu Marks : "); scanf("%d",&tm); printf("Enter English Marks : "); scanf("%d",&em); printf("Enter Maths Marks : "); scanf("%d",&mm); printf("Enter Science Marks : "); scanf("%d",&scm); printf("Enter Social Marks : "); scanf("%d",&sm); printf("Enter Hindi Marks : "); scanf("%d",&hm); fprintf(a,"%d %s %d %d %d %d %d %d\n",sno,sname,tm,em,mm,scm,sm,hm); printf("Do you wish to continue(Y/N)"); scanf("%s",any); }while(strcmp(any,"y")==0); fclose(a); }
..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));
No, they are variadic.
Printf prints something to the standard output stream, and scanf inputs something from the standard input stream.
main() { char firstname[10], middlename[10],lastname[20]; clrscr(); printf("\nEnter First Name :"); scanf("%s", firstname); printf("\nEnter Middle Name :"); scanf("%s", middlename); printf("\nEnter Last Name :"); scanf("%s", lastname); printf("\n%c. %c. %s",firstname[0],middlename[0],lastname); getch(); } I did it just for sake of time pass.............
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............
#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(); }
main() {int nLength, nWidth, A, B; printf ("enter length: "); scanf ("%d", nLength); printf ("enter Width: "); scanf ("%d", nWidth); for(A=1;1<=nWidth;A++) printf ("*"); printf ("\n"); for (A = 2; A <= nLength -1; A++) printf ("*"); for (B = 2; B <= nWidth -1; B++) printf ("*"); printf ("\n");
#include#includevoid main(){ int a,b,c;printf("\nEnter 1st no.");scanf("%d",&a);printf("\nEnter 2nd no.");scanf("%d",&b);c=a;a=b;b=c;printf("\n1st no.",a);printf("\n2nd no.",b);getch();}
#include <stdio.h> main() { FILE *a; int sno,tm,em,mm,scm,sm,hm; char sname[20],any[1]; clrscr(); a=fopen("student.dat","a"); do { printf("Enter Student Number : "); scanf("%d",&sno); printf("Enter Student Name : "); scanf("%s",sname); printf("Enter Telugu Marks : "); scanf("%d",&tm); printf("Enter English Marks : "); scanf("%d",&em); printf("Enter Maths Marks : "); scanf("%d",&mm); printf("Enter Science Marks : "); scanf("%d",&scm); printf("Enter Social Marks : "); scanf("%d",&sm); printf("Enter Hindi Marks : "); scanf("%d",&hm); fprintf(a,"%d %s %d %d %d %d %d %d\n",sno,sname,tm,em,mm,scm,sm,hm); printf("Do you wish to continue(Y/N)"); scanf("%s",any); }while(strcmp(any,"y")==0); fclose(a); }
we write printf() b/c it printf or show us the value contained in a value on the screen after pressing ctrl+f9.
do statement; while (condition);ordo { statements } while (condition);