1. Write a C program to print all alphabets from a to z. – using for loop.
#include <stdio.h>
int main()
{
char ch;
printf("Alphabets from 'a' to “for (ch = 'a'; ch <= 'z'; ch++) {
printf("%c ", ch);
}
printf("\n");
return 0;
}
Write a C program to print all even numbers between 1 to n. – using for
loop, while loop, and do while loop.
#include <stdio.h>
int main() {
int n;
// Input the value of n
printf("Enter a value for n: ");
scanf("%d", &n);
printf("Even numbers between 1 and %d are:\n", n);
for (int i = 2; i <= n; i += 2) {
printf("%d ", i);
printf("\n");
return 0;
Write a C program to print all odd numbers between 1 to n. – using for loop,
#include <stdio.h>
int main() {
int n;
// Input the value of n
printf("Enter a value for n: ");
scanf("%d", &n);
printf("Odd numbers between 1 and %d are:\n", n);
for (int i = 1; i <= n; i += 2) {
printf("%d ", i);
printf("\n");
return 0;
Write a C program to find the sum of all natural numbers between 1 to n. –
using for loop, while loop, and do while loop
#include <stdio.h>
int main() {
int n, sum = 0;
// Input the value of n
printf("Enter a value for n: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
sum += i;
printf("The sum of natural numbers from 1 to %d is: %d\n", n, sum);
return 0;
Write a C program to find the sum of all even numbers between 1 to n. – using for loop
#include <stdio.h>
int main() {
int n, sum = 0;
// Input the value of n
printf("Enter a value for n: ");
scanf("%d", &n);
for (int i = 2; i <= n; i += 2) {
sum += i;
printf("The sum of even numbers from 1 to %d is: %d\n", n, sum);
return 0;
Write a C program to find the sum of all natural numbers between 1 to n. – using for loop
#include <stdio.h>
int main() {
int n, sum = 0;
// Input the value of n
printf("Enter a value for n: ");
scanf("%d", &n);
for (int i = 2; i <= n; i += 2) {
sum += i;
printf("The sum of even numbers from 1 to %d is: %d\n", n, sum);
return 0;
Write a program in C to read n numbers from the keyboard and find their
sum and average.
#include <stdio.h>
int main() {
int n, i;
float num, sum = 0, average;
// Input the value of n
printf("Enter the value of n: ");
scanf("%d", &n);
if (n <= 0) {
printf("Invalid input. n must be a positive integer.\n");
return 1; // Exit with an error code
for (i = 1; i <= n; i++) {
printf("Enter number %d: ", i);
scanf("%f", &num);
sum += num;
average = sum / n;
printf("Sum of the numbers is: %.2f\n", sum);
printf("Average of the numbers is: %.2f\n", average);
return 0;
10.Write a C program to print the multiplication table of a given number.
#include <stdio.h>
int main() {
int number;
// Input the number for which you want to print the multiplication table
printf("Enter a number: ");
scanf("%d", &number);
printf("Multiplication table for %d:\n", number);
for (int i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", number, i, number * i);
return 0;