Posts

Showing posts from March, 2020

Program to print first 9 natural numbers using For loop

Image
Here, I have used Dev C++ platform, it is easy to download. In this program, integer "i" is declared. For Loop has been used initiating i from 1 and print the value of i in each loop increasing value of i by 1 until given condition becomes false ie, i<10. Output Exercise Print natural numbers from 10 to 30 using For Loop. Give your answer in comment section.

Goto Statement or Jump statement in C

Image
T he goto statement is also known as jump statement that makes a program procedure to jump any where from anywhere within the program. It is sometime also called unconditional jump statement.  In this program, it takes name of a person and then prints it. Here " jump: " is a label that goto statement will transfer the step when encountered. So, after printing the name, it asks to continue and if a user enter y or Y the goto statement transfer the step to that label and if any other key is pressed the program will print Visit Again.

Break and Continue in C

Image
B reak statement when encountered in the loop it immediately break the loop and program resumes at the line following the loop. It also terminate the case statement in switch. For example, if we are writing a program to search a name among 1000 of given names, we may have applied loop for this program, . But if the program finds it in 10th iteration and at this point, we don't need to travel for remaining 990 iteration, we just need to terminate the loop and resume the program outside the loop. For this, only break statement is useful.The break statement is used in conjunction with condition. For example, In this program, i increases by 1 and when it encounters with number 5, it gets broken and the loop gets terminated.And thus, the output will be 1 2 3 4 C ontinue statement is used to omit a particular statement and proceed to next iteration. The continue statement escape the statement and move to next iteration. For example, if we have to escape 10th number from 1000...

Looping

Image
L oop is used in programming to execute any instruction repeatedly until a condition is satisfied. The computer has ability to perform a set of instructions repeatedly. This involves repetition of some portion of a program either for a specified number of times or till a given condition is satisfied. This repetition operation is known as looping. Purpose of Looping To execute statements for a specified number of times. To use a sequence of values. Types of Loop in C programming While Loop do while Loop For loop While Loop It execute one or more statements while the given condition remains true. It is useful when number of iterations is unknown. It is also called entry control or pre test loop. fig: Flowchart of while loop do while Loop do while loops are useful where loop is to be executed at least once. In do while loop condition comes after the body of loop. The loop executes one or more statements while the given condition is true. It is an exit control or post...

Social Medias on Corona Virus

Image
Nowadays, social medias such as Facebook, Twitter, Instagram are full of information related to Corona virus. Almost everyone in the world are using these medias and getting information related on this viral topic. But, mean while since the information are shared by anyone may create confusion on the information related Corona virus since a false news are also been posted there. Social medias are need to be consider for this and should make a necessary steps to filter the information on the serious sensitive information. People are becoming panic and are afraid very much since they are getting wrong information. They are in dilemma of either their locality has become prey of the virus or not, either the vaccine are made yet or not, either they are safe to travel to foreign or not, either the precaution they are using is better or not and so on. A large masses of people are sharing the wrong information day by day in Facebook. Many more TV channels are making it as source of inc...

Program to print name of a day using switch case statement.

Image
  Explanation: Here number is inputted in variable 'day' and when it is equivalent with day in week and matches the preceeding case, it will print whatever in the block given.  

Why we use function in C?

F unctions are used for dividing a large code into module, due to this we can easily debug and maintain the code. For example if we write a calculator programs at that time we can write every logic in a separate function. Any function can be called many times. A dvantages of Function Code Reusuability Develop an application in module format Easy to debug the program Code optimization: no need to write a lot of code Code is easier to read Program testing becomes easier Compiled executable is smaller You don't need to make comments because function name make sense Program can be developed in short period of time There is no chance of code duplication

Program to check whether a entered letter is vowel or not using switch case statement

Image
Explanation Here Switch case plays a role of nested if else statement. It is an alternative way of if else statement. In this program, a variable c is declared to store alphabet entered by user. And now case is applied, if the given letter matches to the case then it enters to its block and print the given statement and then break the procedure. If the case is not matched it will check another case and if not matches all the cases then it will enter to in the default block. Output

Program to print division of a person.[Note: A person gets Distinction if s/he score 80% or above, First Division if s/he below 80% and above 60% , similarly 50% or above will be Second and if 32% and above will be Third division]

Image
E xplanation Here, per stores float percentage. It has been checked and if it is above 100 or below 31 it will print invalid that is stated in else statement at line 16. Nested if statement is used here so if the "per" value is  less or equal to 100 and if per is above 31 it enters inside and is checked with value 80,60,50 to print distinction, first and second division respectively and for third division,it will be sure if the above condition is false.

Program to find greatest number among any three different numbers inputted by User.

Image
  Explanation :Here three variables are declared a,b and c. The numbers in a,b and c are checked considering a is the greatest it is compared with b and c. If is greater in both condition, it will be greatest and if not, surely b or c will be greatest and are compared using else if. If b is greater than c then b will be greatest number and if it is also not then c is the greatest number as neither a nor b is greatest. Output Exercise : Make a program to state the smallest number among any three different inputted numbers.

Progarm to state that a person can cast vote or not. [Note: A person can cast vote if he is 18 years old or above]

Image
  Explanation, Here name is string so as it is defined as character of array 50. The specifier is %s is used to take scanf and value in age is checked with 18 and if it is equal to 18 or greater than this s/he can cast vote and if it is less than 18 and s/he cannot vote.   Exercise:  Make a program that can say he is old or yound. [Note if s/he is greater than age 40 than he is old and if he less than 40 then he is young.]

Define operator. Explain different types of operators used in C.

O perator is a special symbol used in programming that performs specific operation on operands. It is used to operate any two or multiple operands. Here, In c=a+b expression, a, b and c are operands and "=" and "+" are operators. There are different types of operators used in C programming. Arithmetic operators Relational operators Equality operators Logical operators Assignment operators, Unary operators Conditional operators Size Of operator Arithmetic Operator Arithmetic Operators are used to perform mathematical calculations. These operators are used with two or more than two operands. Arithmetic Operators are: "+"------------------> Addition---------------->a+b---------------->add value of "a" and "b" "-" ------------------> Subtraction -------------------> a-b-------------> subtract value of "a" and "b" "*" ---------------------> Multiplication------...