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

C Programs Example

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)
13 views2 pages

C Programs Example

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

1.

Print Hello World


#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}

Explanation: Prints Hello, World! to the screen.


Sample Output:
Hello, World!

2. Find Sum of Two Numbers


#include <stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum is %d\n", sum);
return 0;
}

Explanation: Takes two integers from user and prints their sum.
Sample Output:
Enter two numbers: 5 7
Sum is 12

3. Check Even or Odd


#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("%d is even\n", num);
} else {
printf("%d is odd\n", num);
}
return 0;
}

Explanation: Checks if a number is divisible by 2, then prints even or odd.


Sample Output:
Enter a number: 10
10 is even

You might also like