Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
42 views6 pages

C-Program Lab

This document contains 5 C programming questions involving for loops. The first 3 questions print out the numbers from 1 to a user-input integer n. The fourth question prints even numbers from 2 to n. The fifth question calculates and prints the sum of even numbers from 2 to n.

Uploaded by

YASH BHAI YT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views6 pages

C-Program Lab

This document contains 5 C programming questions involving for loops. The first 3 questions print out the numbers from 1 to a user-input integer n. The fourth question prints even numbers from 2 to n. The fifth question calculates and prints the sum of even numbers from 2 to n.

Uploaded by

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

C-program lab

question
First question
• #include <stdio.h>

• int main() {
• int n, i;

• printf("Enter an integer: ");
• scanf("%d", &n);

• for (i = 1; i <= n; ++i) {
• printf("%d\n", i);
• }

• return 0;
•}
SECOND QUESTION
• #include <stdio.h>

• int main() {
• int i;

• for (i = 1; i <= 10; ++i) {
• printf("%d\n", i);
• }

• return 0;
•}
THIRD QUESTION
• #include <stdio.h>

• int main() {
• int n, i;

• printf("Enter an integer: ");
• scanf("%d", &n);

• for (i = 1; i <= n; ++i) {
• printf("%d\n", i);
• }

• return 0;
•}
FOURTH QUESTION
• #include <stdio.h>

• int main() {
• int n, i;

• printf("Enter an integer: ");
• scanf("%d", &n);

• for (i = 2; i <= n; i += 2) {
• printf("%d\n", i);
• }

• return 0;
•}
FIFTH QUESTION
• #include <stdio.h>

• int main() {
• int n, i, sum = 0;

• printf("Enter an integer: ");
• scanf("%d", &n);

• for (i = 2; i <= n; i += 2) {
• sum += i;
• }

• printf("Sum of even numbers from 1 to %d: %d\n", n, sum);

• return 0;
•}

You might also like