prowessapps.in List of Basic Programs

 C Program to add two numbers

#include<stdio.h >
int main( ) {
 int a, b,c;
 printf("Enter Values A and B: ");
 scanf("%d%d",&a,&b);
 c = a+b;
 printf("RESULT : %d\n",c);
 return 0;
}
OUTPUT :
Enter Values A and B :
12 13
RESULT : 25

 C Program to swap values of two no.s

#include< stdio.h >
int main( ) {
 int a, b, temp;
 printf("Enter Values A and B: ");
 scanf("%d%d",&a,&b);
 printf("BEFORE :");
 printf("A=%d B=%d\n",a,b);
 temp = a;
 a = b;
 b = temp;
 printf("AFTER :");
 printf("A=%d B=%d\n",a,b);
 return 0;
}
OUTPUT :
Enter Values for A and B :
12 13
BEFORE: A=12 B=13
AFTER : A=13 B=12

 C Program to swap values of two no.s without using third variable

#include<<stdio.h >
int main( ) {
 int a, b;
 printf("Enter Values for A and B: ");
 scanf("%d%d",&a,&b);
 printf("BEFORE :");
 printf("A=%d B=%d\n",a,b);
 a = a+b;
 b = a-b;
 a = a-b;
 printf("AFTER :");
 printf("A=%d B=%d\n",a,b);
 return 0;
}
OUTPUT :
Enter Values for A and B :
17 19
BEFORE: A=17 B=19
AFTER : A=19 B=17

 C Program to calculate the area of circle

#include< stdio.h >
int main( )
{
 float radius, area;
 const float pi = 3.14f;
 printf("Enter radius: ");
 scanf("%f",&radius);
 area = pi*radius*radius;
 printf("CIRCLE DETAILS:\n");
 printf("RADIUS:%f\n",radius);
 printf("AREA:%f\n",area);
 return 0;
}
OUTPUT :
Enter radius : 8.2
CIRCLE DETAILS:
RADIUS:8.2
AREA :211.1336

 C Program to find cube of a number

#include<stdio.h >
int main( ) {
 int n, cb;
 printf("Enter Value for N : ");
 scanf("%d",&n);
 cb = n*n*n;
 printf("CUBE IS : %d\n",cb);
 return 0;
}
OUTPUT :
Enter Value for N : 3
CUBE IS : 27

 C Program to find square root of a number.

#include<stdio.h >
#include<math.h >
int main( ) {
 float n, sq;
 printf("Enter Value for N : ");
 scanf("%f",&n);
 sq = sqrt(n);
 printf("SQUARE ROOT IS : %f\n",sq);
 return 0;
}
OUTPUT :
Enter Value for N : 16
SQUARE ROOT IS : 4.0


 C Program to find x to the power y (xy).

#include< stdio.h >
#include< math.h >
int main( ) {
 int x,y,res;
 printf("Enter Values for X & Y : ");
 scanf("%d%d",&x,&y);
 res = pow(x,y);
 printf("X^Y IS : %d\n",res);
 return 0;
}
OUTPUT :
Enter Values for X & Y :
4 3
X^Y IS : 64

 C Program to convert temp from Fahrenheit to Celsius.

#include<stdio.h >
int main( ) {
 float c,f;
 printf("Enter Temp in (F) : ");
 scanf("%f",&f);
 c = (5.0/9.0)*(f-32);
 printf("Temp in Celsius : %f\n",c);
 return 0;
}
OUTPUT :
Enter Temp in (F): 42
Temp in Celsius: 5.55556

 C Program to input time in millisecond s and show in minutes and seconds.

#include< stdio.h >
int main( ) {
 int tms, tm, ts;
 printf("Enter Time in millis : ");
 scanf("%d",&tms);
 ts = tms/1000;
 tm = ts/60;
 ts = ts%60;
 printf("TIME(mm:ss) - %d:%d",tm,ts);
 return 0;
}
OUTPUT :
Enter Time in millis:863534
TIME(mm:ss) - 14:39

 C Program to find difference between two numbers, diff must be positive.

#include<stdio.h >
int main( ) {
 int a, b, diff;
 printf("Enter Values for A : ");
 scanf("%d",&a);
 printf("Enter Values for B : ");
 scanf("%d",&b);
 diff = (a>b) ? a-b : b-a;
 printf("DIFFERENCE IS : %d\n",diff);
 return 0;
}
OUTPUT :
Enter Values for A : 62
Enter Values for A : 95
DIFFERENCE IS : 33

 C Program to find greatest among two numbers using ternary operator.

#include<stdio.h >
int main( ) {
 int a, b;
 printf("Enter Values for A : ");
 scanf("%d",&a);
 printf("Enter Values for B : ");
 scanf("%d",&b);
 (a>b)? printf("A is Greatest\n")  :  printf("B is Greatest\n");
 return 0;
}
OUTPUT :
Enter Values for A : 62
Enter Values for B : 119
B is Greatest




CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017, prowessapps.in, All rights reserved