Advertisement
metalx1000

Basic C Program to get user input and add numbers together

Feb 18th, 2024
1,576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int add();
  4.  
  5. int main(){
  6.   printf("Welcome.\n");
  7.  
  8.   int age = 23;
  9.   float money = 2.50;
  10.   char name[] = "User";
  11.  
  12.   printf("Hello %s,\n", name);
  13.   printf("You are %d years old.\n", age);
  14.   printf("You have $%.2f.\n\n", money);
  15.   add();
  16.   return 0;
  17. }
  18.  
  19. int add(){
  20.  
  21.   float A;
  22.   float B;
  23.   float C;
  24.  
  25.   printf("Enter a number: ");
  26.   scanf("%f", &A);
  27.  
  28.   printf("Enter another number: ");
  29.   scanf("%f", &B);
  30.  
  31.   C = A + B;
  32.  
  33.   printf("Total: %f\n", C);
  34.  
  35.  
  36.   return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement