Skip to main content

Posts

Showing posts from February, 2015

C Program To Implement Linear Search.

The following code implements linear search (Searching algorithm) which is used to find whether a given number is present in an array or not and if it is present then at what location it occurs. It is also known as sequential search. It is very simple and works as follows: we keep on comparing each element with the element to search until the desired element is found. Time required to search an element using linear search algorithm depends on the size of list. In the best case, element is present at the beginning of list and in the worst case, element is present at the end. Time complexity of linear search is O(n).  #include <stdio.h> int main() { int array[100], search, c, n; printf("\nEnter the number of elements in array: "); scanf("%d",&n); printf("\n\nEnter %d integer(s): \n", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); printf("\n\nEnter the number to search: "); scanf("

How Are The Web Pages Written?

Web pages are written in HTML, the web programming language that tells web browsers how to structure and present content on a web page. In other words, HTML provides the basic building blocks for the web. And for a long time, those building blocks were pretty simple and static: lines of text, links, and images. Today, we expect to be able to do things like play online chess or seamlessly scroll around a map of our neighborhood, without waiting for the entire page to reload for every chess move or every map scroll. The idea of such dynamic web pages began with the invention of the scripting language JavaScript. JavaScript support in major web browsers meant that web pages could incorporate more meaningful real-time interactions. For example, if you have filled out an online form and hit the “submit” button, the web page can use JavaScript to check your entries in real-time and alert you almost instantly if you had filled out the form incorrectly. But the dynamic web as we

C Program To Display Its Own Source Code As Its Output.

The problem seems complicated but the concept behind it is very simple; display the content from the same file you are writing the source code. A predefined macro __FILE__ contains the location of the programming file, it is working on. For example: t he output of following programs display the location of their files.  #include <stdio.h> int main() { printf("%s",__FILE__); }

C Program To Find The GCD And LCM Of Two Integers.

GCD means Greatest Common Divisor. For two integers a and b, if there are any numbers d so that a/d and b/d doesn’t have any remainder, such a number is called a common divisor. Common divisors exist for any pair of integers a and b, since we know that 1 always divides any integer. We also know that common divisors cannot get too big since divisors cannot be any larger than the number they are dividing. Hence a common divisor d of a and b must have d <= a and d <= b. LCM means Least Common Multiplies. For two integer a and b, to know if there are any smallest numbers d so that d/a and d/b doesn't have a remainder. Such a number is called a Least Common Multiplier. Here is source code of the C program to calculate the GCD and LCM of two integers. It compiles and runs on any operating system. Method 1: #include <stdio.h> int main() { int a, b, x, y, t, gcd, lcm; printf("Enter Two Integers: "); scanf("%d%d", &x, &y);

C Program To Convert Natural Numbers To Roman Numerals.

Roman Number System of representing numbers devised by the ancient Romans. The numbers are formed by combinations of the symbols I, V, X, L, C, D, and M, standing, respectively, for 1, 5, 10, 50, 100, 500, and 1,000 in the Hindu-Arabic numeral system. Natural numbers mean no negative numbers and no fractions, i.e. the whole numbers from 1 upwards: 1, 2, 3, and so on. Here is source code of the C program to convert natural numbers to Roman Numerals. It compiles and runs on any operating system. #include <stdio.h> void predigit(char num1, char num2); void postdigit(char c, int n); char romanval[1000]; int i = 0; int main() { int j; long number; printf("Enter any natural number: "); scanf("%d", &number);

What Is The Web App?

If you play online games, use an online photo editor, or rely on web-based services like Google Maps, Twitter, Amazon, YouTube or Facebook, then you’re an active resident in the wonderful world of web apps. What exactly is a web app, anyway? And why should we care? The app is shorthand for an application. Applications are also called programs or software. Traditionally, they’ve been designed to do broad, intensive tasks like accounting or word processing. In the online world of web browsers and smart phones, apps are usually nimbler programs focused on a single task. Web apps, in particular, run these tasks inside the web browser and often provide a rich, interactive experience. Google Maps is a good example of a web app. It provides helpful map features within a web browser. You can pan and zoom around a map, search for a college or cafe, and get driving directions, and so on. It pulls out all the information you need dynamically every time you ask for it. This brings us

What Is The Internet?

