## C programming examples INTRODUCTION

C programming is completely free and readily available on all platforms and easy to understand.

Follow the steps below for you to run C on your computer.

2. If you want a quick start, you can also run C program online with your phone or pc. online compiler

This article contains examples on basic concepts of C programming like: switch statement nested, functions, pointers, structures etc.

Request for more examples

1. programmig for temperature conversion from celcius to fahreheit

```/* c programmig for temperature conversion from celcius to fahreheit
AUTOR: ORENGO DICKSON
PHONE: 0702262007
*/
#include
int main()
{
float celsius, fahrenheit;
printf("ENTER TEMPERATURE IN CELSIUS\n");
scanf("%f" , &celsius);
fahrenheit=(1.8*celsius) + 32; //formular for conversion
printf("THE TEMPERATURE IN FAHREHEIT IS %f\n\n\n\n\n\n\n" , fahrenheit);
return 0;

}```

2. C program to find the biggest of three numbers

```/* C program to find the biggest of three numbers.
AUTOR: ORENGO DICKSON
PHONE: 0702262007

*/

#include

void main()
{
int x, y, z;

printf("Enter the first number\n");
scanf("%d" , &x);
printf("Enter the second number\n");
scanf("%d" , &y);
printf("Enter the 3rd number\n");
scanf("%d" , &z);

printf("x = %d\ty = %d\tz = %d\n", x, y, z);
if (x > y)
{
if (x > z)
{
printf("The greatest is X \n");
}
else
{
printf("The greatest is Z \n");
}
}
else if (y > z)
printf("The greatest is Y \n");
else
printf("The greatest is Z \n");

}
```

3. Program To Accept Student Roll No, Marks in 3 Subjects and Calculate Total, Average and Print it

```/*Program To Accept Student Roll No, Marks in 3 Subjects and Calculate Total, Average and Print it.
Autor: ORENGO DICKSON

*/

#include
main()
{
int r,x,y,z, tot, avg;   //The integer should be six , i.e rollno,three subject, total and average.
printf ("ENTER  STUDENT RNO\n  "); //The user is prompted to enter the roll no.     \n for newline
scanf ("%d",&r);   //scanf is to accept roll no from the keyboard    %d for decimal conversion
printf("ENTER FIRST MARKS \n");  //The user is prompted to enter the first marks., \n for newline
scanf("%d",&x);    //scanf is accept first marks from the keyboard     %d for decimal conversion   &y for number to be entered.
printf("ENTER SECOND  MARKS\n");    //The user is prompted to enter the second marks.
scanf("%d",&y);            //scanf is accept second marks from the keyboard
printf("ENTER THIRD  MARKS\n");   //The user is prompted to enter the second marks.
scanf("%d",&z);        //scanf is accept third marks from the keyboard
tot=x+y+z;     // total formular
avg=tot/3;      //avearge formular
printf("\n\n\t\t EGERTON UNIVERSITY  \n\n");
printf("STUDENT RNO %d \n",r); // \t is for spacing or tab
printf("\t FIRST   MARKS %d ",x);  //marks display
printf("\t SECOND  MARKS %d ",y);  //marks display
printf("\t THIRD  MARKS  %d ",z);   //marks display
printf("\t AVERAGE MARKS %d", avg);//marks display
}```

4. If-else statement

```   /* If-else statement
Autor DICKSON ORENGO

Syntax
if(expression)
{
//Statements
}
else
{
//Statements
}

*/

#include

main()
{
int num;
printf("enter the number\n");
scanf("%d",&num);
if(num%2==0)
{
printf("%d number in even\n",num);

}
else
printf("%d number in odd\n",num);

return 0;

}
```

5. NESTED STATEMENT

``` /*  AUTOR: OREGO DICKSON NESTED When program requires more than one test     if( expression )
{       if( expression1 )
{      statement-block1;      }      else       {      statement-block 2;      }
}     else     {      statement-block 3;     } */
#include
void main( )
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("a is greatest");
}
else
{
printf("c is greatest");
}
}
else
{
if(b>c)
{
printf("b is greatest");
}
else
{
printf("c is greatest");
}
}
}  ```

6. SWITCH STATEMENT

```/* AUTOR: ORENGO DICKSON */
#include

void main( )
{

{
printf("Excellent!");
}
{
printf("Well done");
}
{
printf("GOOD");
}
{
printf("You passed");
}
{
printf("Better try again");
}
else
{
printf("WROG INPUT");
}
}```

7. Operator, c programming arithmetic

```#include

void main()
{
int a;
int b;
int c;
scanf("%d%d",&a,&b);
c = a+b  ;
printf("Total (a+b) = %d \n",c);

c = a-b;
printf("Sub (a-b )= %d \n",c);

c = a*b;
printf("Mul (a*b) = %d \n",c);

c=a/b;
printf("Div (a/b) = %d \n",c);

c=a%b;
printf("Remainder (a Mod b) = %d \n",c);

}```

8. C PROGRAM FOR FINDINNG AREA OF RECTANGLE

```/*      Project 2
Instructions
1.	Declare compile and execute the program using c, giving the output
2.	Explain the program process from source to output ie declaration and assigment
3.	Submit handwritten and email zipped copy of the code
*/
//PROGRAM FOR FINDINNG AREA OF RECTANGLE

//Autor :Dickson Orengo

#include

int main() {
const int  LENGTH = 10;
const int  WIDTH = 5;
const char NEWLINE = '\n';
int area;

area = LENGTH * WIDTH;
printf("value of area : %d", area);
printf("%c", NEWLINE);

return 0;
}

```

9. ARITHMETIC OPERATOR FOR C PROGRAMMING

```// ARITHMETIC OPERATOR

/*1.	Declare compile and execute the program using c, giving the output
2.	Explain the  program process from source to output, ie declaration assignment
3.	Submit handwritten and email zipped copy of the code

Autor :Dickson Orengo
*/

#include

// Variable declaration:
extern int a, b;
extern int c;
extern float f;

int main ()

{

/* variable definition: */
int a, b;
int c;
float f;

/* actual initialization */
a = 10;
b = 20;

c = a + b;
printf("value of c : %d \n", c);

f = 70.0/3.0;
printf("value of f : %f \n", f);

return 0;
}
```

11. C Program To Read Two Numbers And Print The Sum Of Given Two Numbers

```/* Program To Read Two Numbers And Print The Sum Of Given Two Numbers.
Autor: ORENGO DICKSON

*/

#  include
main()
{
int x,y, sum;      //the three integers are two numbers and the result which is the sum
printf ("ENTER VALUE FOR X\n  ");   //This will be printed out , to prompt user what to do. \n is for new line
scanf ("%d",&x);                  // scanf is to accept input from the keyboard, %d is for decimal conversion &x is for number to be entered
printf("ENTER VALUE FOR Y\n");  //This will be printed out , to prompt user to enter the value of Y. \n is for new line
scanf("%d",&y);   // scanf is to accept input from the keyboard, %d is for decimal conversion &x is for number to be entered
sum=x+y;     //This is the result calculation.
printf("SUM OF THE TWO NUMBER ARE %d", sum);
}```

This site uses Akismet to reduce spam. Learn how your comment data is processed.