Skip to main content

Posts

Showing posts from October, 2018

CALL BY REFERENCE METHOD

Write a program in C to interchange the value of two variables by using the concept of call by reference method. In the call by reference method addresses of argument are passed from main function to the function definition and these addresses are collected or stored in pointer variables. If we update the value of variables in function definition will be reflected throughout the program. Program: - #include<stdio.h> #include<conio.h> void swap(int *a, int *b) { int t; t=*a; *a=*b; *b=t; } void main() { int x,y; clrscr(); printf("\n enter the first number="); scanf("%d",&x); printf("\n enter the second number="); scanf("%d",&y); swap(&x,&y); printf("\n x= %d", x); printf("\n y= %d", y); getch(); } Output: - Enter the first number= Enter the second number= X= Y=

IF GOTO STATEMENT

Write a program to print counting from one to ten using if go to statement. Today we are simply going to discuss about the use of if go to statement. If go to statement is used to transfer the control of execution to the specify label. Syntax: - goto     label name; Program: - #include<stdio.h> #include<conio.h> void main() { int a=1; clrscr(); x:if(a<=10) { printf("\n %d",a); a++; goto x; } getch(); } Output: - 1 2 3 4 5 6 7 8 9 10

CONTINUE STATEMENT

Write a program to input ‘n’ number from the user. Number may be ‘-ve’ or ‘+ve’ . calculate the sum of only ‘-ve’ number. Continue statement is a statement which is used to bypass the current pass of a loop. Syntax: - Continue; Program: - #include<stdio.h> #include<conio.h> void main() { int n, num, sum=0, i; clrscr(); printf("\n enter the number you want to run="); scanf("%d",&n); for( i=0;i<n;i++) { printf("\n enter the number="); scanf("%d",&num); if (num<0) { sum= sum+num; } continue; } printf("\n The sum of numbers is=%d",sum); getch(); } Output: - Enter the number you want to run = (as per user wants) Enter the number = (as per user say) The sum of the numbers is =

USER DEFINE FUNCTION

Write a program to calculate the addition, subtraction, multiplication and division of two numbers by using the concept of user define function. Those functions whose operations are defined by the user are called user defined function. Following functions are included in user define function; -         Function prototype Function prototype know which type of function is return by the function, name of the function, how many argument or parameter is being used by a function and type of argument or parameter used by a function. Syntax: -   Return type     function name (datatype, datatype) -         Function call statement This function call is an independent module which contain main statement which contain main statement which is written for the purpose of execution of the task. Syntax: -   Var. name = function name (arg1, arg2) -     ...

PRINT FIRST 'N' EVEN NUMBER WITH WHILE STATEMENT.

Write a program to print first ‘n’ even number. For this program I’m using while statement to run the loop. While is an repetition  statement which is used to run the program again and again until the required statement is satisfied. Syntax :   - While (condition) { . . Statement ; . } Program : - #include<stdio.h> void main() { int n, a=2, i=0; clrscr(); printf("\n how many first even number you want to calculate="); scanf("%d", &n); while(i<n) { printf("\n %d", a); a=a+2; i++; } getch(); } Output : - How many first even number you want to calculate=

STRUCTURE DATATYPE

Write a program to maintain the record of a student by using the structure datatype. Let’s know something about structure. Structure is a collection of heterogenous element which is created as per requirement of the user. When we have to maintain the many type of values with in a body we need a datatype which can implement all the user define datatype then we can use structure. Syntax : - Struct structure name { Type member 1; Type member 2;           /* desired member can be declared */ }; Struct     structure name     structure variable name; Program : - #include<stdio.h> struct student { int age; char name[20]; float fee; char address[30]; }; struct student s; void main () { clrscr(); printf("\n enter your age= "); scanf("%d",& s.age); printf("\n enter your name="); scanf("%s", s.name ); printf("\n enter your fee="); scanf("...

RECURSIVE FUNCTION

Write a recursive function to calculate the factorial of the number. When a function call itself or when a function call to a second function and in the function definition of 2 nd function again a function call statement for the first function is encountered it is known as recursion and this function is known as recursive function. Let’s do the program: - #include<stdio.h> int factorial (int); void main() { int a,b; clrscr(); printf("\n enter a no="); scanf("%d",&a); b=factorial(a); printf("\n factorial is =%d",b); getch(); } int factorial (int a) { if(a==0) return 1; else return(a*factorial(a-1)); } Dry run : - a=5 (say) return 5* factorial (4) a=4 5*4* factorial (3) a=3 5*4*3* factorial (2) a=2 5*4*3*2*factorial (1) a=1 5*4*3*2*1*factorial (o) a==0 (true) return 1 5*4*3*2*1*1= 120 Factorial is = 120.

POW FUNCTION

Write a program in C to input two variables from the user and calculate the power by using library function. Before going to program we should know about what is library functions. Library function are those type of function which are provided by the library of compiler itself. For this program we are going to use pow function. This function is used to calculate the power of the given number. This function works upon two argument or parameters and after performing the operation always return inter type value. The required header file for these functions is “math.h”. Syntax: -                Int. variable name = pow ( argument 1, argument 2); Program: - #include<stdio.h> #include<math.h> void main ( ) { Int a, b, c; clrscr (); printf (“\n enter the first number=”); scanf(“%d”, &a); printf(“\n enter the power value=”); scanf (“%d”, &b); c= pow (a, b); pr...

UPPER CASE TO LOWER CASE

Write a program in C to input a character from the user in upper case and print that character into lower case. In the previous blog we have discuss about the program to print in upper case and now we are going to write a program to print character in lower case with using to using to lower function. to lower function used to convert a upper case character into the lowercase. The required header file is ctype.h. Syntax: -                Character variable name= tolower (character variable) Program: - #include <stdio.h> #include<ctype.h> void main () { char ch; clrscr (); printf( “\n enter the upper case character= “); scanf(“%c”, & ch); ch= tolower (ch); printf(“\n lower case character is = %c”, ch); getch(); } OUTPUT: - Enter the uppercase character = Lower case character is =
Write a program in C to input a character from the user in lower case and print that character into the upper case. For this program we are going to use toupper function. toupper function is used to convert a lower-case character into the uppercase. The required header file for this is ctype.h (character type). SYNTEX: -                Character variable name = toupper (character variable ) Now let’s do program; #include<stdio.h> #include<ctype.h> void main() { char a; clrscr (); printf (“\n enter the character you want to calculate “); scanf (“%c”, & a); a = toupper (a); printf (“\n upper case form of input character is = %c”, a ); getch(); } OUTPUT: - Enter the character = Uppercase form of input character is =