Tuesday, September 29, 2015

While loop

#include <stdio.h>
#include <conio.h>
int main () {
int count=0;
int total=0;
while (count <10)
{
total+=count;
printf("count = %d,total =%d\n",count++,total);
getche();
return 0;
}
}
books (including programming for pc by robert lafore)


Character counting using while loop

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

int main () {
int count=0;

printf ("type in a phrase\n");
while (getche()!='\r')
{
count++;
printf("in character count is %d\n",count);
}
getche ();
return 0;
}

Sunday, September 27, 2015

Admin

Tabish Ali

Dark sensor Project (LDR)

You wan't do a dark sensor with a LDR, one transistor and one LED and you don't know how to do it? In this small tutorial I will explain to you how you can do that even if you know only the basics of electronic.

Parts you need:

1 Breadboard;
1 Power source of 12v;
1 Transistor (in this case we use the BC547);
1 Resistor of 1KOhm;
1 Resistor of 680KOhm;
1 LED (in this case blue);
1 LDR:
Some condutor cables to connect the parts.

Step 1: Connecting parts in the breadboard

In the above image we can see the circuit we will construct. It's a simple electronic circuit and if you know how to do something on a breadboard, you should be able to do that dark sensor.

Step 2: Connect everything

Just do the circuit like this and all should be working fine.

Remember, the LDR resistance depends on the light you have on the room or where you are constructing that. If you have light, the LDR resistance is low so, the LED should be turned off. When you obstruct the light that focus on the LDR, the LED should light up. 

If for any reason your LED is always lighted up, try to chance the transistor. Switch the Emitter and the Collector. If the problem persist, increase the resistor you have in the base.

Step 3: All should be working

Connect the power source you have to the breadboard. The positive pole in the red line and the negative in the blue line.

Try your circuit and see what happens.

Here's the video of my circuit working:


If you have any questions feel free to ask in the coments. If you think I should improve something, let me know. It's my first guide so it's normal I made some mistakes.




Prgoram to convert your age in months,weeks,days,hours,minutes, and seconds.

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

 int main ( ) {
 int days,years,months,hours,minutes,seconds;
 float weeks;

 printf("Enter your age in years");
 scanf("%.1d",years);
 months=years*12;

printf("Age in months is %d\n",months);
weeks=years*52.14;

printf("Age in weeks is %.1f\n",weeks);
days=years*365;

printf("Age in days is %d\n",days);
 hours=days*24;

 printf("Age in hours is %d\n",hours);
 minutes=hours*60;

 printf("Age in minutes is %d\n",minutes);
 seconds=minutes*60;

 printf("Age in seconds is %d\n",seconds);  

getch();
return ();

}

Basic "Hello world" program using c

Hello, World!

Introduction

The C programming language is a general purpose programming language, which relates closely to the way machines work. Understanding how computer memory works is an important aspect of the C programming language. Although C can be considered as "hard to learn", C is in fact a very simple language, with very powerful capabilities.
C is a very common language, and it is the language of many applications such as Windows, the Python interpreter, Git, and many many more.
C is a compiled language - which means that in order to run it, the compiler (for example, GCC or Visual Studio) must take the code that we wrote, process it, and then create an executable file. This file can then be executed, and will do what we intended for the program to do.

Our first program

Every C program uses libraries, which give the ability to execute necessary functions. For example, the most basic function called printf, which prints to the screen, is defined in the stdio.h header file.
To add the ability to run the printf command to our program, we must add following include derivative to our first line of the code:
The second part of the code is the actual code which we are going to write. The first code which will run will always reside in the main function.
Notice that every line in C must end with a semicolon, so that the compiler knows that a new line has started.
Last but not least, we will need to call the function printf to print our sentence.

#include <stdio.h>

#include <conio.h>


int main (  
{

printf ("Hello world");

getch ();
return 0;

}

Basic Programs (click here)

Variables and Types

Variables and Types

Data types

C has several types of variables, but there are a few basic types:
  • Integers - whole numbers which can be both positive and negative. Defined using charintshortlong orlong long.
  • Unsigned integers - whole numbers which can only be positive. Defined using unsigned charunsigned int,unsigned shortunsigned long or unsigned long long.
  • Floating point numbers - real numbers (numbers with fractions). Defined using float and double.
  • Structures - will be explained later, in the Structures section.
The different types of variables define their bounds. A char can range only from -128 to 127, whereas a long can range from -2,147,483,648 to 2,147,483,647.
Note that C does not have a boolean type. Usually, it is defined using the following notation:
#define BOOL char
#define FALSE 0
#define TRUE 1
For numbers, we will usually use the type int, which an integer in the size of a "word" the default number size of the machine which your program is compiled on. On most computers today, it is a 32-bit number, which means the number can range from -2,147,483,648 to 2,147,483,647 (same as long).
To define the variables foo and bar, we need to use the following syntax:
int foo;
int bar = 1;
The variable foo can be used, but since we did not initialize it, we don't know what's in it. The variable bar contains the number 1.
Now, we can do some math. Assuming abcd, and e are variables, we can simply use plus, minus and multiplication operators in the following notation, and assign a new value to a:
int a = 0,b = 1,c = 2,d = 3, e = 4;
a = b - c + d * e;
printf("%d", a); /* will print 1-2+3*4 = 11 */

#include <stdio.h>
int main() {
  int a = 3;
  float b = 4.5;
  double c = 5.25;
  float sum;
  sum = a + b + c;
  printf("The sum of a, b, and c is %f.", sum);
  return 0;
}
Facebook(contact me)