Program 1: Print Multiplication Table
Objective: Print the multiplication table of a number entered by the user.
#include <stdio.h>
void main() {
int num,i,result;
printf("Enter a number: ");
scanf("%d", &num);
for (i = 1; i <= 10; i++) {
result=num*i;
printf("%d x %d = %d\n", num, i, result);
}
}
Program 2: Print First N Natural Numbers
Objective: Input a number N
and print the first N
natural numbers.
#include <stdio.h>
void main() {
int N;
printf("Enter a number: ");
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
printf("%d ", i);
}
}
Program 3: Print the Sum of the First N Natural Numbers
Objective: Input a number N
and find the sum of all natural numbers from 1 to N
#include <stdio.h>
void main() {
int N, sum = 0;
printf("Enter a number: ");
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
sum =sum+i;
}
printf("Sum of first %d natural numbers is: %d\n", N, sum);
}
Program 4: Sum of Digits of a Number
Objective: Input a number and find the sum of its digits.
#include <stdio.h>
void main() {
int num, sum = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);
for (; num != 0; num /= 10) {
remainder = num % 10;
sum += remainder;
}
printf("Sum of digits is: %d\n", sum);
}
Program 4: Sum of Even and Odd Numbers from 1 to N
Objective: Input a number N
and find the sum of all even and odd numbers separately from 1 to N
.
#include <stdio.h>
int main() {
int N, sumEven = 0, sumOdd = 0;
printf("Enter a number: ");
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
if (i % 2 == 0) {
sumEven += i;
}
else
{
sumOdd += i;
}
}
printf("Sum of even numbers: %d\n", sumEven);
printf("Sum of odd numbers: %d\n", sumOdd);
return 0;
}
Complete Rest of the Programs
- Print first
N
natural numbers. - Sum of first
N
natural numbers. - Multiplication table.
- Find the factorial of a number.
- Fibonacci series.
- Check for a prime number.
- Reverse a number.
- Sum of digits.
- Print patterns.
- Sum of even and odd numbers from 1 to
N
.