Knowledge in c programming questions

Write a program To enter 5 Number and assambe in assanding Order By using Single Dimentional array.

Write a program To enter 5 Number and assambe in assanding Order By using Single Dimentional array. The greatest Number. Programming with C (First semester ) Makhanlal chaturvedi national and jounalism university,Bhopal class notes of C programming from Makhanlal Chaturvedi national journalism and communication university,Bhopal. Share with your friends to Help them to learn c programming. This class notes is very important for BCA first semester students .

C Programs

C Programming Language TutorialC language Tutorial with programming approach for beginners and professionals, helps you to understand the C language tutorial easily. Our C tutorial explains each topic with programs.The C Language is developed for creating system applications that directly interact with the hardware devices such as drivers, kernels, etc.C programming is considered as the base for other programming languages, that is why it is known as mother language.It can be defined by the following ways:Mother languageSystem programming languageProcedure-oriented programming languageStructured programming languageMid-level programming language1) C as a mother languageC language is considered as the mother language of all the modern programming languages because most of the compilers, JVMs, Kernels, etc. are written in C language, and most of the programming languages follow C syntax, for example, C++, Java, C#, etc.It provides the core concepts like the array, strings, functions, file handling, etc. that are being used in many languages like C++, Java, C#, etc.2) C as a system programming languageA system programming language is used to create system software. C language is a system programming language because it can be used to do low-level programming (for example driver and kernel). It is generally used to create hardware devices, OS, drivers, kernels, etc. For example, Linux kernel is written in C.It can't be used for internet programming like Java, .Net, PHP, etc3) C as a procedural languageA procedure is known as a function, method, routine, subroutine, etc. A procedural languagespecifies a series of steps for the program to solve the problem.A procedural language breaks the program into functions, data structures, etc.C is a procedural language. In C, variables and function prototypes must be declared before being used.4) C as a structured programming languageA structured programming language is a subset of the procedural language. Structure means to break a program into parts or blocks so that it may be easy to understand.In the C language, we break the program into parts using functions. It makes the program easier to understand and modify.

First C Program

Before starting the abcd of C language, you need to learn how to write, compile and run the first c program.To write the first c program, open the C console and write the following code:#include <stdio.h>    int main(){    printf("Hello C Language");    return 0;   }  #include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h .int main() The main() function is the entry point of every program in c language.printf() The printf() function is used to print data on the console.return 0 The return 0 statement, returns execution status to the OS. The 0 value is used for successful execution and 1 for unsuccessful execution.Or, press ctrl+f9 keys compile and run the program directly.You will see the following output on user screen.You can view the user screen any time by pressing the alt+f5 keys.Now press Esc to return to the turbo c++ console.

printf() and scanf() in C

printf() and scanf() in Cprintf() functionThe printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file).printf() functionThe printf() function is used for output. It prints the given statement to the console.The syntax of printf() function is given below:printf("format string",argument_list); scanf() functionThe scanf() function is used for input. It reads the input data from the console.scanf("format string",argument_list); 

C programs

Program to print sum of 2 numbersLet's see a simple example of input and output in C language that prints addition of 2 numbers.#include<stdio.h>    int main(){    int x=0,y=0,result=0;    printf("enter first number:");  scanf("%d",&x);  printf("enter second number:");  scanf("%d",&y);    result=x+y;  printf("sum of 2 numbers:%d ",result);    return 0;  }    Outputenter first number:9 enter second number:9

C if else Statement

