0% found this document useful (0 votes)
37 views4 pages

Basic C Programs

Uploaded by

Shaik Afreen
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)
37 views4 pages

Basic C Programs

Uploaded by

Shaik Afreen
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

BASIC C PROGRAMS

1. Write a C program on Hello World.

Program:
#include <stdio.h>
int main() {

printf("Hello, world!\n");

return 0;

Output:

Hello, world!

2. Write a C program on Addition of 2 numbers.

Program:
#include <stdio.h>
int main() {

int num1, num2, sum;

printf("Enter two numbers: ");

scanf("%d %d", &num1, &num2);

sum = num1 + num2;

printf("The sum is: %d\n", sum);

return 0;

Output:

Enter two numbers: 10 20


The sum is: 30
3. Write a C program on Arithemetic operations.

Program:
// C program to demonstrate syntax of binary arithmetic
// operators
#include <stdio.h>

int main()
{
int a = 10, b = 4, res;

// printing a and b
printf("a is %d and b is %d\n", a, b);

res = a + b; // addition
printf("a + b is %d\n", res);

res = a - b; // subtraction
printf("a - b is %d\n", res);

res = a * b; // multiplication
printf("a * b is %d\n", res);

res = a / b; // division
printf("a / b is %d\n", res);

res = a % b; // modulus
printf("a %% b is %d\n", res);

return 0;
}

Output:

a is 10 and b is 4
a + b is 14
a - b is 6
a * b is 40
a / b is 2
a % b is 2

4. Write a C program on any one Conditional statement.

Program:

int time = 20;


if (time < 18) {
printf("Good day.");
} else {
printf("Good evening.");
}

Output:

Good evening.

5. Write a C program on any one Looping statements.

Program:

#include<stdio.h>

int main(){

int i=0;

for(i=1;i<=10;i++){

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

return 0;

Output:

1
2
3
4
5
6
7
8
9
10

---THE END---

You might also like