0% found this document useful (0 votes)
19 views7 pages

CSC Assignment Medha

The document contains C code snippets to print alphabets from a to z, even numbers from 1 to n, odd numbers from 1 to n, the sum of natural numbers from 1 to n, the sum of even numbers from 1 to n, reading n numbers and calculating their sum and average, and printing the multiplication table of a given number - all using for, while, and do-while loops.

Uploaded by

disa ray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

CSC Assignment Medha

The document contains C code snippets to print alphabets from a to z, even numbers from 1 to n, odd numbers from 1 to n, the sum of natural numbers from 1 to n, the sum of even numbers from 1 to n, reading n numbers and calculating their sum and average, and printing the multiplication table of a given number - all using for, while, and do-while loops.

Uploaded by

disa ray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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;

You might also like