Thursday, January 6, 2011

Program to convert Celsius to Farenheit

/*  Name: Program to convert Celsius to Farenheit

Author: Parveen Malik

Date: 06/01/11 15:36*/


#include<stdio.h>

#include<conio.h>

void main()

{

int lower,upper,steps;

int celsius;

float farn;

lower=0;

upper=100;      //you can chanage these parameters like lower,upper and steps

steps=5;

celsius=lower;

printf("Celsius\t\tFarenheit\n\n");         //   /t tab

while(celsius<=upper)

{

farn=((9.0/5.0)*celsius)+32.0;       // formula to Celsius to Farenheit

printf("%d\t==>\t%.2f\n",celsius,farn);

celsius+=steps;

}

getch();

}



[caption id="attachment_156" align="aligncenter" width="655" caption="OUTPUT"]Program to convert Celsius to Farenheit[/caption]


Wednesday, January 5, 2011

Program to find out roots of a quadratic equation

/*  Name: Program to find out roots of a quadratic equation

Author: Parveen Malik

Date: 05/01/11 21:00*/


#include<stdio.h>

#include<conio.h>

#include<math.h>
void main()

{

int a,b,c;

float disc; // Discriminant

float root1,root2;

printf("Enter the value of a,b and c respectively\n");

printf("a = ");

scanf("%d",&a);

printf("b = ");

scanf("%d",&b);

printf("c = ");

scanf("%d",&c);

disc=b*b-4*a*c;

root1=-b+sqrt(disc)/2*a;

root2=-b-sqrt(disc)/2*a;

if(disc==0)

{

printf("Roots are real and equal\n");

printf("First Root :%.2f = Second Root: %.2f\n",root1,root2);

}

else if(disc<0)

{

printf("Roots are imaginary");

printf("First root = %.2f\n",root1);

printf("Second root = %.2f\n",root2);

}

else

{

printf("Roots are real and distinct\n");

printf("First root = %.2f\n",root1);

printf("Second root = %.2f\n",root2);

}

getch();

}

[caption id="attachment_82" align="aligncenter" width="655" caption="OUTPUT"]Program to find out roots of a quadratic equation[/caption]

Tuesday, January 4, 2011

Program to convert Farenheit to Celsius


/*Name: Program to convert Farenheit to Celsius

Author: Parveen Malik

Date: 05/01/11 10:37

*/


#include<stdio.h>

#include<conio.h>


void main()

{

int lower,upper,steps;

int farn;

float celcius;


lower=0;

upper=100; //you can chanage these parameters like lower,upper and steps

steps=5;


farn=lower;

printf("Fareneit\tCelcius\n");                 //   \t is used to give tab

while(farn<=upper)

{

celcius=5.0/9.0*(farn-32.0);                   // formula to convert Farenheit to Celcius

printf("%d\t\t%.2f\n",farn,celcius);

farn+=steps;

}

getch();

}




 




[caption id="attachment_161" align="aligncenter" width="655" caption="OUTPUT"]Program to convert Farenheit to Celsius[/caption]

 

 

Why we bother to learn C ?

C seems so popular because it is simple, reliable, easy to use and easy to learn ( as compare to learn Java directly) general purpose language. There are several reason behind choosing C as first programming language.

  • Before migrating to C++, C# or Java it is necessary to understand the pattern of any programming language thoroughly. By comprehending basic element of any programming language like structure of a program, control statements(if, else, else if, switch statements), expressions, looping statements( while, do while, for).

  • Dennis Ritchie developed C for developing operating system(UNIX) for PDP-11 machine. Kernel was completely written in C. Major parts of popular Operating Systems like Linux, Unix, Mac and Windows are still written in C.

  • It is a machine independent language. It means a program written for any machine can also be executed on another machine and programs written in C can be executed almost on every Operating System.

  • Electronics gadgets like Cell Phones, palmtop, i phones, i-pods, Notebooks etc.) have become rage of today. It seems that life without these gadgets will become dull and boring. Youngsters can not imagine their life without these gadgets. What makes these devices intelligent and smart?.  Off-course because of OS and programs or apps embedded in these devices. Program written in C run fast and efficiently that's why C is always preferred to write programs for these devices.

  • Gaming industry in emerging rapidly. 2D or 3D games requires a lot of memory and processing power. If you had played any game you might  be notice that Player(you) navigates some objects like bikes,cars, weapons etc. And speed plays an important role in gaming. As earlier mentioned programs written in run fast Gaming Frameworks have developed using C. Therefore  developers and programmers./

Monday, January 3, 2011

Program to calculate simple interest.

/*
Name: Program to find out Simple interest
Author: Parveen Malik
Date: 03/01/11 18:45
*/

#include<stdio.h>
#include<conio.h>


void main()
{
float rate,time,prin; // declaring rate, time and principle
float si; // simple interest

printf("Enter the value of\n\nPrinciple : "); // taking user
scanf("%f",&prin); //principle
printf("Rate : ");
scanf("%f",&rate);
printf("Time : ");
scanf("%f",&time);


si=prin*rate*time/100; //formula of finding simple interest
printf("\nSimple Interest : %.2f",si); // printing simple interest to the console

getch();
}




[caption id="attachment_55" align="aligncenter" width="800" caption="OUTPUT:"]program to find out simple interest[/caption]



Program to calculate area of a circle

/*
Name: Program to calculate area of a circle
Author: Parveen Malik
Date: 03/01/11 19:46
*/

#include<stdio.h>
#include<stdio.h>
#define PI 3.141 // to define value of pi


void main()
{
int radius;
float area;

printf("Enter the radius of the Circle : ");
scanf("%d",&radius);

area=PI*radius*radius; // formula to find the area of a circle
printf("\nArea of the Circle is : %.2f",area);

getch();
}
OUTPUT:



[caption id="attachment_12" align="aligncenter" width="656" caption="OUTPUT"]Program to calculate area of a circle[/caption]



Sunday, January 2, 2011

Program to find out sum of any two integers.

/*
Name:  Program to find out sum of any two integers.
Author: Parveen Malik
Date: 02/01/11 16:05
*/

#include<stdio.h>
#include<conio.h>   // preprocessor section


void main()
{
int n1,n2,sum; //declare integers

printf("Enter any two integers \n");
scanf("%d%d",&n1,&n2); // for the user input

sum=n1+n2;

printf("\n\n%d + %d = %d",n1,n2,sum); // to print the sum


getch();
}
 

[caption id="attachment_11" align="aligncenter" width="655" caption="OUTPUT"]Program to find out sum of any two integers.[/caption]



First Program "hello world"

Here is the first program from which you can start your programming as i did. C is a general purpose programming language developed by Dennis Ritchie at Bell Laboratories(1972).
C is the one of the most popular language of all the time. C is  influenced by B, BCPL, CPL, ALGOL, Assembly, FORTRAN, PL/I and it has influenced many languages like C++, C--, C#, Objective C, BitC, D, Java, JavaScript, PHP, Perl, Pike , LPC and Python etc.
Look at the program below and try to understand it.



/*  Name: hello world
Author: Parveen Malik,,
Date: 02/01/11 15:11      // comment section
*/


#include<stdio.h> // header section
#include<conio.h>


void main() //program starts from here
{
printf("hello world"); // Prints the "hello world" on console screen

getch();

} //exit





[caption id="attachment_8" align="aligncenter" width="662" caption="OUTPUT"]First Program "hello world"[/caption]