To some of us, the Internet is where we stay in touch with friends, get the news, shop, and play games. To some others, the Internet can mean their local broadband providers, or the underground wires and fiber-optic cables that carry data back and forth across cities and oceans. A helpful place to start is near the Very Beginning: 1974 . That was the year that a few smart computer researchers invented something called the Internet Protocol Suite, or TCP/IP for short. TCP/IP created a set of rules that allowed computers to “talk” to each other and send information back and forth. TCP/IP is somewhat like human communication: when we speak to each other, the rules of grammar provide structure to language and ensure that we can understand each other and exchange ideas. Similarly, TCP/IP provides the rules of communication that ensure interconnected devices understand each other so that they can send information back and forth. As that group of interconnected devices grew from one

C Program To Find Leap Years.

In the Gregorian calendar (the current standard calendar in the world), normally the years that are integer multiples of 4 are called leap years. In each leap year, the month of February has 29 days instead of 28. Adding an extra day to the calendar every four years compensates for the fact that a period of 365 days is shorter than a solar year by almost 6 hours. The Gregorian calendar was first used in 1582. Some exceptions to this basic rule are required since the duration of a solar year is slightly less than 365.25 days. Over a period of 4 centuries, the accumulated error of adding a leap day every 4 years amounts to about 3 extra days. The Gregorian calendar therefore omits 3 leap days every 400 years, which is the length of its leap cycle. This is done by omitting February 29 in the 3 century years (integer multiples of 100) that are not also integer multiples of 400. For example, 1700, 1800, 1900, 2100 and 2200 are common years, but 1600, 2000 and 2400 are leap years. By

C Program To Check Whether A Number Is Palindrome Or Not.

This program takes an integer from user and the integer is reversed. If the reversed integer is equal to the integer entered by user then that number is a palindrome. If not that number is not a palindrome.   #include <stdio.h> int main()  { int num, temp, remainder, reverse = 0; printf("Enter an integer: "); scanf("%d", &num); /*  original number is stored at temp */ temp = num; while (num > 0)  { remainder = num % 10; reverse = reverse * 10 + remainder; num /= 10;   }

C Program To Find The Largest Of Three Numbers.

In this program user is asked to enter three numbers and this program will find the largest number among three numbers entered by user. This program can be solved in more than one way. Method 1: #include <stdio.h> int main(){ float a, b, c; printf("Enter three numbers:\n"); scanf("%f %f %f", &a, &b, &c); if(a>=b && a>=c) printf("\nLargest number = %.2f", a); if(b>=a && b>=c) printf("\nLargest number = %.2f", b); if(c>=a && c>=b) printf("\nLargest number = %.2f", c); return 0; }

C Program To Check Whether An Integer Is Odd Or Even.

If a given number is divisible by 2 with the remainder 0 then the number is even number. If the number is not divisible by 2 then that number will be odd number. This C Program checks if a given integer is odd or even. The program can be successfully compiled and run on any system. #include <stdio.h> int main() { int ival, remainder; printf("Enter an integer : "); scanf("%d", &ival); remainder = ival % 2;

C Program To Find The Sum Of Odd And Even Numbers From 1 To N.

The C program calculates the sum of odd numbers and sum of even numbers from 1 to N. It first separates the odd and even numbers from 1 to N, and then adds all odd and even numbers separately. The program can be successfully compiled and run on any system: #include <stdio.h> int main()  { int i, N, oddSum = 0, evenSum = 0; printf("Enter the value of N: "); scanf ("%d", &N); for (i=1; i <=N; i++)  {

C Program To Check Whether A Number Is Positive Or Negative.

If a number is greater than 0 then that number is a positive. If a number is less than 0 then the number is negative. Here the C Program checks if a given number is positive or negative. It can be compiled and run on any system. Method 1: #include <stdio.h> int main() { float num; printf("Enter a number: "); scanf("%f",&num); if (num<=0)  { if (num==0) printf("\n\nYou entered zero which is neither positive nor negative.\n\n"); else printf("\n\n%.2f is negative.\n\n",num); } else printf("\n\n%.2f is positive.\n\n",num); return 0; }

How To Use Margin In CSS?

The CSS margin properties set the size of the white space outside the border. The margins are completely transparent and cannot have a background color. CSS has properties for specifying the margin for each side of an element: §   margin-top §   margin-right §   margin-bottom §   margin-left All the margin properties can have the following values: §   auto - the browser calculates the margin §   length - specifies a margin in px, pt, cm, etc. §   % - specifies a margin in % of the width of the containing element §   inherit - specifies that the margin will be inherited from the parent element It is also possible to use negative values for margins; to overlap content.