Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Long Question

C-Language Solved Program (Past Papers)


All Punjab Boards

Table of Contents
WRITE A PROGRAM IN C-LANGUAGE THAT INPUTS A CHARACTER FROM USER AND DETERMINES WHETHER IT IS A VOWEL OR
CONSONANT? (BWP – 2012) (SWL – 2016) (SWL – 2017) (SGD – 2016) (SGD – 2018) (LHR – 2016) ............................... 3
WRITE A PROGRAM THAT INPUTS MARKS AND DISPLAYS " CONGRATULATIONS " IF THE MARKS ARE 40 OR MORE. (BWP –
2014) ......................................................................................................................................................................................... 3
WRITE A PROGRAM THAT INPUT MARKS FROM USER AND DISPLAY ‘PASS’. IF MARKS ARE GREATER OF OR EQUAL TO 40
OTHERWISE ‘FAIL;? (LHR – 2015) .............................................................................................................................................. 3
WRITE A PROGRAM IN C - LANGUAGE TO ACCEPT A YEAR FROM THE KEYBOARD. FIND OUT IT IS " LEAP YEAR " OR " NOT LEAP
YEAR ". [HINT | LEAP YEAR IS DIVISIBLE BY 4] (BWP – 2016) (BWP – 2018) (DGK – 2016) (FSB – 2015) (FSB – 2018) (MLT
– 2016) (MLT – 2018) ............................................................................................................................................................... 4
WRITE A PROGRAM IN C LANGUAGE THAT INPUTS A NUMBER FROM USER AND FINDS WHETHER IT IS POSITIVE NEGATIVE,
ZERO. (BWP – 2017) (FSB – 2012) (RWP – 2014) (SHWL – 2012) (SGD – 2012) (SGD – 2015) (SGD – 2017) (LHR –
2017) ......................................................................................................................................................................................... 4
WRITE A PROGRAM IN C – LANGUAGE THAT INPUTS A NUMBER FROM USER AND PRINTS THE TABLE OF NUMBER TO BE
ENTERED BY USER. (BWP – 2019) (FSB – 2019) (FSB – 2021) (MLT – 2015) (SGD – 2021).................................................. 4
WRITE A PROGRAM TO PRINT ODD NUMBERS FROM 1 TO 20 USING LOOP. (BWP – 2021)...................................................... 5
WRITE A PROGRAM IN C TO DISPLAY THE FOLLOWING SERIES USING LOOP. (BWP – 2023) ..................................................... 5
WRITE A PROGRAM THAT INPUT VALUE FROM USER AND TELL WHETHER IT IS DIVISIBLE BY 3 OR NOT. (DGK – 2012) .......... 5
WRITE A PROGRAM THAT INPUTS A NUMBER AND DISPLAYS THE MASSAGE "PRIME NUMBER" IF IT IS A PRIME NUMBER.
(DGK – 2013) (FSB – 2013) ..................................................................................................................................................... 6
WRITE A PROGRAM THAT INPUT A NUMBER AND FINDS WHETHER IT IS EVEN OR ODD USING IF-ELSE STRUCTURE. (DGK –
2014) (DGK – 2017) (DGK – 2018) (MLT – 2014) (MLT – 2017) (RWP – 2015) (SWL – 2015)............................................ 6
WRITE A PROGRAM THAT DISPLAYS THE FIRST 15 EVEN NUMBERS. (DGK – 2015) .................................................................. 7
WRITE A PROGRAM IN C-LANGUAGE TO PRINT THE SUM OF FOLLOWING SERIES. 0 3 6 9 12 15 (DGK – 2019)........................ 7
WRITE A PROGRAM IN C-LANGUAGE TO PRINT THE FOLLOWING SERIES. 0 3 6 9 12 15 (SWL – 2023) ..................................... 7
WRITE A PROGRAM THAT INPUTS A NUMBER FROM THE USER AND DISPLAYS THE FACTORIAL OF THAT NUMBER USING
WHILE OR FOR LOOP STRUCTURE. (DGK – 2021) (SGD – 2019) (LHR – 2019) ....................................................................... 8
WRITE A PROGRAM IN C LANGUAGE THAT ACCEPTS THREE NUMBERS FROM USER AND DISPLAY THE SMALLEST NUMBER
USING NESTED IF. (DGK – 2022) ............................................................................................................................................... 8
WRITE A PROGRAM IN C THAT ACCEPTS THREE NUMBERS FROM THE USER AND DISPLAY THE MINIMUM NUMBER USING
NESTED IF. (LHR – 2012) ........................................................................................................................................................... 8
WRITE A PROGRAM THAT INPUTS A CHARACTER AND CHECKS WHETHER IT IS VOWEL OR CONSONANT USING SWITCH
STATEMENT. (FSB – 2014) (FSB – 2022) (RWP – 2016) (RWP – 2022) ................................................................................. 9
WRITE A PROGRAM IN C THAT INPUTS THE NUMBER OF THE MONTH OF THE YEAR AND DISPLAY THE NUMBER OF DAYS OF
THE CORRESPONDING MONTH USING IF - ELSE - IF STATEMENT. (E.G. IF USER ENTERS 2, IT WILL DISPLAY 28 OR 29). (FSB –
2016) ......................................................................................................................................................................................... 9

P a g e 1 | 16
WRITE A PROGRAM IN C-LANGUAGE THAT INPUTS TEMPERATURE AND DISPLAY MESSAGE ACCORDING TO FOLLOWING (FSB
– 2017) (SGD – 2022) ............................................................................................................................................................. 10
WRITE A PROGRAM THAT GETS STARTING AND ENDING POINT FROM THE USER AND DISPLAYS ALL ODD NUMBER IN THE
GIVEN RANGE USING LOOP. (FSB-2023)................................................................................................................................. 10
WRITE A PROGRAM THAT PRINTS THE FOLLOWING SERIES USING LOOP: 19 16 13 10 7 4 1 (LHR – 2023) .............................. 11
WRITE A PROGRAM IN C THAT ACCEPTS THREE NUMBERS FROM THE USER AND DISPLAY THE MINIMUM NUMBER USING
NESTED IF. (LHR – 2013) ...... 11
WRITE A PROGRAM IN C THAT TAKES A NUMBER FROM USER, CALCULATE THE SQUARE – ROOT OF THE NUMBER IF IT IS
POSITIVE AND PRINT THE RESULT. (MLT-2012) ...................................................................................................................... 11
WRITE A PROGRAM THAT DISPLAYS FIRST FIVE NUMBERS WITH THEIR SQUARES. (MLT-2013) ............................................. 12
WRITE A PROGRAM IN C-LANGUAGE WHICH DOES DISPLAYS THE SUM OF FOLLOWING SERIES USING ANY LOOP. 1 + 1\2 + 1\4
+ 1\6 +………….. + 1\100 (MLT-2023) ....................................................................................................................................... 12
WRITE A PROGRAM IN C-LANGUAGE WHICH PRINTS THE SUM OF THE FOLLOWING SERIES BY USING LOOP: 1+ 1/2 + 1/3 + 1/4
+…. 1/N (RWP – 2023) ............................................................................................................................................................ 12
WRITE A PROGRAM THAT DISPLAYS PRODUCTS OF ALL ODD NUMBERS FROM 1 TO 10 USING FOR-LOOP. (RWP – 2013) (LHR
– 2021) .................................................................................................................................................................................... 13
WRITE DOWN A PROGRAM IN C-LANGUAGE THAT INPUTS TWO NUMBERS FROM USER AND FINDS WHETHER THEY ARE
EQUAL OR NOT. (RWP – 2017) (SGD – 2014) ........................................................................................................................ 13
WRITE A PROGRAM TO INPUT TWO INTEGER VALUES AND AN ARITHMETIC OPERATOR CALCULATES ARITHMETIC OPERATION
DEPENDING UPON USER INPUT OPERATOR USING SWITCH STATEMENT. (SWL – 2014) ........................................................ 13
WRITE A PROGRAM THAT PRINT ODD MEMBERS FROM 11 TO 49 USING LOOP. (SWL – 2019) .............................................. 14
WRITE A PROGRAM THAT PRINTS EVEN NUMBERS BETWEEN ( 1 TO 100 ) USING FOR LOOP. (SWL – 2021) .......................... 14
WRITE A PROGRAM IN C-LANGUAGE THAT ACCEPTS THREE NUMBERS FROM THE USER AND DISPLAY THE LARGEST NUMBER
USING NESTED IF. (SWL – 2022) (LHR – 2014) (LHR – 2019) (BWP – 2915) ...................................................................... 15
WRITE A PROGRAM IN C-LANGUAGE THAT ACCEPTS THREE NUMBERS FROM THE USER AND DISPLAY THE MAXIMUM
NUMBER USING IF ELSE IF. (LHR – 2022) ................................................................................................................................ 15
WRITE A PROGRAM IN C TO INPUT THE STARTING NUMBER AND ENDING NUMBER AND TO DISPLAY ALL EVEN NUMBERS IN
THE GIVEN RANGE USING DO-WHILE-LOOP. (SGD – 2013) ..................................................................................................... 16
WRITE A PROGRAM IS C LANGUAGE WHICH PRINTS THE SUM OF THE FOLLOWING SERIES BY USING LOOPS: 1 + 4 + 9 + 16 + 25
+ … + 256 (SGD – 2023) .......................................................................................................................................................... 16

P a g e 2 | 16
Write a program in C-Language that inputs a character from user and determines whether it is a vowel or
consonant? (BWP – 2012) (SWL – 2016) (SWL – 2017) (SGD – 2016) (SGD – 2018) (LHR –
2016)
#include <stdio.h>
#include <conio.h>
void main()
{
char ch;
clrscr();
printf("Enter a character: ");
scanf(" %c", &ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' ||
ch == 'U')
printf("%c is a vowel.\n", ch);
else
printf("%c is a consonant.\n", ch);
getch();

Write a program that inputs marks and displays " congratulations " if the marks are 40 or more. (BWP – 2014)
#include <stdio.h>
#include <conio.h>
void main()
{
int marks;
clrscr();
printf("Enter marks: ");
scanf("%d", &marks);
if (marks >= 40)
printf("Congratulations!\n");
getch();
}

Write a program that input marks from user and display ‘pass’. If marks are greater of or equal to 40 otherwise
‘fail;? (LHR – 2015)
#include <stdio.h>
#include <conio.h>
void main()
{
int marks;
clrscr();
printf("Enter marks: ");
scanf("%d", &marks);
if (marks >= 40)
printf("PASS");
else
printf(“FAIL”);
getch();
}

P a g e 3 | 16
Write a program in C - Language to accept a year from the Keyboard. Find out it is " Leap Year " OR " Not Leap
Year ". [Hint | Leap Year is Divisible by 4] (BWP – 2016) (BWP – 2018) (DGK – 2016) (FSB – 2015)
(FSB – 2018) (MLT – 2016) (MLT – 2018)

#include <stdio.h>
#include <conio.h>
void main()
{
int year;
clrscr();
printf("Enter a year: ");
scanf("%d", &year);
if (Year % 4 == 0 )
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
getch();

Write a program in C language that inputs a number from user and finds whether it is positive negative, zero.
(BWP – 2017) (FSB – 2012) (RWP – 2014) (SHWL – 2012) (SGD – 2012) (SGD – 2015)
(SGD – 2017) (LHR – 2017)
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf("Enter a number: ");
scanf("%d", &n);

if (n > 0)
printf("Positive number.\n");
else if (n < 0)
printf("Negative number.\n");
else
printf("Number is Zero.\n");
getch();
}

Write a Program in C – Language that inputs a number from user and prints the table of number to be entered by
user. (BWP – 2019) (FSB – 2019) (FSB – 2021) (MLT – 2015) (SGD – 2021)
Suppose the number entered is 5, the output will be as follows:-
5*1=5
5 * 2 = 10
5 * 3 = 15
---
-- --
5 * 10 = 50
#include <stdio.h>
P a g e 4 | 16
#include <conio.h>
void main()
{
int t, i;
clrscr()
printf("Enter Table Number: ");
scanf("%d", &t);
printf("Table of %d:\n", t);
for (i = 1; i <= 10; i++)
{
printf("%d * %d = %d\n", t, i, t * i);
}
getch();
}

Write a program to print odd Numbers from 1 to 20 using loop. (BWP – 2021)
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
clrscr();
printf("Odd numbers from 1 to 20:\n");
for (n = 1; n <= 20; n+=2)
{
printf("%d\n", n);
}
getch();
}

Write a program in c to display the following series using loop. (BWP – 2023)
0 2 4 6 8 10 12 14 16
#include <stdio.h>
#include <conio.h>
void main()
{
int n;
printf("Series: ");
for (n = 0; n <= 16; n += 2)
{
printf("%d ", n);
}
getch();
}

Write a program that input value from user and tell whether it is divisible by 3 or Not. (DGK – 2012)
#include <stdio.h>
#include <conio.h>
void main()
{
int num;
clrscr();
P a g e 5 | 16
printf("Enter a number: ");
scanf("%d", &num);
if (num % 3 == 0)
printf("%d is divisible by 3.\n", num);
else
printf("%d is not divisible by 3.\n", num);
getch();
}

Write a program that inputs a number and displays the massage "Prime Number" if it is a prime number. (DGK
– 2013) (FSB – 2013)
#include <stdio.h>
#include <conio.h>
void main()
{
int num, i, flag = 0;
clrscr();
printf("Enter a number: ");
scanf("%d", &num);

for (i = 2; i <= num; i++)


{
if (num % i == 0)
{
flag = 1;
break;
}
}

if (num == 1)
printf("1 is not a prime number.\n");
else {
if (flag == 0)
printf("%d is a prime number.\n", num);
else
printf("%d is not a prime number.\n", num);
}
}

Write a program that input a number and finds whether it is even or odd using if-else structure. (DGK – 2014)
(DGK – 2017) (DGK – 2018) (MLT – 2014) (MLT – 2017) (RWP – 2015) (SWL – 2015)

#include <stdio.h>
#include <conio.h>
void main()
{
int num;
clrscr();
printf("Enter a number: ");
scanf("%d", &num);

if (num % 2 == 0)
printf("%d is even.\n", num);

P a g e 6 | 16
else
printf("%d is odd.\n", num);
getch();
}

Write a program that displays the first 15 even numbers. (DGK – 2015)
#include <stdio.h>
#include <conio.h>
void main()
{
int num = 2;
clrscr();
printf("First 15 even numbers:\n");
while (num < 15)
{
printf("%d\n", num);
num = num + 2;
}
getch();
}

Write a program in C-Language to print the sum of following series. 0 3 6 9 12 15 (DGK – 2019)
#include <stdio.h>
#include <conio.h>
void main()
{
int sum = 0, i;
clrscr();
printf("Series: ");
for (i = 0; i <= 15; i += 3)
{
printf("%d ", i);
sum = sum + I;
}
printf("\nSum of the series: %d\n", sum);
getch();
}

Write a program in C-Language to print the following series. 0 3 6 9 12 15 (SWL – 2023)

#include <stdio.h>
#include <conio.h>
void main()
{
int , i;
clrscr();
printf("Series: ");
for (i = 0; i <= 15; i += 3)
{
printf("%d ", i);
}
getch();
}

P a g e 7 | 16
Write a program that inputs a number from the user and displays the factorial of that number using while or for
loop structure. (DGK – 2021) (SGD – 2019) (LHR – 2019)
#include <stdio.h>
#include <conio.h>
void main()
{
int num, fact = 1, i = 1;;
clrscr();
printf("Enter a number: ");
scanf("%d", &num);
while (i <= num)
{
fact *= i;
i++;
}
printf("Factorial of %d is %d\n", num, fact);
getch();
}

Write a program in C language that accepts three numbers from user and display the smallest number using
nested if. (DGK – 2022)

Write a program in C that accepts three numbers from the user and display the minimum number using nested if.
(LHR – 2012) (LHR – 2013)
#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, c;
clrscr();
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if (a <= b)
{
if (a <= c)
printf("The smallest number is: %d\n", a);
else
printf("The smallest number is: %d\n", c);
}
else
{
if (b <= c)
printf("The smallest number is: %d\n", b);
else
printf("The smallest number is: %d\n", c);
}
getch();
}

P a g e 8 | 16
Write a program that inputs a character and checks whether it is vowel or consonant using switch statement.
(FSB – 2014) (FSB – 2022) (RWP – 2016) (RWP – 2022)
#include <stdio.h>
#include <conio.h>
void main()
{
char ch;
printf("Enter a character: ");
scanf(" %c", &ch);
switch (ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("%c is a vowel.\n", ch);
break;
default:
printf("%c is a consonant.\n", ch);
}
getch();
}

Write a program in C that inputs the number of the month of the year and display the number of days of the
corresponding month using if - else - if statement. (e.g. if user enters 2, it will display 28 or 29). (FSB – 2016)
#include <stdio.h>
#include <conio.h>
void main()
{
int month, days;
clrscr();
printf("Enter the number of the month: ");
scanf("%d", &month);

if (month == 2)
days = 28; // Assuming non-leap year
else if (month == 4 || month == 6 || month == 9 || month == 11)
days = 30;
else
days = 31;

printf("Number of days in month %d: %d\n", month, days);


getch();
}

P a g e 9 | 16
Write a program in C-language that inputs temperature and display message according to following (FSB –
2017) (SGD – 2022)
Temperature Message

Greater than 35 Hot day

Between 25 and 35 (inclusive) Pleasant day

Less than 25 Cool day

#include <stdio.h>
#include <conio.h>
void main()
{
float temp;
clrscr();

printf("Enter the temperature: ");


scanf("%f", &temp);

if (temp > 35)


printf("Hot day\n");
else if (temp >= 25 && temp <= 35)
printf("Pleasant day\n");
else
printf("Cool day\n");

getch();
}

Write a program that gets starting and ending point from the user and displays all odd number in the given range
using loop. (FSB-2023)
#include <stdio.h>
#include <conio.h>
void main()
{
int start, end, i;
// Getting starting and ending points from the user
printf("Enter the starting point: ");
scanf("%d", &start);
printf("Enter the ending point: ");
scanf("%d", &end);

printf("Odd numbers between %d and %d are:\n", start, end);

for (i = start; i <= end; i++)


{
if (i % 2 != 0)
{
printf("%d\n", i);
}
}
getch();
}

P a g e 10 | 16
Write a program that prints the following series using loop: 19 16 13 10 7 4 1 (LHR – 2023)
#include <stdio.h>
#include <conio.h>

void main()
{

int num = 19;


clrscr();
while (num >= 1)
{
printf("%d ", num);
num -= 3;
}
getch();
}

Write a program that display first five numbers and their sum using while loop. (LHR – 2013)
#include <stdio.h>
#include <conio.h>
void main()
{
int c = 1, sum = 0;
clrscr();
printf("The first five numbers are:\n");

while (c <= 5)
{
printf("%d ", c);
sum = sum + c;
c++;
}
printf("\nSum of the first five numbers: %d\n", sum);
getch();
}

Write a program in C that takes a number from user, calculate the square – root of the number if it is positive and
print the result. (MLT-2012)
#include <stdio.h>
#include <math.h>
#include <conio.h>
void main()
{
float num, squareRoot;
clrscr();
printf("Enter a number: ");
scanf("%f", &num);

if (num >= 0)
{
squareRoot = sqrt(num);
printf("Square root of %0.2f is %0.2f\n", num, squareRoot);

P a g e 11 | 16
}
else
{
printf("Number should be non-negative to calculate square root.\n");
}
getch();
}

Write a program that displays First Five numbers with their squares. (MLT-2013)
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
clrscr();
printf("Number\t Square\n");
for (i = 1; i <= 5; i++)
{
printf("%d \t %d\n", i, i * i);
}
getch();
}

Write a program in C-Language which does displays the sum of following series using any loop. 1 + 1\2 + 1\4 + 1\6
+………….. + 1\100 (MLT-2023)

#include <stdio.h>
#include <conio.h>
void main()
{
int i;
float sum = 0.0;
clrscr();
for (i = 1; i <= 100; i++)
{
sum = sum + 1.0 / (2 * i);
}
printf("Sum of the series: %0.2f \n", sum);
getch();
}

Write a program in C-language which prints the sum of the following series by using loop: 1+ 1/2 + 1/3 + 1/4 +….
1/n (RWP – 2023)

#include <stdio.h>
#include <conio.h>
void main()
{
int n, i;
float sum = 0.0;
clrscr();
P a g e 12 | 16
printf("Enter a Positive Integer : ");
scanf("%d", &n);

for (i = 1; i <= n; i++)


{
sum = sum + 1.0 / i;
}

printf("Sum of the series: %0.2f \n", sum);


getch();
}

Write a program that displays products of all odd numbers from 1 to 10 using for-Loop.

(RWP – 2013) (LHR – 2021)


#include <stdio.h>
#include <conio.h>
void main()
{
int product = 1, i;
clrscr();
for (i = 1; i <= 10; i += 2)
{
product *= i;
}
printf("Product of all odd numbers from 1 to 10: %d\n", product);
getch();
}

Write down a program in C-language that inputs two numbers from user and finds whether they are equal or not.
(RWP – 2017) (SGD – 2014)
#include <stdio.h>
#include <conio.h>
void main()
{
int num1, num2;
clrscr();
printf("Enter Two Numbers: ");
scanf("%d %d", &num1, &num2);

if (num1 == num2)
printf("Numbers are equal.\n");
else
printf("Numbers are not equal.\n");
getch();
}

Write a program to input two integer values and an arithmetic operator calculates arithmetic operation
depending upon user input operator using switch statement. (SWL – 2014)
#include <stdio.h>
#include <conio.h>

P a g e 13 | 16
void main()
{
int num1, num2;
char op;
clrscr();
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
printf("Enter an arithmetic operator [+, -, *, /]: ");
scanf(" %c", &op);

switch (op)
{
case '+':
printf("Result: %d\n", num1 + num2);
break;
case '-':
printf("Result: %d\n", num1 - num2);
break;
case '*':
printf("Result: %d\n", num1 * num2);
break;
case '/':
printf("Result: %d\n", num1 / num2);
break;
default:
printf("Invalid operator.\n");
}
getch();

Write a program that print odd members from 11 to 49 using loop. (SWL – 2019)
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
clrscr();
printf("Odd numbers from 11 to 49: \n");
for (i = 11; i <= 49; i += 2)
{
printf("%d\n", i);
}
getch();
}

Write a program that prints even numbers between ( 1 to 100 ) using for loop. (SWL – 2021)
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
clrscr();
P a g e 14 | 16
printf("Even numbers between 1 to 100:\n");
for (i = 2; i <= 100; i += 2)
{
printf("%d\n", i);
}
getch();
}

Write a program in C-language that accepts three numbers from the user and display the largest number using
nested if. (SWL – 2022) (LHR – 2014) (LHR – 2019) (BWP – 2915)
#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, c;
clrscr();
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);

if (a > b)
{
if (a > c)
printf("%d is the largest number.\n", a);
else
printf("%d is the largest number.\n", c);
}
else
{
if (b > c)
printf("%d is the largest number.\n", b);
else
printf("%d is the largest number.\n", c);
}
getch();
}

Write a program in C-language that accepts three numbers from the user and display the maximum number using
if else if. (LHR – 2022)
#include <stdio.h>
#include <conio.h>
void main()
{
int a, b, c;
clrscr();
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);

if (a > b && a > c)


{
printf("Maximum number: %d\n", a);
}
else if (b > a && b > c)
{
P a g e 15 | 16
printf("Maximum number: %d\n", b);
}
else
{
printf("Maximum number: %d\n", c);
}
getch();
}

Write a program in C to input the starting number and ending number and to display all even numbers in the
given range using do-while-loop. (SGD – 2013)
#include <stdio.h>
#include <conio.h>
void main()
{
int start, end;
clrscr();
printf("Enter starting and ending numbers: ");
scanf("%d %d", &start, &end);

printf("Even numbers between %d and %d are:\n", start, end);


do
{
if (start % 2 == 0)
{
printf("%d\n", start);
}
start++;
} while (start <= end);
getch();
}
Write a program is C Language which prints the sum of the following series by using loops: 1 + 4 + 9 + 16 + 25 + … +
256 (SGD – 2023)
#include <stdio.h>
#include <conio.h>
void main()
{
int i, sum = 0;
clrscr();
for (i = 1; i <= 16; i++) {
sum = sum + i * i;
}

printf("Sum of the series: %d\n", sum);


getch();
}

P a g e 16 | 16

You might also like