1.Write a program to print “Hello, World!” on the screen.
2.Write a program to add two integers.
3.Write a program to find the largest of two numbers.
4.Program to check if a number is even or odd.
5.Program to find the sum of first 10 natural numbers.
6. Program to print multiplication table of 5.
7.Program to calculate factorial of a number (e.g., 5).
8.Program to find whether a character is a vowel or consonant.
9. Program to swap two numbers.
10.Program to calculate the square of a number.
ANS OF ALL QUESTION
cCopyEdit#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Explanation:
#include <stdio.h>allows us to use input-output functions.printfprints the message to the console.\nmoves the cursor to the next line.
cCopyEdit#include <stdio.h>
int main() {
int a = 10, b = 20;
int sum = a + b;
printf("Sum = %d\n", sum);
return 0;
}
Explanation:
Two integers are declared and added. %d is used for integer output.
cCopyEdit#include <stdio.h>
int main() {
int a = 10, b = 25;
if (a > b)
printf("%d is larger\n", a);
else
printf("%d is larger\n", b);
return 0;
}
Explanation:
Simple if-else logic checks which number is larger.
cCopyEdit#include <stdio.h>
int main() {
int num = 5;
if (num % 2 == 0)
printf("Even\n");
else
printf("Odd\n");
return 0;
}
Explanation:
An even number leaves remainder 0 when divided by 2.
cCopyEdit#include <stdio.h>
int main() {
int sum = 0;
for (int i = 1; i <= 10; i++)
sum += i;
printf("Sum = %d\n", sum);
return 0;
}
Explanation:
A for loop adds numbers from 1 to 10.
cCopyEdit#include <stdio.h>
int main() {
int num = 5;
for (int i = 1; i <= 10; i++)
printf("%d x %d = %d\n", num, i, num * i);
return 0;
}
Explanation:
A loop multiplies 5 with values from 1 to 10.
cCopyEdit#include <stdio.h>
int main() {
int num = 5, fact = 1;
for (int i = 1; i <= num; i++)
fact *= i;
printf("Factorial = %d\n", fact);
return 0;
}
Explanation:
Factorial is calculated by multiplying numbers from 1 to num.
cCopyEdit#include <stdio.h>
int main() {
char ch = 'e';
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
printf("Vowel\n");
else
printf("Consonant\n");
return 0;
}
Explanation:
Use logical OR to check against all vowels.
cCopyEdit#include <stdio.h>
int main() {
int a = 5, b = 10, temp;
temp = a;
a = b;
b = temp;
printf("a = %d, b = %d\n", a, b);
return 0;
}
Explanation:
Using a temporary variable, values are exchanged.
cCopyEdit#include <stdio.h>
int main() {
int num = 7;
int square = num * num;
printf("Square = %d\n", square);
return 0;
}
Explanation:
Square of a number is the number multiplied by itself.