Posts

basic 2 c++.cpp

 #include<iostream> using namespace std; int glo = 6; void sum() {     int a;     cout<<glo; }     int main() {     int a = 5, b = 9;     int glo = 8;     glo = 78;     float pi = 3.14;     char c = 'u';     //bool true mean 1 and false mean 0     bool is_true =false;     sum();     cout<<glo<<is_true;     // cout <<"the value of a is "<<a<<"\nthe value of b is "<<b;     // cout<<"\nthe value of pi is "<<pi;     // cout<<"\nthe value of pi is "<<c;     return 0; } 

add two values by taking input from user c++.cpp

 #include <iostream> using namespace std; int main() {     int num1, num2;     cout << "enter the value of num1: \n"; /*<< this is called insertion operator*/     cin >> num1;                           /*>>extraction operator*/     cout << "enter the value of num2: \n"; /*<< this is called insertion operator*/     cin >> num2;                           /*>>extraction operator*/          cout << "sum of num1 and num2 is : "<<num1+num2;     return 0; }

basic program of c++.cpp

  #include <iostream> using   namespace   std ; int   main () {      int  a  =   5 , b  =   9 ;      float  pi  =   3.14 ;      char  c  =   'u' ;     cout  << "the value of a is " << a << " \n the value of b is " << b;     cout << " \n the value of pi is " << pi;     cout << " \n the value of pi is " << c;      return   0 ; } 

decrypt.c

 #include<stdio.h>  #include<conio.h> void decrypt(char *c) {     char *ptr=c;     while(*ptr!='\0')     {         *ptr = *ptr - 1;         *ptr++;     } } int main() {     char c[]= "dpnf!up!uijt!sppn";     decrypt(c);     printf("decrypted string is %s", c);     getch();     return 0; }

encrypt.c

 #include<stdio.h>  #include<conio.h> void encrypt(char *c) {     char *ptr=c;     while(*ptr!='\0')     {         *ptr = *ptr + 1;         *ptr++;     } } int main() {     char c[]= "come to this room";     encrypt(c);     printf("encrypted string is %s", c); getch();     return 0; }

game(snake gun and water).c

 #include <stdio.h> #include <stdlib.h> #include <time.h> char game(char you, char comp) {     if (you == comp)     {         return 0;     }     else if (you == 's' && comp == 'g')     {         return -1;     }     else if (you == 'g' && comp == 's')     {         return 1;     }     else if (you == 's' && comp == 'w')     {         return 1;     }     else if (you == 'w' && comp == 's')     {         return -1;     }     else if (you == 'w' && comp == 'g')     {         return 1;     }     else if (you == 'g' && comp == 'w')     {         return -1;     } } int main() { ...

number guessing game.c

 #include <stdio.h> #include <stdlib.h> #include <time.h> #include<conio.h> int main() {     int num, guess, nguess = 1;     srand(time(0));     num = rand() % 100 + 1;     // printf("the number is %d\n", num);     do     {         printf("guess the number between 1 to 100\n");         scanf("%d", &guess);         if (guess < num)         {             printf("higher number please\n");         }         else if (guess > num)         {             printf("lower number please\n");         }         else         {             printf("guess after %d attempt\n", nguess);         }   ...