1.HELLO WORLD
#include<stdio.h>
main()
{
printf("Hello World\n");
}
2. PRINT 1 TO 100
#include<stdio.h>
main()
{
int i;
for(i=1;i<=100;i++)
{
printf("%d\n",i);
}
}
3.PRINT A TO Z
#include<stdio.h>
main()
{
int i;
for(i=65;i<=90;i++)
{
printf("%c\n",i);
}
}
4. Print odd or even
#include<stdio.h>
main()
{
int i;
printf("Enter a Number\n");
scanf("%d",&i);
if(i%2==0)
{
printf("The number %d is Even",i);
}
else
{
printf("The number %d is Odd",i);
}
printf("\n");
}
5.Print till N odd number
#include<stdio.h>
main()
{
int i,n;
printf("Enter a Number\n");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if(i%2==1)
printf("%d\n",i);
else
continue;
}
printf("\n");
}
6. Swap variable using third variable
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter a\n");
scanf("%d",&a);
printf("Enter b\n");
scanf("%d",&b);
printf("The values of a is %d
and b is %d before swaping\n",a,b);
c=a;
a=b;
b=c;
printf("The values of a is %d
and b is %d after swaping\n",a,b);
}
7.Swap numbers without using 3rd variable
#include<stdio.h>
main()
{
int a,b;
printf("Enter a\n");
scanf("%d",&a);
printf("Enter b\n");
scanf("%d",&b);
printf("The values of a is %d
and b is %d before swaping\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("The values of a is %d
and b is %d after swaping\n",a,b);
}
8.CHECK LEAP YEAR OR NOT
#include<stdio.h>
main()
{
int year;
printf("Enter the year you want to check\n");
scanf("%d",&year);
if(year%400==0)
{
printf("%d is leap year\n",year);
}
else if(year%100==0)
{
printf("%d is not a leap year\n",year);
}
else if(year%4==0)
{
printf("%d is a leap year\n",year);
}
else
{
printf("%d is not a leap year\n",year);
}
}
9. Convert day to year,weak and day
#include<stdio.h>
main()
{
int nodays,years,weeks,days;
printf("Enter the total days\n");
scanf("%d",&nodays);
years=nodays/365;
weeks=(nodays%365)/7;
days=(nodays%365)%7;
printf("%d = %d years,%d weeks,%d
days\n",nodays,years,weeks,days);
}
10.Biggest of three no.
#include<stdio.h>
main()
{
int num1,num2,num3;
printf("Enter a number 1\n");
scanf("%d",&num1);
printf("Enter a number 2\n");
scanf("%d",&num2);
printf("Enter a number 3\n");
scanf("%d",&num3);
if((num1>num2) && (num1>num3))
{
printf("%d is bigger\n",num1);
}
else if((num2>num1) && (num2>num3))
{
printf("%d is bigger\n",num2);
}
else
{
printf("%d is bigger\n",num3);
}
}
11. Multiplication by using addition
#include<stdio.h>
main()
{
int a,b,i,multiplication=0;
printf("Enter a,b\n");
scanf("%d%d",&a,&b);
if(b<0)
{
a=a+b;
b=a-b;
a=a-b;
}
if(a>=0)
{
for(i=1;i<=a;i++)
multiplication+=b;
}
if(a<0)
{
for(i=a;i<=-1;i++)
multiplication-=b;
}
printf("Multiplication=%d\n",multiplication);
}
12. Print company bonus on salary
#include<stdio.h>
#include<string.h>
main()
{
int i,j;
float salary,bonus;
char gender;
printf("Enter M for Male and F for Female\n");
scanf("%c",&gender);
printf("Enter Salary\n");
scanf("%f",&salary);
if(gender=='M' || gender=='m')
{
if(salary>10000)
bonus=(float)(salary*0.05);//0.05--5%
else
bonus=(float)(salary*0.07);
}
if(gender=='F' || gender=='f')
{
if(salary>10000)
bonus=(float)(salary*0.1);//0.1--10%
else
bonus=(float)(salary*0.12);
}
salary+=bonus;
printf("Bonus=%.2f\nSalary=%.2f\n",bonus,salary);
}
13. Calculate 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=%.2f\n",basicPay);
printf("Dearness Allowance=%.2f\n",dearnessAllowance);
printf("House Rent Allowance=%.2f\n",houseRentAllowance);
printf("ProvidentFund=%.2f\n",providentFund);
printf("Gross Salary=%.2f\n",grossSalary);
}
Comments