Sum of two numbers
/* Sum of two Variable */
#include<stdio.h>
int main()
{
int var2;
int var1;
int var3;
printf("Type your frist value to add : ");
scanf("%i",&var1);
printf("Type your second value to add : ");
scanf("%i",&var2);
var3 =var2+var1;
printf("Total of your value = %i",var3);
return 0;
}
Calculate Simple Interest
/* Calculate Simple interest */
#include<stdio.h>
int main()
{
float p;
float ir,t;
float in;
printf("Type your principle amount : ");
scanf("%f",&p);
printf("\n Type your rate of intrest : ");
scanf("%f",&ir);
printf("\n Type time (in year) : ");
scanf("%f",&t);
in=p*ir*t/100;
printf("\n You will get intrest : %.2f",in);
return 0;
}
#include<stdio.h>
int main()
{
float p;
float ir,t;
float in;
printf("Type your principle amount : ");
scanf("%f",&p);
printf("\n Type your rate of intrest : ");
scanf("%f",&ir);
printf("\n Type time (in year) : ");
scanf("%f",&t);
in=p*ir*t/100;
printf("\n You will get intrest : %.2f",in);
return 0;
}
Convert Km to Meter, Centimeter or Millimeter
/* Convert Km to Meter, Centimeter or Millimeter */
#include<stdio.h>
int main()
{
float km;
char v;
float ans;
printf("K.M. : ");
scanf("%f",&km);
printf("KM will be changed in (M,s,m) : ");
fflush(stdin);
scanf("%c",&v);
if(v=='M')
ans=km*1000;
if(v=='s')
ans=km*100000;
if(v=='m')
ans=km*1000000;
printf("Answer : %.2f",ans);
return 0;
}
#include<stdio.h>
int main()
{
float km;
char v;
float ans;
printf("K.M. : ");
scanf("%f",&km);
printf("KM will be changed in (M,s,m) : ");
fflush(stdin);
scanf("%c",&v);
if(v=='M')
ans=km*1000;
if(v=='s')
ans=km*100000;
if(v=='m')
ans=km*1000000;
printf("Answer : %.2f",ans);
return 0;
}
Swap values of two Variables
/* Swap the values of two Variables using three variables */
#include<stdio.h>
int main()
{
int a;
int b;
int c;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
c=a;
a=b;
b=c;
printf("A : %i",a);
printf("\nb : %i",b);
return 0;
}
#include<stdio.h>
int main()
{
int a;
int b;
int c;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
c=a;
a=b;
b=c;
printf("A : %i",a);
printf("\nb : %i",b);
return 0;
}
Swap two values without using third variable
/* Swap the values of two variables without using third variable */
#include<stdio.h>
int main()
{
int a;
int b;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
a = a + b;
b = a - b;
a = a - b ;
printf("A : %i",a);
printf("\nB : %i",b);
return 0;
}
#include<stdio.h>
int main()
{
int a;
int b;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
a = a + b;
b = a - b;
a = a - b ;
printf("A : %i",a);
printf("\nB : %i",b);
return 0;
}
Swap values of two variables using XOR
/* Swap values of two variables using XOR */
#include<stdio.h>
int main()
{
int a;
int b;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
a ^= b;
b ^= a;
a ^= b;
printf("A : %i",a);
printf("\nB : %i",b);
return 0;
}
#include<stdio.h>
int main()
{
int a;
int b;
printf("Type value of A : ");
scanf("%i",&a);
printf("\nType value of b : ");
scanf("%i",&b);
a ^= b;
b ^= a;
a ^= b;
printf("A : %i",a);
printf("\nB : %i",b);
return 0;
}
Convert meter to feet
/* convert meter to feet */
#include<stdio.h>
int main()
{
float m,f;
printf("Type meter : ");
scanf("%f",&m);
f = 3.2808399 * m;
printf("feets: %f",f);
return 0;
}
#include<stdio.h>
int main()
{
float m,f;
printf("Type meter : ");
scanf("%f",&m);
f = 3.2808399 * m;
printf("feets: %f",f);
return 0;
}
Convert feet to meter
/* convert feet to meter */
#include<stdio.h>
int main()
{
float m,f;
printf("Type feet : ");
scanf("%f",&f);
m = f / 3.2808399;
printf("meter: %f",m);
return 0;
}
#include<stdio.h>
int main()
{
float m,f;
printf("Type feet : ");
scanf("%f",&f);
m = f / 3.2808399;
printf("meter: %f",m);
return 0;
}
Convert celcius to farenheit
/* convert celcius to farenheit */
#include<stdio.h>
int main()
{
float c,f;
printf("Type celcius: ");
scanf("%f",&c);
f = c * 9/5 + 32;
printf("farenheit: %f",f);
return 0;
}
#include<stdio.h>
int main()
{
float c,f;
printf("Type celcius: ");
scanf("%f",&c);
f = c * 9/5 + 32;
printf("farenheit: %f",f);
return 0;
}
Just Give Your Feedback ConversionConversion EmoticonEmoticon