0% found this document useful (0 votes)
2 views3 pages

C basic programs

The document contains five C programming examples demonstrating basic operations. These include adding two numbers, printing an integer, finding the ASCII value of a character, determining the sizes of various data types, and swapping two numbers using a temporary variable. Each program includes necessary input/output functions and comments explaining the code.

Uploaded by

rakeshjadhav7625
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

C basic programs

The document contains five C programming examples demonstrating basic operations. These include adding two numbers, printing an integer, finding the ASCII value of a character, determining the sizes of various data types, and swapping two numbers using a temporary variable. Each program includes necessary input/output functions and comments explaining the code.

Uploaded by

rakeshjadhav7625
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Program to add two numbers


#include<stdio.h>
int main()
{
int number1, number2, sum;
Printf(“Enter Two Integers:”);
scanf(“%d %d”, &number1, &number2);
//calculating sum
sum= number1+number2;
printf(“%d + %d = %d”, number1, number2, sum);
return 0;
}

2. Program to print an Integer


#include<stdio.h>
int main()
{
int number;
Printf(“Enter an Integer:”);
scanf( “%d”, &number);
printf(“You Entered: %d”, number);
return 0;
}

3. Program to print ASCII value

#include<stdio.h>
int main()
{
char c;
printf(“Enter a Character:”);
scanf(“%c”, &c);
// %d displays the integer value of a character
//%c displays the actual character
Printf(“ASCII value of %c = %d”, c,c);
Return 0;
}

4. Program to find the size of int, float, double and char


#include<stdio.h>
int main()
{
int inType;
float floatType;
double doubleType;
char charType;
//we use either %lu or %zu Format specifier
/*sizeof(variable) operator computes the size of a variable and to print the
result returned by sizeof*/
printf(“size of int: %lu bytes\n”, sizeof(intType));
printf(“size of float: %lu bytes\n”, sizeof(floatType));
printf(“size of double: %lu bytes\n”, sizeof(doubleType));
printf(“size of char: %lu bytes\n”, sizeof(charType));
return 0;
}

5. Sap numbers using Temporary variable


#include<stdio.h>
Int main() {
double first, second, temp;
printf(“Enter first number:”);
scanf(“%lf”, &first);
printf(“Enter second number:”);
scanf(“%lf”, &second);
// value of first is assigned to temp
temp=first;
//value of second is assigned to first
first=second;
//value of temp(initial value of first) is assigned to second
second=temp;
//%.2lf displays number up to 2 decimal points
printf(“\nAfter swapping first number=%.2lf\n”, first);
printf(“\nAfter swapping second number=%.2lf\n”, second);
return 0;
}

You might also like