Create your first program in the C programming language.  

This tutorial will help you create your first program in the C programming language.  

Here is what you will need

  • Computer
  • Dev++

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

1. You need to download a compiler and install it in your pc you can download DEV -C++ {https://filehippo.com/download_dev-c/} this will work best.

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

3. Install Dev/C++ and launch from your computer and press Ctrl +N to open blank page as show below. Copy any code below into the text area: Highlight the code and press Ctrl +C to copy , then click at text area inside Devc++ and press Ctrl + V to paste.

Step 4: Save and Compile Code

Click at the file and select save, a new window will popup, then give your file a name with .C extension and click save. For example hello.c, Egerton.c

Compile your code by going to Execute > Compile.  This will check through the code to make sure that it is a valid C file.

You have now completed your first program.  But don’t stop here there is still much to learn about this great programming language, including arrays, loops, and pointers.  There are many great resources available on the internet .  Here are a few good reference books for that you can check out if you want to continue learning about C

To get started request basic C programming book below and will be sent to your inbox please check your spam folder.


1. C program to find the biggest of three numbers.

C program to print hello

#include
main() {
printf(“HELLO WORLD”);
}

C program to find the biggest of three numbers. 


AUTOR: ORENGO DICKSON

#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”);         
}

Note: // is treated as comment, This will describe the general idea of what is happening in the code following.


2. 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;        
}

Note: // is treated as comment, This will describe the general idea of what is happening in the code following.Output


3. NESTED When program requires more than one test    

/* AUTOR: ORENGO 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;          
printf(“Please Enter 3 number”);     
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”);     
}     
}             
}

Note: // is treated as comment, This will describe the general idea of what is happening in the code following.


4. Program to find sum of two numbers output

The line with // is comment

/* 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);
}

Output


5.PROGRAM FOR FINDINNG AREA OF RECTANGLE
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
#include <stdio.h> 

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;
}



6. 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




#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;
}

Note: // is treated as comment, This will describe the general idea of what is happening in the code following.


7. C program for Arithmetic_Operators {Addition, multipulication, substruction and division}

#include       
void main()    
{     
int a;
int b;
int c;  
printf(“Please Enter 2 number\n”);     
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 Student grade using switch statement

/* AUTOR: ORENGO DICKSON */

#include       
void main( )    
{     
char grade;    
printf(“ENTER YOUR GRADE\n”);    
scanf(“%char”,&grade);          
if (grade == ‘A’)     
{     
printf(“Excellent!”);     
}     
else if (grade == ‘B’)     
{     
printf(“Well done”);     
}     
else if (grade == ‘C’)     
{     
printf(“GOOD”);
}     
else if (grade == ‘D’)     
{     
printf(“You passed”);     
}     
else if (grade == ‘F’)     
{     
printf(“Better try again”);     
}     
else     
{     
printf(“WROG INPUT”);     
}     
}

9. C program for Student grade using switch

#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
}


Output

10. c programmig for temperature conversion from celcius to fahreheit

/* c programmig for temperature conversion from celcius to fahreheit AUTOR: ORENGO DICKSON */

#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” ,fahrenheit);
return 0; }

Did you make this project? Comment below

3 Replies to “Create your first program in the C programming language.  ”

  1. Its really a cool and helpful piece of info. I¦m happy that you simply shared this helpful information with us. Please stay us informed like this. Thanks for sharing.

Leave a Reply

Your email address will not be published. Required fields are marked *