skip to main | skip to sidebar
Showing posts with label C Programming. Show all posts
Showing posts with label C Programming. Show all posts

Wednesday, August 24, 2011

Requested Tutorial Basic input with if else Conditions

0 comments
A sociological study clasifies a family of three persons as POOR, MIDDLE CLASS and WEALTHY. provided that family income is less than 12,000.00 Php between 12,000.00 and 70,000.00 Php respectively.

The Problem

Create a program which acepts family income as input from the user and displays the proper classification of the family.
FAMILY INCOME CLASSIFICATION
FAMILY INCOME
below 12,000 - POOR
12,000 - 70,000 - MIDDLE CLASS
above 70,000 - WEALTHY

Requested By: Jp Natividad


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

void main() {
clrscr();
int income;
printf("Enter your income: ");
scanf("%d",&income);
if (income < 12000) {
printf("Family income classification: POOR \n\n");
printf("FAMILY INCOME: %d",income);
}
else if(income >= 12000 && income <= 70000)
{
printf("Family income classification: MIDDLE CLASS \n");
printf("FAMILY INCOME: %d",income);
}
else if(income > 70000)
{
printf("Family income classification: WEALTHY \n");
printf("FAMILY INCOME: %d",income);
}
getch();
}




Tuesday, August 23, 2011

Simple Arithmetic Operation using Selective Structure Switch

0 comments
















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

void main() {
clrscr();
int operand1, operand2;
char oprtor;
printf("Enter the first number: ");
scanf("%d",&operand1);
printf("\nEnter the second number: ");
scanf("%d",&operand2);
printf("\nEnter operation: ");
scanf("%s",&oprtor);
switch (oprtor) {
case '+': //Addition
printf("%d %c %d = %d",operand1, oprtor, operand2, operand1 + operand2 );
break;
case '-': // Subtraction
printf("%d %c %d = %d",operand1, oprtor, operand2, operand1 - operand2 );
break;
case '*': //Multiplication
printf("%d %c %d = %d",operand1, oprtor, operand2, operand1 * operand2 );
break;
case '/': //Division
printf("%d %c %d = %d",operand1, oprtor, operand2, operand1 / operand2 );
break;
case '%': // Modulo, display the Reamaider
printf("%d %c %d = remainder %d",operand1, oprtor, operand2, (operand1) % operand2 );
break;
default:
break;
}
getch();
}

Simple Arithmetic Operation using Conditional Structure if & else in C Language

0 comments

This source code perform simple arithmetic operation using Conditional structure (if & else) and Arithmetic operators ( +, -, *, /, % ).












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

void main() {
clrscr();
int operand1, operand2;
char oprtor;
printf("Enter the first number: ");
scanf("%d",&operand1);
printf("\nEnter the second number: ");
scanf("%d",&operand2);
printf("\nEnter operation: ");
scanf("%s",&oprtor);
if (oprtor == '+') { //Addition
printf("%d %c %d = %d",operand1, oprtor, operand2, operand1 + operand2);
}
else if (oprtor == '-') {// Subtraction
printf("%d %c %d = %d",operand1, oprtor, operand2, operand1 - operand2);
}

else if (oprtor == '*') { //Multiplication
printf("%d %c %d = %d",operand1, oprtor, operand2, operand1 * operand2);
}
else if (oprtor == '/') { //Division
printf("%d %c %d = %d",operand1, oprtor, operand2, operand1 / operand2);
}
else if (oprtor == '%') { // Modulo, display the Reamaider
printf("%d %c %d = remainder %d",operand1, oprtor, operand2, (operand1) % operand2);
}
getch();

}

Sunday, August 21, 2011

How to find Grade equivalent using C Language

0 comments
This program was the first requested tutorial on C programming Language using the Turbo C++ IDE.

This source code will determine the corresponding equivalent of your grade using the conditional structure if & else and selective structure switch.


Requested by: Jp Natividad


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

float eq; // global variable

void main() // main function
{
clrscr();
int grade; // contains the value input

printf("enter your grade: ");
scanf("%d",&grade);


//conditions

if(grade <= 74 ) {
printf("FAILED");
eq = 5.00;
}
else if (grade >= 75 && grade <=100) {
printf("PASSED\n");

switch (grade){
case 75: case 76: case 77:
eq = 3.00; break;
case 78: case 79: case 80: case 81:
eq = 2.75; break;
case 82: case 83:
eq = 2.50; break;
case 84: case 85: case 86:
eq = 2.25; break;
case 87: case 88: case 89:
eq = 2.00; break;
case 90: case 91: case 92:
eq = 1.75; break;
case 93: case 94: case 95:
eq = 1.50; break;
case 96: case 97: case 98:
eq = 1.25; break;
case 99: case 100:
eq = 1.00; break;
default:
break;
}
}
else {
printf("invalid\n");

}
printf("your equivalent grade is: %.2f",eq);

getch();

}

Friday, August 19, 2011

What is C Programming Language?

0 comments
C Programming Language is a general-purpose computer programming language developed by Dennis Ritchie between 1969 and 1973 at the Bell Telephone Laboratories for use with the Unix operating system.

C is one of the most widely used programming languages for various reasons.

It has high-level constructs.
It can handle low-level activities.
It produces efficient programs.
It can be compiled on a variety of computers.

The syntax of the C programming language is a set of rules that specifies whether the sequence of characters in a file is conforming C source code. The syntax of textual programming languages is usually defined using a combination of regular expressions.

The syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language.

Before you start programing you need a text editor there are many text editor available online, the most popular text editor are Vim and Emacs, a text editor with syntax highlighting is recommended as it can make code easier to read. Highlighting can also make it easy to spot syntax errors.

If you choose to use a text editor, you will be required to have a C compiler. The most popular C compilers GNU C Compiler, Visual Studio Express, Borland C Compiler. A compiler is a program that converts C code into executable machine code.

Or you can download an IDE (Integrated Development Environment) over a text editor and compiler. An IDE is a program that combines a set of programs that developers need into one convenient package, usually with a graphical user interface. These programs include a compiler, linker, and text editor. Most popular IDE use CDT, Dev C++, Xcode and Microsoft Visual Studio Express.

On Microsoft Windows, Microsoft Visual Studio Express, may be helpful for beginners but requires setting up a compilation project before making an executable file.

On Mac OS X, the Xcode IDE provides the compilers needed to compile various source files.

Sample Program that will print "Hello World" on screen

hello.c

#include <stdio.h>

int main () {
printf("Hello World! \n");

return 0;
}