Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Header file



Working with switch case



Test expression



Comment



Iterative statement




Summation, Subtraction, Multiplication and division



// AHF C PROGRAM SOLVING

//solving here basic type of programming problem

#include<stdio.h> #include<math.h> #include<stdlib.h> #define pf printf int main() { int choice; while(1){ pf("\nEnter your choice "); pf("\nEnter 1 for summation "); pf("\nEnter 2 for subtraction "); pf("\nEnter 3 for multiplication "); pf("\nEnter 4 for division .......... "); pf("\nEnter 5 to Exit .......... "); scanf("%d",&choice); switch(choice) { case 1: { int x,y,sum=0; pf("\nEnter first and second number: "); scanf("%d %d",&x,&y); sum=x+y; pf("\nThe summation = %d",sum); } break; case 2: { int x,y,sub=0; pf("\nEnter first and second number: "); scanf("%d %d",&x,&y); sub=x-y; pf("\nThe summation = %d",sub); } break; case 3: { int x,y,mul=0; pf("\nEnter first and second number: "); scanf("%d %d",&x,&y); mul=x*y; pf("\nThe summation = %d",mul); } break; case 4: { float x,y,div=0; pf("\nEnter first and second number: "); scanf("%f %f",&x,&y); div=x/y; pf("\nThe summation = %f",div); } break; case 5: exit(1); default : pf("\nInvalid Input."); } } return 0; }
OUTPUT:


© 2018 - All rights reserved