Posts

Showing posts from December, 2021

Rand function in c language (useful for random number generating game )

  #include <stdio.h> #include <stdlib.h> int main(void) { // This program will create same sequence of // random numbers on every program run for(int i = 0; i<5; i++) printf(" %d ", rand()); return 0; }

FUNCTION OVERRIDING IN CPP

  #include<conio.h> #include<iostream> using namespace std; class overriding {     int age;     public:          void over(){         cout<<"Enter your age :"<<endl;         cin>>age;         cout<<"Age: "<<age;              } }; class override{       char name[20];       public:       void over(){                cout<<"Enter your name "<<endl;     cin>>name;     cout<<"Name :"<<name; }       }; int main(){     overriding obj1;     obj1.over();          override obj;     obj.over();           return 0;      }

GYM HOME

Image
  Lakshman's Fitness Home   About Us   Services   Whatsapp   Blog Email Now   Sign Up These days is 60% off join Pune Gym now Submit Now

About gym

  This is the website whereby you can register yourself and you can join the gym of Pune. It is the best gym in All Pune. After joining this gym. You will show that yes I have developed my body personality.

write a program to print tribonacci series in c language

  // A simple recursive CPP program to print // first n Tribonacci numbers.  #include<stdio.h>  #include<conio.h>   int printTribRec(int n) { if (n == 0 || n == 1 || n == 2) return 0; if (n == 3) return 1; else return printTribRec(n - 1) + printTribRec(n - 2) + printTribRec(n - 3); } void printTrib(int n) { for (int i = 1; i < n; i++) printf("\n%d  ",printTribRec(i)); } // Driver code int main() { int n = 30; printTrib(n); return 0; }

write a program to calculate total and average marks of 5 subjects

  ** * C program to calculate total, average and percentage of five subjects */ #include <stdio.h> int main() { float eng, phy, chem, math, comp; float total, average, percentage; /* Input marks of all five subjects */ printf("Enter marks of five subjects: \n"); scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp); /* Calculate total, average and percentage */ total = eng + phy + chem + math + comp; average = total / 5.0; percentage = (total / 500.0) * 100; /* Print all results */ printf("Total marks = %.2f\n", total); printf("Average marks = %.2f\n", average); printf("Percentage = %.2f", percentage); return 0; }

write a program to check year is leap year or not

  #include <stdio.h> int main () { int year ; year = 2016 ; if ((( year % 4 == 0 ) && ( year % 100 != 0 )) || ( year % 400 == 0 )) printf ( "%d is a leap year" , year ); else printf ( "%d is not a leap year" , year ); return 0 ; }

write a program to calculate area of circle area of square area of triangle and area of rectangle

  #include <stdio.h> #include <math.h> main (){     int choice ;    printf ( "Enter\n1 to find area of Triangle\n2 for finding area of Square\n3 for finding area of Circle\n4 for finding area of Rectangle\n5 for Parallelogram\n" );    scanf ( "%d" ,& choice );     switch ( choice ) {       case 1 : {           int a , b , c ;           float s , area ;          printf ( "Enter sides of triangle\n" );          scanf ( "%d%d %d" ,& a ,& b ,& c );          s =( float )( a + b + c )/ 2 ;          area =( float )( sqrt ( s *( s - a )*( s - b )*( s - c )));          printf ( "Area of Triangle is %f\n" , area );           break ;       }       case 2 : { ...

write a program to find prime numbers between two range in c

  #include <stdio.h> int main (){     int number1 , number2 , i , j , flag ;    printf ( "enter the two intervals:" );    scanf ( "%d %d" ,& number1 ,& number2 );    printf ( "prime no’s present in between %d and %d:" , number1 , number2 );     for ( i = number1 + 1 ; i < number2 ; i ++){ // interval between two numbers       flag = 0 ;       for ( j = 2 ; j <= i / 2 ;++ j ){ //checking number is prime or not           if ( i % j == 0 ){             flag = 1 ;             break ;           }       }       if ( flag == 0 )          printf ( "%d\n" , i );     }     return 0 ; }

write a program to print fibonacci series

  #include<stdio.h>      int  main()     {       int  n1=0,n2=1,n3,i,number;      printf( "Enter the number of elements:" );      scanf( "%d" ,&number);      printf( "\n%d %d" ,n1,n2); //printing 0 and 1        for (i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed       {       n3=n1+n2;       printf( " %d" ,n3);       n1=n2;       n2=n3;      }      return  0;    }    

