#include<stdio.h> #include<conio.h> void main() { int a,b,c; int menu; printf("choose the arithmetic option\n"); scanf("%d",&menu); switch(menu) { case 1: printf("Enter The Two Numbers:\n"); scanf("%d%d",&a,&b); c=a+b; printf("The addition of two numbers %d\n",c); break; case 2: printf("Enter THE TWO NUMBERS:\n"); scanf("%d%d",&a,&b); c=a-b; printf("The subtraction of two numbers %d\n",c); break; case 3: printf("Enter THE TWO NUMBERS:\n"); scanf("%d%d",&a,&b); c=a*b; printf("The multiplication of two numbers %d\n",c); break; case 4: printf("Enter THE TWO NUMBERS:\n"); scanf("%d%d",&a,&b); c=a/b; printf("The division of two numbers %d\n",c); break; } getch(); }
#include <stdio.h> #include <conio.h> int main() { int a,b,c,d; printf("Enter any 4 numbers"); scanf("%d%d%d%d",&a,&b,&c,&d); if(a>b&&a>c) { else if(a>d) printf("%d is greatest",a); } if(b>a&&b>c) { else if(b>d){ printf("%d is greatest",b); } if(c>a&&c>b) { else if(c>d) printf("%d is greatest",c); } else { printf("%d is greatest",d); } }
main() { int i,c=0,sum=0; scanf("%d",&i); while(i>=0) { i=i%2; sum=sum+i*pow(10,c); i=i/2; c++ } printf("%d",sum); } OR =) #include<stdio.h> #include<conio.h> void showbits(int h) { if(h==1) printf("%d",h); else { showbits(h/2); printf("%d",h%2); } } void main() { int nu; void showbits(int h); clrscr(); printf("Num?");scanf("%d",&nu); printf("\nBin eq of %d is ",nu); showbits(nu); getch(); }
#include<stdio.h> #include<stdlib.h> main() { int number,binary[10000],b=0; printf("Enter decimal number "); scanf("%d",&number); printf("\nBinary: "); for(;number;number/=2,b++) binary[b]=number%2; for(b--;b>-1;b--) printf("%d ",binary[b]); }
#include<stdio.h> #include<conio.h> void main() { int i,c,n; printf("Enter the number of terms you want which are divisible by 7"); scanf("%d",&n); c=0; for(i=7;;i+=7) { printf("\n %d ",i); c++; if(c==n) break; } getch(); }
printf , scanf , getchar, putchar, getc are the other operators in C except gets and puts..
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
#include<stdio.h> #include<conio.h> void main() { int a,b,c; int menu; printf("choose the arithmetic option\n"); scanf("%d",&menu); switch(menu) { case 1: printf("Enter The Two Numbers:\n"); scanf("%d%d",&a,&b); c=a+b; printf("The addition of two numbers %d\n",c); break; case 2: printf("Enter THE TWO NUMBERS:\n"); scanf("%d%d",&a,&b); c=a-b; printf("The subtraction of two numbers %d\n",c); break; case 3: printf("Enter THE TWO NUMBERS:\n"); scanf("%d%d",&a,&b); c=a*b; printf("The multiplication of two numbers %d\n",c); break; case 4: printf("Enter THE TWO NUMBERS:\n"); scanf("%d%d",&a,&b); c=a/b; printf("The division of two numbers %d\n",c); break; } getch(); }
#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();}
The C standard library IO facilities are not extensible. For instance, the printf() and scanf() functions cannot handle user-defined types. However, the C++ standard library provides IO streams with insertion and extraction operators (<< and >>) that can be overloaded to support any user-defined type.
void main() { int a,b,c; clrscr(); printf("Enter the value of a:"); scanf("%d",&a); printf("\nEnter the value of b:"); scanf("%d",&b); printf("\nEnter the value of c:"); scanf("%d",&c); if(a>b) { if(a>c) { if(b>c) { printf("c is smallest\n"); printf("b is middle\n"); printf("a is largest\n"); } else { printf("b is smallest\n"); printf("c is middle\n"); printf("a is largest\n"); } } else { printf("b is smallest\n"); printf("a is middle\n"); printf("c is largest\n"); } } else if(b>c) { if(a>c) { printf("c is smallest\n"); printf("a is middle\n"); printf("b is largest\n"); } else { printf("a is smallest\n"); printf("c is middle\n"); printf("b is largest\n"); } } else { printf("a is smallest\n"); printf("b is middle\n"); printf("c is largest\n"); } getch(); }
to write and read the values
..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> main() { int i,j,k,n; char c; printf("enter the # of rows of graphical output\n"); scanf("%d",&n); printf("enter the character you want to print\n"); scanf("%c",&c); for(i=1;i<=n;i++) { for (k=1;k<=(n-i);k++) { printf(" "); } for(j=0;j<i;j++) { printf("%c",c); printf(" "); } for(k=1;k<=(n-i-1);k++) { printf(" "); } printf("\n"); } 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); }
do statement; while (condition);ordo { statements } while (condition);
#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; }