Introduction to Computer And Programming,I/O Functions,Control Structures in C,Arrays,Pointers,Functions, Strings,Structure and Unions, Preprocessor and Macros, Dynamic Memory Allocations,File Management.
Monday, 20 March 2017
C program the division operation
Program :
#include
#include
int main()
{
int x,y;
int result1,result2;
printf("\n Enter the dividend : ");
scanf("%d",&x);
printf("\n Enter the divisor: ");
scanf("%d",&y);
result1 = x/y;
result2 = x%y;
printf("\n The Quotient is: %d ",result1);
printf("\n The Remainder is: %d ",result2);
getch();
return 0;
}
Output ;
#include
#include
int main()
{
int x,y;
int result1,result2;
printf("\n Enter the dividend : ");
scanf("%d",&x);
printf("\n Enter the divisor: ");
scanf("%d",&y);
result1 = x/y;
result2 = x%y;
printf("\n The Quotient is: %d ",result1);
printf("\n The Remainder is: %d ",result2);
getch();
return 0;
}
Output ;
Calculate Simple interest
/* Calculate Simple interest */
#include
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
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;
}
Output:
Swap the values of two Variables using three variables
/* Swap the values of two Variables using three variables */
#include
int main()
{
int p;
int q;
int r;
clrscr();
printf("Enter your value of P : ");
scanf("%i",&p);
printf("\n Enter your value of Q : ");
scanf("%i",&q);
r=p;
p=q;
q=r;
printf("P : %i",p);
printf("\nQ : %i",q);
getch();
return 0;
}
#include
int main()
{
int p;
int q;
int r;
clrscr();
printf("Enter your value of P : ");
scanf("%i",&p);
printf("\n Enter your value of Q : ");
scanf("%i",&q);
r=p;
p=q;
q=r;
printf("P : %i",p);
printf("\nQ : %i",q);
getch();
return 0;
}
Output:
Simple if statement
Syantax:
if(condition)
{
statement1;
statement2;
.
.
.
statement n;
}
#include
void main()
{
int age;
printf(" >>> c program to implement simple if<<< \n\n");
printf("\n Enter the age of the person: ");
scanf("%d",&age);
if(age>=18)
{
printf("\n Eligible for Licence \n");
}
printf("\n program ends \n\n");
}
Output:
if(condition)
{
statement1;
statement2;
.
.
.
statement n;
}
Program :
#include
void main()
{
int age;
printf(" >>> c program to implement simple if<<< \n\n");
printf("\n Enter the age of the person: ");
scanf("%d",&age);
if(age>=18)
{
printf("\n Eligible for Licence \n");
}
printf("\n program ends \n\n");
}
C program to sort an array using function
Program :
#include
#include
#define MAX 100 // maximum no of elements of array
int sortArray(int);
int array[MAX];
int main()
{
int i,size;
printf("\n>>>> PROGRAM TO SORT ARRAY USING FUNCTION <<<<\n\n");
printf("\n Enter the size of array: ");
scanf("%d",&size);
printf("\n Enter the %d elements of array: \n",size);
for(i=0;i
{
printf("\n array[%d]=",i);
scanf("%d", &array[i]);
}
sortArray(size); //calling sortArray() function
printf("\n The Sorted elements of array are:");
for(i=0;i
{
printf(" %d",array[i]);
}
getch();
return 0;
}
sortArray(n) // function for sorting array elements
{
int temp=0,i,j; // temp var is temporary variable used for swapping
for(i=0;i
{
for(j=i+1;j
{
if(array[i]>array[j])
{
temp=array[i]; //swapping for the array to be sorted
array[i]= array[j];
array[j]=temp;
}
}
}
}
Output :
#include
#include
#define MAX 100 // maximum no of elements of array
int sortArray(int);
int array[MAX];
int main()
{
int i,size;
printf("\n>>>> PROGRAM TO SORT ARRAY USING FUNCTION <<<<\n\n");
printf("\n Enter the size of array: ");
scanf("%d",&size);
printf("\n Enter the %d elements of array: \n",size);
for(i=0;i
{
printf("\n array[%d]=",i);
scanf("%d", &array[i]);
}
sortArray(size); //calling sortArray() function
printf("\n The Sorted elements of array are:");
for(i=0;i
{
printf(" %d",array[i]);
}
getch();
return 0;
}
sortArray(n) // function for sorting array elements
{
int temp=0,i,j; // temp var is temporary variable used for swapping
for(i=0;i
{
for(j=i+1;j
{
if(array[i]>array[j])
{
temp=array[i]; //swapping for the array to be sorted
array[i]= array[j];
array[j]=temp;
}
}
}
}
Subscribe to:
Posts (Atom)




