[go: up one dir, main page]

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

50 C Loop Programs

The document contains 50 C programming examples that utilize loops for various tasks. It includes programs to print numbers, even and odd numbers, calculate the sum of natural numbers, and generate multiplication tables. Each example is accompanied by code snippets demonstrating the implementation.

Uploaded by

ishantmovva
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)
24 views2 pages

50 C Loop Programs

The document contains 50 C programming examples that utilize loops for various tasks. It includes programs to print numbers, even and odd numbers, calculate the sum of natural numbers, and generate multiplication tables. Each example is accompanied by code snippets demonstrating the implementation.

Uploaded by

ishantmovva
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

50 C Programs Using Loops

1. Print numbers from 1 to N

#include <stdio.h>
int main() {
int n, i;
printf("Enter N: ");
scanf("%d", &n);
for(i = 1; i <= n; i++) {
printf("%d\n", i);
}
return 0;
}

2. Print even numbers from 1 to N

#include <stdio.h>
int main() {
int n, i;
printf("Enter N: ");
scanf("%d", &n);
for(i = 2; i <= n; i += 2) {
printf("%d\n", i);
}
return 0;
}

3. Print odd numbers from 1 to N

#include <stdio.h>
int main() {
int n, i;
printf("Enter N: ");
scanf("%d", &n);
for(i = 1; i <= n; i += 2) {
printf("%d\n", i);
}
return 0;
}

4. Sum of first N natural numbers

#include <stdio.h>
int main() {
int n, sum = 0, i;
printf("Enter N: ");
scanf("%d", &n);
for(i = 1; i <= n; i++) {
sum += i;
}
printf("Sum = %d", sum);
return 0;
}

5. Print multiplication table of a number

#include <stdio.h>
int main() {
int n, i;
printf("Enter number: ");
scanf("%d", &n);
for(i = 1; i <= 10; i++) {
printf("%d x %d = %d\n", n, i, n*i);
}
return 0;
}

You might also like