graphics program for traffic light in C++

C Programming Tutorial

Here is traffic light program written in C++ using graphics.h header file. This program is Compiled using Turbo C++. /*Program for traffic Light*/ #include<iostream.h> #include<graphics.h> #include<conio.h> #include<dos.h> #include<stdlib.h> void main() { clrscr(); int gd = DETECT, gm, midx, midy; initgraph(&gd, &gm, “C:\\TC\\BGI”); midx = getmaxx()/2; midy = getmaxy()/2; setcolor(CYAN); settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(midx, midy-10, “Traffic Light … Read more

Hierarchy of Operators Revisited in C

C Programming Tutorial

Since we have now added the logical operators to the list of operators we know, it is time to review these operators and their priorities. The higher the position of an operator is in the table, higher is its priority. The following figure summarizes the working of all the three logical operators.

C Program to calculate the salary

C Programming Tutorial

Problem Statement: Write a program to calculate the salary as per the following table: Solution: /* C program to calculate salary */ main( ) { char g ; int yos, qual, sal ; printf ( “Enter Gender, Years of Service and Qualifications ( 0 = G, 1 = PG ):” ) ; scanf ( “%c%d%d”, &g, … Read more

write a C program to obtain the sum of the first and last digit of this number

C Programming Tutorial

Problem Statement: If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number. Solution: /* Sum of 1st and last digit of a four digit number */ #include<stdio.h> #include<conio.h> main() { int n,a,sum=0; clrscr(); printf(“\Enter a four digit number”); scanf(“%d”,&n); a=n/1000; … Read more

write a C program to reverse the number

C Programming Tutorial

Problem Statement : If a five-digit number is input through the keyboard, write a program to reverse the number. Answer: /* To reverse the digits of 5-digit number */ #include<stdio.h> #include<conio.h> main() { int n,a,b; long int revnum=0; clrscr(); printf(“\n Enter a five digit number less than 32767”); scanf(“%d”,&n); a=n%10; /*last digit */ n-n/10; /* … Read more

Write a C program to interchange the contents of C and D

C Programming Tutorial

Problem Statement :  Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D. Answer: /* Interchanging of contents of two variables c & d */ #include<stdio.h> #include<conio.h> main() { int c,d,e; clrscr(); printf(“\n Enter the number at location C:”); scanf(“%d”, &c); … Read more

Write a C program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle

C Programming Tutorial

Problem Statement: The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle. Answer: /* Calculation of perimeter and area of rectangle and circle */ #include<stdio.h> #include<conio.h> main() { … Read more

let us C : Start Learning C Programming

C Programming Tutorial

Before we can begin to write serious programs in C, it would be interesting to find out what really is C, how it came into existence and how does it compare with other computer languages. In this chapter we would briefly outline these issues. We will also learn four important aspects of any language are … Read more