write a program to find factorial of a number using both methods

 // C program to find factorial of given number #include <stdio.h // function to find factorial of given number unsigned int factorial(unsigned int n) { if (n == 0) return 1; return n * factorial(n - 1); } int main() { int num = 5; printf("Factorial of %d is %d", num, factorial(num)); return 0; }   or or ......................................... #include <stdio.h> // function to find factorial of given number unsigned int factorial(unsigned int n) { int res = 1, i; for (i = 2; i <= n; i++) res *= i; return res; } int main() { int num = 5; printf( "Factorial of %d is %d", num, factorial(num)); return 0; }

write a program to check a number is prime or not

 // C++ program to check if a // number is prime #include <iostream> #include <math.h> using namespace std; int main() { int n, i, flag = 1; // Ask user for input cout <<"Enter a number: \n"; // Store input number in a variable cin >> n ; // Iterate from 2 to sqrt(n) for (i = 2; i <= sqrt(n); i++) { // If n is divisible by any number between // 2 and n/2, it is not prime if (n % i == 0) { flag = 0; break; } } if (n <= 1) flag = 0;  if (flag == 1) { cout << n <<" is a prime number"; } else { cout << n <<" is not a prime number"; } return 0; } // This code is contributed by shivanisinghss2110.

write a program to check a number is perfect or not

  #include <stdio.h> int main (){     int number , i , result = 0 ; //declare variables and initialize result to 0    printf ( "enter the number:" );    scanf ( "%d" ,& number );     for ( i = 1 ; i <= number ; i ++){       if ( number % i == 0 )          result = result + i ;     }     if ( result == 2 * number ) //checking the sum of factors==2*number       printf ( "perfect number" );     else       printf ( "not perfect number" ); }

write a program to print first n natural numbers

  # include <stdio.h> void main () { int i, n; printf ( "Enter the value of n\t" ); scanf ( "%d" , &n); printf ( "Printing natural numbers from 1 to %d\n" , n); i = 1 ; do { printf ( "%d\t" , i); i++; } while (i <= n); printf ( "\n" ); }

write a program to check a number is armstrong or not

  #include<stdio.h>      int  main()     {     int  n,r,sum=0,temp;     printf( "enter the number=" );     scanf( "%d" ,&n);     temp=n;     while (n>0)     {     r=n%10;     sum=sum+(r*r*r);     n=n/10;     }     if (temp==sum)     printf( "armstrong  number " );     else      printf( "not armstrong number" );     return  0;   }   

write a program to check a number is palindrome or not

  #include<stdio.h>    int  main()     {     int  n,r,sum=0,temp;     printf( "enter the number=" );     scanf( "%d" ,&n);     temp=n;     while (n>0)     {     r=n%10;     sum=(sum*10)+r;     n=n/10;     }     if (temp==sum)     printf( "palindrome number " );     else      printf( "not palindrome" );    return  0;   }   

write a program to calculate sum of digits

  #include<stdio.h>      int  main()     {     int  n,sum=0,m;     printf( "Enter a number:" );     scanf( "%d" ,&n);     while (n>0)     {     m=n%10;     sum=sum+m;     n=n/10;     }     printf( "Sum is=%d" ,sum);     return  0;   }   

write a program to reverse a number

  #include<stdio.h>      int  main()     {     int  n, reverse=0, rem;     printf( "Enter a number: " );       scanf( "%d" , &n);        while (n!=0)       {          rem=n%10;          reverse=reverse*10+rem;          n/=10;       }       printf( "Reversed Number: %d" ,reverse);     return  0;   }   

write a program to make calculator using switch case

 #include <stdio.h> int main() {   char op;   double first, second;   printf("Enter an operator (+, -, *, /): ");   scanf("%c", &op);   printf("Enter two operands: ");   scanf("%lf %lf", &first, &second);   switch (op) {     case '+':       printf("%.1lf + %.1lf = %.1lf", first, second, first + second);       break;     case '-':       printf("%.1lf - %.1lf = %.1lf", first, second, first - second);       break;     case '*':       printf("%.1lf * %.1lf = %.1lf", first, second, first * second);       break;     case '/':       printf("%.1lf / %.1lf = %.1lf", first, second, first / second);       break;     // operator doesn't match any case constant     default:       printf("Error! operator is not correct");   }   return 0; }

write a program to print 5 student records using structure and union

 #include <stdio.h> struct student {     char firstName[50];     int roll;     float marks; } s[5]; int main() {     int i;     printf("Enter information of students:\n");     // storing information     for (i = 0; i < 5; ++i) {         s[i].roll = i + 1;         printf("\nFor roll number%d,\n", s[i].roll);         printf("Enter first name: ");         scanf("%s", s[i].firstName);         printf("Enter marks: ");         scanf("%f", &s[i].marks);     }     printf("Displaying Information:\n\n");     // displaying information     for (i = 0; i < 5; ++i) {         printf("\nRoll number: %d\n", i + 1);         printf("First name: ");         puts(s[i].firstName);       ...