Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views2 pages

Basic C Programs With Header

This document provides basic C programming examples, including printing a name, adding two numbers, taking user input, checking if a number is odd or even, multiplying two numbers, and calculating simple interest. Each example includes the code and a sample output. These examples serve as fundamental exercises for beginners learning C programming.

Uploaded by

kalaivanant
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)
6 views2 pages

Basic C Programs With Header

This document provides basic C programming examples, including printing a name, adding two numbers, taking user input, checking if a number is odd or even, multiplying two numbers, and calculating simple interest. Each example includes the code and a sample output. These examples serve as fundamental exercises for beginners learning C programming.

Uploaded by

kalaivanant
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/ 2

Basic C Programming Examples - With Output

1. Print Your Name


#include <stdio.h>

int main() {
printf("My name is Kalaivanan.\n");
return 0;
}
Sample Output:

My name is Kalaivanan.

2. Add Two Numbers


#include <stdio.h>

int main() {
int a = 5, b = 3, sum;
sum = a + b;
printf("Sum = %d\n", sum);
return 0;
}
Sample Output:

Sum = 8

3. Input and Output of a Number


#include <stdio.h>

int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered: %d\n", num);
return 0;
}
Sample Output:

Enter a number: 7

You entered: 7

4. Check Odd or Even


#include <stdio.h>

int main() {
int number;
printf("Enter a number: ");
Basic C Programming Examples - With Output

scanf("%d", &number);

if (number % 2 == 0) {
printf("%d is Even.\n", number);
} else {
printf("%d is Odd.\n", number);
}

return 0;
}
Sample Output:

Enter a number: 5

5 is Odd.

5. Multiply Two Numbers (Input from user)


#include <stdio.h>

int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("Product = %d\n", a * b);
return 0;
}
Sample Output:

Enter two numbers: 4 6

Product = 24

6. Simple Interest Calculator


#include <stdio.h>

int main() {
float p, r, t, si;
printf("Enter principal, rate, and time: ");
scanf("%f %f %f", &p, &r, &t);
si = (p * r * t) / 100;
printf("Simple Interest = %.2f\n", si);
return 0;
}
Sample Output:

Enter principal, rate, and time: 1000 5 2

Simple Interest = 100.00

You might also like