Posts

Showing posts from August, 2020

Guess the number

 #guessing our numbers by user print("Guess the number\n""You have only 7 guesses") n=1 while(True):     i = int(input())     if i==18:         print("You have guessed correct number")         break     else:         if n<7:             print("Remaining chances are", 7 - n)             n = n + 1             if i<18:                 print("Enter little bit big number")             elif i>18:                 print("Enter lesser number")         else:             print("you have lost your chances")             break

Faulty calculator

a=int(input("Enter first number")) c=input("Enter operator") b=int(input("Enter second number")) if a==45 and b==3 and  c=='*':     print("Your answer is", 555) elif a==56 and b==9 and c=='+':     print("Your answer is", 77) elif a==56 and b==6 and c=='/':     print("Your answer is", 4) elif c=='+':     print("Your answer is", a+b) elif c=='-':     print("Your answer is", a-b) elif c=='*':     print("Your answer is",a*b) else :     print("Your answer is ",a/b)

Loops in C program

Do while loop in c  program //do while loop //  Do while loops are used when we have to execute block of loop // at least once for sure i.e. even the condition is false then also // do while loop get executed for once. // In do while loop, first of all the statements of do block get // executed and then the condition is checked and if the condition is true // then it repeat the same step i.e. control goes to top of the loop // and again executes it and this process occur till the condition becomes false. #include <stdio.h> int main() {     int num, index = 0;     printf("Enter a number\n");     scanf("%d", &num);     do     {         // In this case we take integer input from user as num         //Then the other integer index perform the program         // Mainly it print the numbers in the order         //untill the index is less than num...

If Else control statements and switch

If else control statements // if else control statements #include <stdio.h> int main() {     int age;     printf("Enter your age\n");     //  we have taken the input age     scanf("%d", &age);     printf("You have entered %d as your age\n", age);     if (age >= 18)     {         // if statement- In if statement condition is checked,         // and if it is true then 'if'statement is executed         // otherwise it is skipped and rest of the code is exected.         printf("You can vote!");     }     else if (age >= 10)     {         // if-else statement: In if-else statement first of all 'If'         // // condition is checked and if the condition is true then 'If'         // statement gets executed otherwise 'else'statements get...

Operators in C programming

  // operators in c // Arithmatic operators // Relational operators // Logical operators // Bitwise operators #include <stdio.h> #include <conio.h> #include <math.h> int main() {         // this is an example for arithmatic operators         int a, b, c, d;         printf("note - this programm includes addtion substraction and multiplication\n");         printf("enter number a\n");         scanf("%d", &a);         printf("enter number b\n");         scanf("%d", &b);         printf("enter number c\n");         scanf("%d", &c);         printf("enter number d\n");         scanf("%d", &d);         // Arthmatic operators are         // addition, substraction, multiplication, divison     ...

Data types in C programm

                                // data types in c programm // 1 primary data types in c  // char,int,float,double // 2 secondary data types in c // array, pointer, structure etc // data type of variable // char (stores the character value) // int (stores the integer value) // float (stores the decimal value) // int %d // char %c // string %s // float %f

Basic structure of a c programm

                                 // basic structure of a c programm #include <stdio.h> #include <conio.h>// these are header files // #include<stdio.h> means standered input and output // syntax of the c programm basically syntax is the way of programm // code that runs int main()   //int main is the main code every programm starts with int main. {     printf("Hello world");      // printf is used to print the character, result or output     return 0; } // important points to remember while writing a c programm // must use printf //  scanf( it is used to read character or a vlaue assign)