C if else StatementThe if-else statement in C is used to perform the operations based on some specific condition. The operations specified in if block are executed if and only if the given condition is true.There are the following variants of if statement in C language.If statementIf-else statementIf else-if ladderNested ifIf StatementThe if statement is used to check some given condition and perform some operations depending upon the correctness of that condition. It is mostly used in the scenario where we need to perform the different operations for the different conditions. The syntax of the if statement is given below.if(expression){  //code to be executed  } Let's see a simple example of C language if statement.#include<stdio.h>    int main(){    int number=0;    printf("Enter a number:");    scanf("%d",&number);    if(number%2==0){    printf("%d is even number",number);    }    return 0;  }    OutputEnter a number:4 4 is even number enter a number:5 If-else StatementThe if-else statement is used to perform two operations for a single condition. The if-else statement is an extension to the if statement using which, we can perform two different operations, i.e., one is for the correctness of that condition, and the other is for the incorrectness of the condition. Here, we must notice that if and else block cannot be executed simiulteneously. Using if-else statement is always preferable since it always invokes an otherwise case with every if condition. The syntax of the if-else statement is given below.if(expression){  //code to be executed if condition is true  }else{  //code to be executed if condition is false  } Let's see the simple example to check whether a number is even or odd using if-else statement in C language.#include<stdio.h>    int main(){    int number=0;    printf("enter a number:");    scanf("%d",&number);     if(number%2==0){    printf("%d is even number",number);    }    else{    printf("%d is odd number",number);    }     return 0;  }    Outputenter a number:4 4 is even number enter a number:5 5 is odd number

C Switch Statement

C Switch StatementThe switch statement in C is an alternate to if-else-if ladder statement which allows us to execute multiple operations for the different possibles values of a single variable called switch variable. Here, We can define various statements in the multiple cases for the different values of a single variable.The syntax of switch statement in c language is given below:switch(expression){    case value1:     //code to be executed;     break;  //optional  case value2:     //code to be executed;     break;  //optional  ......        default:      code to be executed if all cases are not matched;    }  Rules for switch statement in C language1) The switch expression must be of an integer or character type.2) The case value must be an integer or character constant.3) The case value can be used only inside the switch statement.4) The break statement in switch case is not must. It is optional. If there is no break statement found in the case, all the cases will be executed present after the matched case. It is known asfall through the state of C switch statement.Let's try to understand it by the examples. We are assuming that there are following variables.int x,y,z;  char a,b;  float f; Switch case example 2#include <stdio.h>  int main()  {      int x = 10, y = 5;       switch(x>y && x+y>0)      {          case 1:           printf("hi");          break;           case 0:           printf("bye");          break;          default:           printf(" Hello bye ");      }             }  Outputhi

C Loops

C LoopsThe looping can be defined as repeating the same process multiple times until a specific condition satisfies. There are three types of loops used in the C language. In this part of the tutorial, we are going to learn all the aspects of C loops.Why use loops in C language?The looping simplifies the complex problems into the easy ones. It enables us to alter the flow of the program so that instead of writing the same code again and again, we can repeat the same code for a finite number of times. For example, if we need to print the first 10 natural numbers then, instead of using the printf statement 10 times, we can print inside a loop which runs up to 10 iterations.Advantage of loops in c1) It provides code reusability.2) Using loops, we do not need to write the same code again and again.3) Using loops, we can traverse over the elements of data structures (array or linked lists)Types of C LoopsThere are three types of loops in C language that is given below:do whilewhilefordo-while loop in CThe do-while loop continues until a given condition satisfies. It is also called post tested loop. It is used when it is necessary to execute the loop at least once (mostly menu driven programs).The syntax of do-while loop in c language is given below:do{  //code to be executed  }while(condition);  Flowchart and Example of do-while loopdo-while loop in CThe do-while loop continues until a given condition satisfies. It is also called post tested loop. It is used when it is necessary to execute the loop at least once (mostly menu driven programs).The syntax of do-while loop in c language is given below:do{  //code to be executed  }while(condition);  Flowchart and Example of do-while loop

do while loop in C

do while loop in CThe do while loop is a post tested loop. Using the do-while loop, we can repeat the execution of several parts of the statements. The do-while loop is mainly used in the case where we need to execute the loop at least once. The do-while loop is mostly used in menu-driven programs where the termination condition depends upon the end user.do while loop syntaxThe syntax of the C language do-while loop is given below:do{  //code to be executed  }while(condition); Example 1#include<stdio.h>  #include<stdlib.h>  void main ()  {      char c;      int choice,dummy;        do{      printf("\n1. Print Hello\n2. Print Javatpoint\n3. Exit\n");      scanf("%d",&choice);      switch(choice)      {          case 1 :           printf("Hello");           break;          case 2:            printf("Javatpoint");          break;          case 3:          exit(0);           break;          default:           printf("please enter valid choice");          }      printf("do you want to enter more?");       scanf("%d",&dummy);      scanf("%c",&c);      }while(c=='y');  }  Output1. Print Hello 2. Print Javatpoint 3. Exit 1 Hello do you want to enter more? y 1. Print Hello 2. Print Javatpoint 3. Exit 2 Javatpoint do you want to enter more? n

C break statement

C break statementThe break is a keyword in C which is used to bring the program control out of the loop. The break statement is used inside loops or switch statement. The break statement breaks the loop one by one, i.e., in the case of nested loops, it breaks the inner loop first and then proceeds to outer loops. The break statement in C can be used in the following two scenarios:With switch caseWith loopSyntax://loop or switch case   break; Example#include<stdio.h>  #include<stdlib.h>  void main ()  {      int i;      for(i = 0; i<10; i++)      {          printf("%d ",i);          if(i == 5)          break;      }      printf("came outside of loop i = %d",i);        }  Output0 1 2 3 4 5 came outside of loop i = 5

C continue statement

C continue statementThe continue statement in C language is used to bring the program control to the beginning of the loop. The continue statement skips some lines of code inside the loop and continues with the next iteration. It is mainly used for a condition so that we can skip some code for a particular condition.Syntax://loop statements  continue;  //some lines of the code which is to be skipped  Continue statement example 1#include<stdio.h>  void main ()  {      int i = 0;       while(i!=10)      {          printf("%d", i);           continue;           i++;      }  }  Output infinite loop

C goto statement

C goto statementThe goto statement is known as jump statement in C. As the name suggests, goto is used to transfer the program control to a predefined label. The goto statment can be used to repeat some part of the code for a particular condition. It can also be used to break the multiple loops which can't be done by using a single break statement. However, using goto is avoided these days since it makes the program less readable and complecated.Syntax:label:   //some part of the code;   goto label; goto exampleLet's see a simple example to use goto statement in C language.#include <stdio.h>  int main()   {    int num,i=1;     printf("Enter the number whose table you want to print?");     scanf("%d",&num);    table:     printf("%d x %d = %d\n",num,i,num*i);    i++;    if(i<=10)    goto table;    }  Output:Enter the number whose table you want to print?10 10 x 1 = 10 10 x 2 = 20 10 x 3 = 30 10 x 4 = 40 10 x 5 = 50 10 x 6 = 60 10 x 7 = 70 10 x 8 = 80 10 x 9 = 90 10 x 10 = 100