Posts

Showing posts from January, 2021

Make a Digital Clock in C languege

 C Program to design a digital clock In this program the clock will start with the time 00:00:00 and then it will work like a digital clock where it will show the time with hour, minutes and second. STEP 1:Initialize hour, minute, seconds with 0. STEP 2:Run an infinite loop. STEP 3:Increase second and check if it is equal to 60 then increase minute and reset second to 0. STEP 4:Increase minute and check if it is equal to 60 then increase hour and reset minute to 0. STEP 5:Increase hour and check if it is equal to 24 then reset hour to 0. Example #include <stdio.h> #include <time.h>//for sleep() function #include <unistd.h> #include <stdlib.h> int main() { int hour, minute, second; hour=minute=second=0; while(1) { //clear output screen system("clear"); // if "clear" doesn't work , use "CLS" in bricket //print time in HH : MM : SS format printf("%02d : %02d : %02d ",hour,minute,second); //clear output buffer in gcc fflus...

Draw a line, First graphics program in C

Program to Draw a line    #include<graphics.h> #include<stdio.h> #include<conio.h> void main(void) {     int gdriver = DETECT, gmode;     int x1 = 200, y1 = 200;     int x2 = 300, y2 = 300;     clrscr();          initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");     line(x1, y1, x2, y2);     getch();     closegraph(); } Code Explanation- The first step in any graphics program is to include graphics.h header file. The graphics.h header file provides access to a simple graphics library that makes it possible to draw lines, rectangles, ovals, arcs, polygons, images, and strings on a graphical window. The second step is initialize the graphics drivers on the computer using initgraph method of graphics.h library. void initgraph(int *graphicsDriver, int *graphicsMode, char *driverDirectoryPath); It initializes the graphics system by loading the passed graphics d...

Make program of Marksheet in C language

#include<conio.h> #include<stdio.h> #include<string.h> void main() {  /*variable declaration part */  int rl,s1,s2,s3,t;  float per;  char nm[25],div[10];  clrscr();  /*reading part */  printf("Enter the Roll No : ");  scanf("%d",&rl);  printf("Enter Name : ");  fflush(stdin);  gets(nm);  printf("Enter Three Subject Marks :\n");  scanf("%d%d%d",&s1,&s2,&s3);  /* processing part */  t=s1+s2+s3;  per=t/3.0;  if(per>=75)       strcpy(div,"Honour"); else if( per>=60)     strcpy(div,"First"); else if( per>=48)     strcpy(div,"Second"); else if (per>=36)         strcpy(div,"Pass"); else         strcpy(div,"Fail");  /* display part */  printf("\t\tUniversity of Rajasthan\n");  printf("\n\n");  printf("Roll No: %d \t Name : %s\n",rl,nm);  printf("-------------...

What is printf() and scanf() in C language

printf() and scanf() The printf() and scanf() is a predefined functions. these are used for input and output in C language. Both functions are inbuilt library functions. Defined in stdio.h (header file). printf() function - The printf() function is used for output or display. It prints the given statement to the screen. scanf() function - The scanf() function is used for input. It reads the input data from the user.

Format specifier in C languege

 Format specifier for accept or display any types of data %d  - Used for accept or display the integer value. %c  - Used for accept or display the character value. %f  - Used for accept or display the float value. %lf  - Used for accept or display the double value. %s  - Used for accept or display the string value. Some Examples Data types value :- Integer examples -  32, 5, 098, 345, 893274 etc. Character examples - 'r' , 'E' , 'o' , '5' , '9' , 'w'  etc. Float examples - 23.4 , 2.0 , 5.9 , 8495.78  etc. Double examples - 54.324 , 3.0000 , 2.8754 , 9.222222  etc. String Examples - "prem" ,  "india" , "kumar" , "nishad" etc.

Program to check Even or Odd number

 This program is for display the number is Odd or even in C language #include<stdio.h> #include<conio.h> main() { int a; printf("Enter a number to check odd or even  \n"); scanf("%d",&a); if(a%2==0) printf("Even Number "); else   {    printf("Odd Number ");   } getch(); }

Basic Division program in C languege

 This program is for display the Division of two number in C language #include<stdio.h> #include<conio.h> main() { int a,b,c; printf("Enter two number for Division "); scanf("%d %d ",&a,&b); c=a/b; printf("Division of two number is %d ",c); getch(); }

Basic Multiplication Program in C language

This program is for display the Multiplication of two number in C language #include<stdio.h> #include<conio.h> main() { int a,b,c; printf("Enter two number for Multiplication "); scanf("%d %d ",&a,&b); c=a*b; printf("Multiplication of two number is %d ",c); getch(); }

Basic Substract Program in C Languege

 This program is for display the substraction of two number in C language #include<stdio.h> #include<conio.h> main() { int a,b,c; printf("Enter two number for Substraction "); scanf("%d %d ",&a,&b); c=a-b; printf("Substraction of two number is %d ",c); getch(); }

Basic Add program in C language

This program is for display the sum of two number with C language #include<stdio.h> #include<conio.h> main() { int a,b,c; printf("Enter two number for addition "); scanf("%d %d ",&a,&b); c=a+b; printf("Sum of two number is %d ",c); getch(); }

Hello World in C language

Write your first program in C language Program of Hello World #include<stdio.h> #include<conio.h> main() { printf("Hello World"); }