top of page

How to print variables in C?

  • a01337106
  • 11 feb 2015
  • 1 Min. de lectura

For this explanation we will need a little program

#include <stdio.h>

int main(){

int a=5;

int b=9;

int sum=a+b;

printf("La suma es : %d \n", sum);

}

We can see that as we have said before, we started the code and opened the main.

Inside we declare three variables: a,b and sum;

The numbers inside a and b will be summed and stored in sum.

Now, for printing we put the printf();

Inside we open start and statement: “La suma es : %d \n”

The text will print as it is written, the term %d refers to a variable, finally de \n indicates to the computer to go to the next line.

After this statement there is a comma and the variable that will be printed.

Note: All the variables are represented with the statement: %d. If you want to call several variables in a statement, you just have to write several times “%d”. The variables assigned to the statement %d will depend on the order in which you call them after the comma.

For example:

int A=1;

int B=2;

int C=3;

print(“Esta es una prueba, variable A: %d, variable B: %d, variable C: %d”,A,B,C);

The printed statement will be:

Esta es una prueba, variable A:1, variable B:2, variable C:3

 
 
 

Comments


 THE ARTIFACT MANIFAST: 

 

This is a great space to write long text about your company and your services. You can use this space to go into a little more detail about your company. Talk about your team and what services you provide. Tell your visitors the story of how you came up with the idea for your business and what makes you different from your competitors. Make your company stand out and show your visitors who you are. Tip: Add your own image by double clicking the image and clicking Change Image.

 UPCOMING EVENTS: 

 

10/31/23:  Scandinavian Art Show

 

11/6/23:  Video Art Around The World

 

11/29/23:  Lecture: History of Art

 

12/1/23:  Installations 2023 Indie Film Festival

 FOLLOW THE ARTIFACT: 
  • Facebook B&W
  • Twitter B&W
  • Instagram B&W
 RECENT POSTS: 
 SEARCH BY TAGS: 

© 2023 by Karla Lugo. Proudly created with Wix.com

bottom of page