Basic of C programming- Print 1-100, leap year,calculate gross salary etc

1.Write a C program to print 1 to 100 numbers

#include<stdio.h>
main()
{
 int i;
 for(i=1;i<=100;i++)
{
 printf(“%dn”,i);

}

}

2. Write a C program to print whether given number is odd or even

#include<stdio.h>
main()
{
 int i;
 printf(“Enter a Numbern”);
 scanf(“%d”,&i);
 if(i%2==0)
{
 printf(“The number %d is Even”,i);

}
 else
{
 printf(“The number %d is Odd”,i);

}
 printf(“n”);

}

3. Write a C program to find the given year is leap year or not

#include<stdio.h>
main()
{
 int year;
 printf(“Enter the year you want to checkn”);
 scanf(“%d”,&year);
 if(year%400==0)
{
 printf(“%d is leap yearn”,year);

}
 else if(year%100==0)
{
 printf(“%d is not a leap yearn”,year);

}
 else if(year%4==0)
{
 printf(“%d is a leap yearn”,year);

}
 else
{
 printf(“%d is not a leap yearn”,year);

}

}

4.Write a C program to calculate the gross salary from given basic pay

#include<stdio.h>
main()
{
 float basicPay,dearnessAllowance,houseRentAllowance,grossSalary,providentFund;
 printf(“Enter Basic Pay n”);
 scanf(“%f”,&basicPay);
 houseRentAllowance=0.2*basicPay;
 dearnessAllowance=0.4*basicPay;
 providentFund=0.12*basicPay;
 grossSalary=basicPay+dearnessAllowance+houseRentAllowance+providentFund;
 printf(“Basic Pay=%.2fn”,basicPay);
 printf(“Dearness Allowance=%.2fn”,dearnessAllowance);
 printf(“House Rent Allowance=%.2fn”,houseRentAllowance);
 printf(“ProvidentFund=%.2fn”,providentFund);
 printf(“Gross Salary=%.2fn”,grossSalary);

}

5.Write a C program to covert given days to years,week and days 

#include<stdio.h>
main()
{
 int nodays,years,weeks,days;
 printf(“Enter the total daysn”);
 scanf(“%d”,&nodays);
 years=nodays/365;
 weeks=(nodays%365)/7;
 days=(nodays%365)%7;
 printf(“%d = %d years,%d weeks,%d
daysn”,nodays,years,weeks,days);

}

Leave a Comment

error: Content is protected !!