Posts

Function in C Programming language

Image
 Functions- Functions in c language  A function is group of statements that together perform a task. Every C program has at least one function, which is main(). Every function has a name and it is reusable. It can take parameters called as argument. Properties- Every function has a unique name. This name is used to call function from "main()" function.  A  function can be called another function. A function is independent and it can perform its task without intervention from or interfering with other parts of the program. A function returns a value to the calling program. this is optional and depends upon the task your function is going to accomplish. Structure of a Function <return type>FunctionName(Argument1,Argument2,Argument3..............) {                                                      ...

Pattern1 in C language

Image
 Nested loop  C programming language allows to use one loops inside another loop is know as nested loop  Syntax: for(init;condition;increment) {     for(init;condition;increment) {     statement(s); } statement(s); } p1-program to print following pattern 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5  program- #include<stdio.h> void main()  { int i,j; for(i=1;i<=5;i++) { for(j=1;j<=5;j++) {   printf("%d ",j);} printf("\n");}  } P2-program to print following pattern  1  1  1  1  1  2  2  2  2  2  3  3  3  3  3  4  4  4  4  4  5  5  5  5  5 program- #include<stdio.h> void main() { int i,j; for(i=1;i<=5;i++) { for (j=1;j<=5;j++) { printf(" %d ",i);} printf("\n"); } } P3-Program to print following pattern   * * * * *  * * * * *  * * * *...

For Loop in C-programming

Image
 For Loop  A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Syntax- for(variable int; condition ;variable update) {     statement; } program1-write a program to print "hello Word" five time  code- #include<stdio.h> void main() { int i; for(i=0;i<=5;i++) { printf("hello\n"); } } output- hello hello hello hello hello hello -------------------------------- program2-Write a program to print 0to 10 number using while loop code- #include<stdio.h> void main() { int i; for(i=0;i<=10;i++) { printf("%d\n",i); } } output- 0 1 2 3 4 5 6 7 8 9 10 -------------------------------- Program3-write a program to find sum of series 1!+1/2!+1/3!+1/4!+1/5!.......... code- #include<stdio.h> void main() { float fact=1,sum=0,i,n; printf("Enter the value of n"); scanf("%f",&n); for(i= 1;i<=n;i++) { fact=fact*...

While Loop in C language

Image
While loop  While loop is also known as Entry Control loop because condition is checked at the entry of loop. syntax while(condition) { statement;  Increment/decrement; } Program1-Write a program to print 0to 10 number using while loop  code- #include<stdio.h> void main() { int i=0,number=10; while(i<=10) { printf("%d\n",i); i++; } } Output 0 1 2 3 4 5 6 7 8 9 10 --------------------------------------------------------------------------------- program2-write a program to find out the factorial of number using while loop. code- #include<stdio.h> void main() { int fact=1,i=1,number; printf("Enter a number to find factorial:"); scanf("%d",&number); while(i<=number) { fact=fact*i; i++; } printf("The factorial of %d is %d",number,fact); output- Enter a number to find factorial:5 The factorial of 5 is 120 -----------------------------------------------------------------------------------------...

Assignment and Bitwise Operators

 Assignment Operators(=,+=,-=,*=,/=,%=) The assignment operators are used to assign right-hand side value( Rvalue ) to the left-hand side variable(L value). The Assignment operator used in different variants along with arithmetic operators. Operator Meaning Example = Assign the right-hand side value to left-hand side variable A=15 += Add both left and right-hand side values and store the result into left-hand side variable A+=10 A=A+10   -= Subtract right-hand   side value from left-hand side variable value and store the result Into left-hand side variable A-=B A=A-B   *= Multiply right-hand side value with left-hand side variable Value and store the result Into left hand side variable A*=B A=A*B     /= Divide left-hand side variable value w...

Branching Statement (if ,If-else) in C-language

Image
Concept of Branching -if If statement is very frequently used in decision making and allowing the flow of program execution. The condition part should not end with a semicolon, since the condition and statement should be put together as a dingle statement.  Syntax if(condition) {      Statement;} Example-Write a code using if statement show input number is positive or negative  program- #include<stdio.h> void main() { int number; printf("Type a number "); scanf("%d",&number); if(number>0) printf("Enter number is  positive "); if (number<0) printf("Enter number is negative "); } output- Type a number 10 Enter number is  positive -------------------------------- //for negative number  Type a number -5 Enter number is negative -------------------------------- Q.N. which of the following are incorrect statements ? if int a=10. 1) if(a==10)      printf("Include Help"); 2) if(10==a)     pr...

Data Input functions in C programming

Image
 DATA INPUT  The input operators are used to read user value (input) from the keyboard.  The c programming language provides the following built-in-input functions. 1.  scanf() 2.  getcher() 3.  getch() 4.  gets() 5.  fscanf() scanf() function : The scanf() function is used to read multiple data values of different data types from the keybord. Syntax:             scanf("format strings",&variableName); Example : #include<stdio.h> #include<conio.h> void main() {     int i;        printf("\nEnter any integer value:");        scanf("%d",&i);       printf("\nYou have entered %d number",i);       getch(); } getcher() functn The getcher() function is used to read a characher from the keyboard and return it to the program. getch() function: The getch function is similar to getcher function. The getch() function is used to ...

Logical Operator and conditional operator

Image
Logical Operator  The logical operators are the symbols that are used to combined multiple condition into one condition.   Logical Operator with example Operator Meaning Example && Logical AND -Return TRUE   if all conditions are TRUE otherwise returns FALSE 8<5&&12>10 is FALSE || Logical OR- Returns FALSE if all condition are FALSE otherwise returns TRUE 8<5&&12>10 is true ! Logical NOT -Return TRUE if condition is FALSE and returns FALSE if it is TRUE !(8<5   && a2>10) is true Conditional operator  The conditional operator is also called a ternary operator  because it requires three operands. This operator is used for decision making. Syntax Condition? TRUE part :FALSE part; Example-write a code for conditional operator  program- #include...

Arithmetic and Relational Operators with example in C programming

Image
 Arithmetic (+,-,/,%) Arithmetic Operators in C The arithmetic operators are the symbols that are used to perform basic mathematical  operations like addition , subtraction, multiplication, division and percentage modulo. Example-Write a program to perform all Arithmetic operation in c language  Program for Arithmetic operation #include <stdio.h> void main() {   int a, b;             printf("Enter the valur of the two number for performing the arithmatic opertion \n");       printf("Enter the frist number a::");       scanf("%d",&a);       printf("Enter the second number of the b::");       scanf("%d",&b);     printf("Arithmetic operator in C \n");  printf("this is value of a+b is %d",a+b); printf("\nthis is value of a-b is %d",a-b); printf("\n this is value of a*b is %d",a*b);     printf("\n This is value of a/b is %d",a/b); }...

Constants in C Programing with Example

Image
 Constants: A constant is analogous to the variable but the constant hold just one value during the program execution. In constant once a value is assigned to the constant, that value cannot be changed during the program execution. Once value is assigned to the constant, it is fixed throughout the program. In C programming language, a constant are often of any data type like integer, floating-point, character, string and double ,etc. Creating constants in C Constant  can be created using two concepts. Using the 'const' keyword- We create a constant of any data type using 'const' keyword. To create a constant , we prefix the variable declaration with 'const' keyword. Syntax const datatype constantName;                         or  const datatype constantName=value; Example: const int c=10; Here 'x' is a integer constant with fixed value 10.   Q.N. write code for const and try to change value of con...