Sunday, 21 June 2015
Thursday, 18 June 2015
C Program for getting ip address
C Program for getting ip address
This c program prints ip (internet protocol) address of your computer, system function is used to execute the command ipconfig which prints ip address, subnet mask and default gateway.
The code given below works for Windows xp and Windows 7.
If you are using turbo c compiler then execute program from folder, it may not work when you are working in compiler and press Ctrl+F9 to run your program.
C programming code
#include<stdlib.h> int main() { system("C:\\Windows\\System32\\ipconfig"); return 0; }
Download IP address program.
Output of program: ( In Windows 7)
C program to add two numbers
C program to add two numbers
C program to add two numbers: This c language program perform the basic arithmetic operation of addition on two numbers and then prints the sum on the screen. For example if the user entered two numbers as 5, 6 then 11 (5 + 6) will be printed on the screen.
#include<stdio.h> int main() { int a, b, c; printf("Enter two numbers to add\n"); scanf("%d%d",&a,&b); c = a + b; printf("Sum of entered numbers = %d\n",c); return 0; }
Output:
Download Add numbers program executable.
In the expression (c = a + b) overflow may occur if sum of a and b is larger than maximum value which can be stored in variable c.
Addition without using third variable
#include<stdio.h> main() { int a = 1, b = 2; /* Storing result of addition in variable a */ a = a + b; /** Not recommended because original value of a is lost * and you may be using it somewhere in code considering it * as it was entered by the user. */ printf("Sum of a and b = %d\n", a); return 0; }
C program to add two numbers repeatedly
#include <stdio.h> int main() { int a, b, c; char ch; while (1) { printf("Inut two integers\n"); scanf("%d%d", &a, &b); getchar(); c = a + b; printf("(%d) + (%d) = (%d)\n", a, b, c); printf("Do you wish to add more numbers (y/n)\n"); scanf("%c", &ch); if (ch == 'y' || ch == 'Y') continue; else break; } return 0; }
Output of program:
Inut two integers 2 6 (2) + (6) = (8) Do you wish to add more numbers (y/n) y Inut two integers 2 -6 (2) + (-6) = (-4) Do you wish to add more numbers (y/n) y Inut two integers -5 3 (-5) + (3) = (-2) Do you wish to add more numbers (y/n) y Inut two integers -5 -6 (-5) + (-6) = (-11) Do you wish to add more numbers (y/n) n
Adding numbers in c using function
#include<stdio.h> long addition(long, long); main() { long first, second, sum; scanf("%ld%ld", &first, &second); sum = addition(first, second); printf("%ld\n", sum); return 0; } long addition(long a, long b) { long result; result = a + b; return result; }
C Programming
C Programming for Beginners
1.
C hello world program: c programming language code to print hello world.
This program prints hello world, printf library function is used to display text on screen,
'\n' places cursor on the beginning of next line, stdio.h header file contains declaration of printf function.
The code will work on all operating systems may be its Linux, Mac or any other and compilers.
C hello world program: c programming language code to print hello world.
This program prints hello world, printf library function is used to display text on screen,
'\n' places cursor on the beginning of next line, stdio.h header file contains declaration of printf function.
The code will work on all operating systems may be its Linux, Mac or any other and compilers.
Hello world in C language
//C hello world example #include <stdio.h> int main() { printf("Hello world\n"); return 0; }
Purpose of Hello world program may be to say hello to people or the users of your software or application.
Wednesday, 17 June 2015
Sunday, 14 June 2015
Thursday, 4 June 2015
Subscribe to:
Posts (Atom)