C Variable

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

//Write a program to take an input from user and print it.

#include <stdio.h>

int main()

int myNum;

printf (“Enter the number you wish to print:”);

scanf (“%d”, &myNum);

printf("\nThe number you entered is :%d", myNum);

return 0;

//Write a program to take multiple input from user and print it.

#include <stdio.h>

int main()

int Num1, Num2;

printf (“Enter the First number you wish to print:”);

scanf (“%d”, &Num1);

printf (“\nEnter the Second number you wish to print:”);

scanf (“%d”, &Num2);

printf("\nThe First number you entered is :%d", Num1);

printf("\nThe Second number you entered is :%d", Num2);

return 0;

}
//Write a program to create an integer variable and print it.

#include <stdio.h>

int main()

int myNum = 15; //create an integer variable myNum, and assign value to it.

printf("%d", myNum); // print the output of value assigned to myNum variable.

return 0;

}
//Write a program to add a variable to another variable and print it.

#include <stdio.h>

int main()

int x = 5; // create a variable and assign value to it.

int y = 6; // create a variable and assign value to it.

int sum = x + y; // create a variable and perform the arithmetic operations.

printf("%d", sum); // get the output from the value stored in the variable.

return 0;

}
//Write a program to declare many variable of same type separated by comma and print it.

#include <stdio.h>

int main()

int x = 5, y = 6, z = 50;

printf("%d", x + y + z);

return 0;

}
//Write a program to assign a constant value to a variable which cannot be changed.

#include <stdio.h>

int main()

const int BIRTHYEAR = 1980;

printf("%d", BIRTHYEAR);

return 0;

}
//Write a program using %c for char and %f for float and printing output.
#include <stdio.h>

int main()

// Create variables

int myNum = 5; // Integer (whole number)

float myFloatNum = 5.99; // Floating point number

char myLetter = 'D'; // Character

// Print variables

printf("%d\n", myNum);

printf("%f\n", myFloatNum);

printf("%c\n", myLetter);

return 0;

}
//Write a program to combine both text and variable and printing it output.
#include <stdio.h>

int main()
{
int myNum = 5;
printf("My favorite number is: %d", myNum);
return 0;
}
//Write a program to print different types in a single printf() function
#include <stdio.h>

int main()
{
int myNum = 5;
char myLetter = 'D';
printf("My number is %d and my letter is %c", myNum, myLetter);
return 0;
}

You might also like