0% found this document useful (0 votes)
4 views

Sample Programs

Uploaded by

raagavi109
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Sample Programs

Uploaded by

raagavi109
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<stdio.

h>

int main(){

int number;

printf("enter a number:");

scanf("%d",&number);

printf("cube of number is:%d ",number*number*number);

return 0;

Program to print sum of 2 numbers


Let's see a simple example of input and output in C language that prints
addition of 2 numbers.

#include<stdio.h>

int main(){

int x=0,y=0,result=0;

printf("enter first number:");

scanf("%d",&x);

printf("enter second number:");

scanf("%d",&y);

result=x+y;

printf("sum of 2 numbers:%d ",result);

return 0;

}
Example of variable initialization:

1. #include <stdio.h>

2. int main() {

3. // Variable definition and initialization

4. int age = 25;

5. float salary = 2500.5;

6. char initial = 'J';

7. // Later in the program, you can change the value of the variable

8. age = 30;

9. salary = 3000.0;

10.

11. return 0;

12. }

. C Program to Calculate Fahrenheit to Celsius


#include <stdio.h>

int main() {

float fahrenheit, celsius;

printf(“Enter temperature in Fahrenheit: “);

scanf(“%f”, &fahrenheit);

celsius = (fahrenheit – 32) * 5 / 9;

printf(“Temperature in Celsius: %f\n”, celsius);

return 0;

// A simple arithmetic operation on two integers


#include<stdio.h>

int main() {

int number1, number2, addition, subtraction, multiplication, division, modulo;

printf("Enter two numbers :\n");

scanf("%d%d", & number1, & number2);

addition = number1 + number2;

subtraction = number1 - number2;

multiplication = number1 * number2;

division = number1 / number2;

modulo = number1 % number2;

printf("Addition of number 1 and number 2 : %d\n", addition);

printf("Subtraction of number 1 and number 2 : %d\n", subtraction);

printf("Multiplication of number 1 and number 2 : %d\n", multiplication);

printf("Division of number 1 and number 2 : %d\n", division);

printf("Modulo of number 1 and number 2 : %d\n", modulo);

return 0;

You might also like