Advertisement
touhid_xml

Sum in C -- FI

Sep 21st, 2016
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main(){
  4.  
  5.     int a;
  6.     char symbol;
  7.     int b;
  8.     int c = a + b;
  9.  
  10.     printf("Enter digit\n");
  11.      while(scanf("%d",&a) != 1)
  12.     {
  13.         printf("Please enter an integer: ");
  14.         while(getchar() != '\n');
  15.     }
  16.     //scanf(" %d", &a);
  17.     printf("Enter + symbol\n");
  18.     fflush(stdin);
  19.     scanf(" %c", &symbol);
  20.     printf("Enter digit\n");
  21.    // scanf(" %d", &b);
  22.      while(scanf("%d",&b) != 1)
  23.     {
  24.         printf("Please enter an integer: ");
  25.         while(getchar() != '\n');
  26.     }
  27.     if(symbol == '+'){
  28.             int sum;
  29.     sum = a + b;
  30.         printf(" %d\n\n", sum);
  31.     }
  32.  
  33.     printf("---------------------------------\n");
  34.     printf("---------------------------------\n");
  35.     printf("\n");
  36.  
  37.     printf("a: %d b: %d c: %c\n", a,b,symbol);
  38.  
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement