1.
//checking leap year or not
#include <stdio.h>
int main()
int year;
printf("enter year\n");
scanf("%d",&year);
if ((year%4==0&&year%100!=0)||year%400==0){
printf("it is a leap year \n");
else{
printf("it is not a leap year ");
return 0;
Output :
2.
//comparing the person based on their heights
#include<stdio.h>
int main()
int height;
printf("enter the height \n");
scanf("%d",&height);
if (height < 150){
printf("the person is dwarf \n");
}
else
if(height > 150 && height < 164){
printf("the person is average \n");
else
if(height >= 165){
printf("the person is tall \n");
return 0;
Output :
3.
#include<stdio.h>
int main()
int m;
printf("enter m \n");
scanf("%d",&m);
if(m>0)
printf("enter n=1 \n");
else
if(m=0)
printf("enter n=0 \n");
else
if(m<0)
{
printf("enter n=1 \n");
return 0;
Output:
4.
// finding the quadrants
#include<stdio.h>
int main()
int x,y;
printf("enter x \n");
scanf("%d",&x);
printf("enter y \n");
scanf("%d",&y);
if(x>0 && y>0){
printf("enter q1 \n");
else
if(x<0 && y>0){
printf("enter q2 \n");
else
if(x<0 && y<0){
printf("enter q3 \n");
else
if(x>0 && y<0){
printf("enter q4 \n");
return 0;
Output:
5.
GNU nano 5.6.1 ps2_5.c Modified // eligibility for the admissions
#include<stdio.h>
int main()
int m,p,c;
printf("enter m \n");
scanf("%d",&m);
printf("enter p \n");
scanf("%d",&p);
printf("enter c \n");
scanf("%d",&c);
if(m>=65 && p>=55 && c>=50){
printf("enter qualified \n");
else
if((m+p+c)>=190||(m+p)>=140){
printf("enter qualified \n");
if((m+p+c)<190||(m+p)<140);{
printf("enter not qualified \n");
}
return 0;
Output :
6.
scanf("%d",&che);
printf("enter cpa \n");
scanf("%d",&cpa);
total=(phy+che+cpa);
printf("%d=total",total);
per=(total)/3;
printf("%f=per",per);
if(per>=80.0)
printf("enter first division");
else
if(80.0<per<60.0)
printf("enter second division");
else
if(60.0<per<50.0)
printf("enter third division");
else
{
printf("enter failed");
return 0;
Output :
7.
if(unit<=199)
printf("enter rate=1.20 \n");
if(200<unit<400)
printf("enter rate=1.50 \n");
if(400<unit<600)
printf("enter rate=1.80 \n");
if(unit>600)
printf("enter rate=2.00 \n");
}
amount=rate*unit;
printf("amount=%d",amount);
if(amount>400.0)
surg=amount*0.15;
printf("surg=%d",surg);
total=amount+surg;
printf("total=%d",total);
if(total<100.0)
total=100.0;
return 0;
Output :
8.
#include <stdio.h>
int main()
int a,b,c,d;
printf("enter the four numbers \n");
scanf("%d%d%d%d",&a,&b,&c,&d);
if(a<b && a<c && a<d){
printf("enter a \n");
else if(b<a && b<c && b<d){
printf("enter b \n");
}
else if(c<a && c<b && c<d){
printf("enter c \n");
return 0;
Output :
enter the four numbers
enter a
9.
else
if(c>a && c>b && c>d)
printf("enter c \n");
else
if(d>a && d>b && d>c)
printf("ennter d\n");
if (a == b || a == c || a == d){
printf("%d ", a);
if ((b == c || b ==d) && b != a){
printf("%d ", b);
}
if ((c == d) && c != a && c != b){
printf("%d ", c);
if ( d != a && d != b && d != c){
printf("%d ", d);
printf("\n");
return 0;
Output :
10 .
#include <stdio.h>
int main()
int a;
printf("enter value of a");
scanf("%d",&a);
if(a<=100){
printf("The absolute difference is %d", 100-a);
else{
printf("The absolute difference is %d", (a-100)> }
return 0;
Output :
11 .
#include <stdio.h>
int main()
int x,y;
printf("enter the value of x");
scanf("%d",&x);
printf("enter the value of y");
scanf("%d",&y);
if(((x>=20 && x<=30) || (y>=20 && y<=30)) && x>y )
printf("%d is the required number", x);
else if(((x>=20 && x<=30) || (y>=20 && y<=30)) && y>x )
printf("%d is the required number", y);
else{
printf("0");
return 0;
Output :
12 .
printf("Enter b:\n");
scanf("%d", &b);
printf("Enter c:\n");
scanf("%d", &c);
scanf("%d", &c);
if(10<=a<=20 && a!=13 && a!=17){
a=0;
else{
a=a;
if(10<=b<=20 && b!=13 && b!=17){
b=0;
else{
b=b;
if(10<=c<=20 && c!=13 && c!=17){
c=0;
else{
c=c;
sum=a+b+c;
printf("sum is %d", sum);
return 0;
13 .
#include <stdio.h>
int main()
int i=1;
while(i<=20)
printf("i=%d",i);
if(i%5==0)
printf("\n");
else
printf("\t");
i++;
return 0;
Output :
14 .
#include <stdio.h>
int main ()
int n=1,fact=1;
printf("n\tfact\n");
for(n=1;n<=5;n++)
fact*=n;
printf("%d\t%d\n",n,fact);
}
return 0;
Output :
15 .
#include <stdio.h>
int main ()
int i,j,num;
for(i=0;i<5;i++);
scanf("%d",&num);
for(j=1;j<=num;j++) {
printf("*");
printf("\n");
return 0;
Output :
16 .
printf("Enter quantity sold: ");
scanf("%d", &quantitySold);
switch (productNumber) {
case 1:
price = 2.98;
break;
case 2:
price = 4.50;
break;
case 3:
price = 9.98;
break;
case 4:
price = 4.49;
break;
case 5:
price = 6.87;
break;
default:
printf("Invalid product number. Please enter a > continue;
} totalAmount += price * quantitySold;
} printf("\nTotal retail value of all products sold: $%.2f\n">
return 0;
Output :
17 .
// pythagorean triplets
#include <stdio.h>
int main() {
int side1, side2, hypotenuse;
for (side1 = 1; side1 <= 500; side1++) {
for (side2 = side1; side2 <= 500; side2++) {
for (hypotenuse = side2; hypotenuse <= 500; hypoten>
if (side1 * side1 + side2 * side2 == hypotenuse> printf("(%d, %d, %d)\n", side1,
side2, hypo> }
return 0;
}
Output :
18 .
// sum cubes of even numbers
#include <stdio.h>
int main()
int n,i=2;
long long sum=0;
printf("enter the limit:");
scanf("%d",&n);
while(i<=n){
long long cube=(long long)i*i*i;
if(cube%10!=10) {
sum+=cube;
i+=2;
printf("sum of cubes=%d\n",sum);
return 0;
Output :
19 .
GNU nano 5.6.1 ps2_19.c Modified //
palindromes
#include <stdio.h>
int main() {
int num, originalNum, reversedNum = 0, remainder;
printf("Enter a number: ");
scanf("%d", &num);
originalNum = num;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
if (originalNum == reversedNum) {
printf("%d : palindrome\n", originalNum);
} else {
printf("%d : not a palindrome : %d\n", originalNum, reversedNum);
}
return 0;
Output :
20 .
// fibonacci number
#include <stdio.h>
int main()
int n,a=0,b=1,temp,i=1;
printf("n \n");
scanf("%d is n",&n);
while(i<=n){
printf("%d",a);
temp=a+b;
a=b;
b=temp;
i++;
printf("\n");
return 0;
Output :
21 .
// fibonacci with prime number
#include <stdio.h>
int main() {
int count = 0, n = 10;
long long a = 0, b = 1, next;
while(count < n) {
int isPrime = 1;
if(a < 2) isPrime = 0;
for(int i = 2; i*i <= a; i++) {
if(a % i == 0) {
isPrime = 0;
break;
printf("%lld", a);
if(isPrime) printf(" (prime)");
printf("\n");
next = a + b;
a = b;
b = next;
count++;
return 0;
Output :
22 .
// seperating different types of characters
#include <stdio.h>
#include <ctype.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if (isalpha(ch)) {
char lower = tolower(ch);
if (lower == 'a' || lower == 'e' || lower == 'i' || lower == 'o' || lower == 'u') {
printf("'%c' is a vowel.\n", ch);
} else {
printf("'%c' is a consonant.\n", ch);
else if (isdigit(ch)) {
printf("'%c' is a digit.\n", ch);
else {
printf("'%c' is a special character.\n", ch);
}
return 0;
Output :
23 .
// sum of the squares
#include <stdio.h>
int main() {
int n, digit, sum = 0;
scanf("%d", &n);
if(n <= 0) {
printf("Please enter a positive integer\n");
return 0;
do {
digit = n % 10;
sum += digit * digit;
n /= 10;
} while(n > 0);
printf("Sum of squares of digits = %d\n", sum);
return 0;
Output :
24 .
// sum of the prime numbers
#include <stdio.h>
int main() {
int limit, i = 2, j, isPrime, sum = 0;
scanf("%d", &limit);
do {
isPrime = 1;
for(j = 2; j * j <= i; j++) {
if(i % j == 0) {
isPrime = 0;
break;
if(isPrime) sum += i;
i++;
} while(i <= limit);
printf("Sum of prime numbers up to %d = %d\n", limit, sum);
return 0;
Output :
25.
// sum of odd numbers
#include <stdio.h>
int main() {
int n, i, sum = 0;
scanf("%d", &n);
for(i = 1; i <= n; i++) {
int odd = 2 * i - 1;
printf("%d ", odd);
sum += odd;
printf("\nSum = %d\n", sum);
return 0;
Output :
26 .
// calculating total amount of candy
#include <stdio.h>
int main()
int a,b,amount;
printf("enter number of candy bars sold: ");
scanf("%d",&a);
printf("enter the cost of each bar: ");
scanf("%d",&b);
amount=a*b;
printf("amount=%d",amount);
return 0;
Output :
27 .
GNU nano 5.6.1 ps2_27.c //calculating the milaze of a veichle
#include <stdio.h>
int main() {
double tank = 20.0;
double mpg_town = 21.5;
double mpg_highway = 26.8;
double distance_town, distance_highway;
distance_town = tank * mpg_town;
distance_highway = tank * mpg_highway;
printf("Distance in town: %.2f miles\n", distance_town);
printf("Distance on highway: %.2f miles\n", distance_highwa>
return 0;
Output :
28 .
//calculating the rise of ocean
#include <stdio.h>
int main() {
double rise_per_year_mm = 1.8;
int years = 100;
double total_rise_mm, total_rise_cm, total_rise_in;
total_rise_mm = rise_per_year_mm * years;
total_rise_cm = total_rise_mm * 0.1;
total_rise_in = total_rise_cm * 0.3937;
printf("Ocean rise in %d years:\n", years);
printf("Millimeters: %.2f mm\n", total_rise_mm);
printf("Centimeters: %.2f cm\n", total_rise_cm);
printf("Inches: %.2f in\n", total_rise_in);
return 0;
Output :
29 .
//calculating the amount of calories consumed from cookies
#include <stdio.h>
int main() {
int cookies_per_bag = 40;
int servings_per_bag = 10;
int calories_per_serving = 300;
int cookies_eaten;
double calories_per_cookie, total_calories;
calories_per_cookie = (double)(servings_per_bag * calories_per_serving) / cookies_per_bag;
printf("Enter the number of cookies you ate: ");
scanf("%d", &cookies_eaten);
total_calories = cookies_eaten * calories_per_cookie;
printf("You consumed %.2f calories.\n", total_calories);
return 0;
}
Output :
30 .
int number Of Payments;
float amount Paid Back,interest Paid;
printf("Enter loan amount: ");
scanf("%f", &loan Amount);
printf("Enter annual interest rate (in %%): ");
scanf("%f", &annual Rate);
printf("Enter number of payments: ");
scanf("%d", &number Of Payments);
monthly Rate = annual Rate / 12.0f / 100.0f;
monthly Payment = (loan Amount * monthly Rate * powf(1 + monthly Rate, number Of
Payments)) /
(powf(1 + monthly Rate, number Of Payments) - 1);
amount Paid Back = monthly Payment * number Of Payments;
interest Paid = amount Paid Back - loan Amount;
printf("\nLoan Amount: $%.2f\n", loan Amount);
printf("Monthly Interest Rate: %.2f%%\n", monthly Rate * 100);
printf("Number of Payments: %d\n", number Of Payments);
printf("Monthly Payment: $%.2f\n", monthly Payment);
printf("Amount Paid Back: $%.2f\n", amount Paid Back);
printf("Interest Paid: $%.2f\n", interest Paid);
return 0;
Output :