• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

store and print the input numbers entered by user

Status
Not open for further replies.

Parth86

Member
Hi
I want to write c program that will store and print the input numbers entered by user. I have doubt I know how to print any number on screen but I don't know what logic use in c programming to store user input
my effort
C:
#include <stdio.h>
int main()
{
       int number;
 
    printf("Enter an integer: "); 

    scanf("%d", &number); 

   printf("display  entered value : %d", number);
 
    return 0;
}
I have tested this program when I enter any number I see that numbers display on Screen. I just want to know how does user input store in c programming I mean wichh logic statement is use to store data. I think we use for loop , array , pointer . In this case how to decide what will store user input.
 
Last edited:

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
The variable "number" is allocated for input... There is no error checking in that code, so if a non number is pressed, number will be corrupted..

scanf() is a formatted scan routine that will allow you to input the number, it will convert the number, then it will store it in "number"..
 

Parth86

Member
The variable "number" is allocated for input... There is no error checking in that code, so if a non number is pressed, number will be corrupted..

scanf() is a formatted scan routine that will allow you to input the number, it will convert the number, then it will store it in "number"..
ok. can you help me with small example because when I try to understand big program I feel difficulty
suppose we have three buttons
first for number "1"
second for number "2"
third for "+"
forth for "result "

program
enter fist operand and print on screen
enter operator and print on screen
enter second operand and print on screen
display result on screen

it will better if you will try to explain embedded c program. my goal to understand logic how do you apply logic to make any program
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
So! You want a simple calculator program for an 8051 in C?

When the user presses the first button, a 1 is stored.. When the user presses the second button, 2 is stored.. then + and finally a result is displayed...
C:
void main()
 {
 int first, second, third;
 char buff[] = {"Press the keys"};
 Lcd_init();
 init_ser();
 for( ; ; )
  {
    Lcd_line(1);
    Lcd_write(buff);
    while(BUT1);
    first = 1;
    Lcd_xy(1,2);
    Lcd_data(first + 0x30);
    while(BUT2);
    second = 2;
     Lcd_xy(3,2);
     Lcd_data(second + 0x30);
     while(BUT3);
     Lcd_xy(2,2);
     Lcd_data('+'); 
     Lcd_xy(4,2);
     Lcd_data('=');
     third = second + first;
     Lcd_xy(5,2);
     Lcd_data(third + 0x30);
  }
 }
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top