Skip to main content

Posts

Showing posts with the label Program Code

C++ Program to calculate the factorial of an integer

In C++ program you can write a program to calculate the factorial of an integer . Let's look at the code to calculate the factorial of an integer.  #include <iostream> using namespace std ; int main ()  { int i, num, fact=1 ; cout <<"\n Enter integer" ; cin>> num; i = num ;  while (num)  { fact *=num ; --num ; } cout<< "The factorial of " << i ; cout<<"is" << fact <<"\n" ; return 0 ;  } The output of the C++ Code  C++ Program to calculate the factorial of an integer

C++ Program to calculate the area of a square

In C++ program you can write a program to calculate the area of a square. Let's look at the C++ Code to calculate the area of a square . #include <iostream.h> #include <conio.h> using namespace std; int main () { float side, area ; cout<<"Enter side of the square : " ; cin >>side ; cout<<"\n The area of the square is :" ; cout<<side*side ; cout<<"square-units" ; return 0 ; } The Output of the C++ Code C++ Program to calculate the area of a square 

C++ Program to convert a given number of days into years, weeks and days

In C++ Programs we can write a program to convert a given number of days into years, weeks and days. Let's look at the C++ Code  to convert a given number of days into years, weeks and days. #include <iostream.h> #include <conio.h> using namespace std ; int main () { clrscr ();  int totdays, years, weeks, days, num1;  cout<<"Ener total number of days : " ; cin>> totdays ;  years = totdays / 366 ;  num1= totdays % 365 ;  weeks = num1 / 7 ; days = num1 % 7 ; cout<<"\n" ; cout<<" Years =" << years <<"," ;  cout<<"weeks ="<< weeks <<"," ;  cout<<"Days ="<< days <<"\n" ; return 0 ; } The output of the C++ Code C++ Program to convert a given number of days into years, weeks and days 

C++ Program to check if a string is palindrome or not

The word palindrome means that when read from left to right or right to left it is the same. The spelling of palindromic words is the same on either side.  In C++ Programs we can write a program to check if the string is palindrome or not. C++ Program to check if a string is a palindrome or not #include <iostream> #include <stdlib.h> int main () { system ("cls"); char string[80],c ; std::cout<<"Enter a string (maximum 79 characters only) \n"; std::cin.getline(string,80); for (int len = 0 ; string[len] != '\0'; ++len) ; int i,j,len, flag = 1 ;  for (i = 0, j = len - 1 ; i < len / 2 ; ++i, --j)  { if (string[i]=string[j]) { flag = 0 ; break ;  } } if (flag) std::cout <<"It is a palindrome \n"; else  std::cout<<"It is not a palindrome \n" ; return 0 ; } The output of the C++ Code C++ Program to check if a string is a palindrome or not

C++ Program to count the number of characters entered

In C++ Program you can write a code to count the characters of the word entered. Let's look at the coding. C++ Program to count the number of characters entered #include <iostream.h> #include <conio.h> int main () { int chcount =  0 ; const char ent = '\n' ; char ch ; std::cout << "Enter character\n" ;  std::cin.get(ch) ; while (ch!=ent) { chcount++ ; std::cout.put(ch) ; std::cin.get(ch) ; } std::cout <<"\n The number of characters = " <<chcount <<"\n" ; return 0 ;  } The output of the C++ Program Code C++ Program to count the number of characters entered

C++ Program to Convert Temperature from Fahrenheit to Celsius and Celsius to Fahrenheit (If-else statement)

In C++ programming language we can write a program to convert temperature from Fahrenheit to Celsius and Celsius to Fahrenheit with the simple use ofIf-else statement. Let's us look at the code.  C++ Program to Convert Temperature from Fahrenheit to Celsius and Celsius to Fahrenheit  (If-else statement) #include <iostream.h> int main() { int choice ;  float temp, countemp ;  std::cout<<"Temperature conversion Menu"<<"\n" ; std::cout<<"1. Fahrenheit to Celsius"<<"\n" ; std::cout<<"2. Celsius to Fahrenheit"<<"\n" ; std::cout<<"Enter your choice:" ; std::cin>>choice;  if( choice == 1) { std::cout<<"\n"<<" Enter temperature in Fahrenheit :" ; std::cin >> temp ;  countemp = (temp -32) / 1.8 ; std::cout<<" The temperature in Celsius is : " << countemp <<"\n" ; } else  { std::cout<<...

C ++ Program to read radius of a circle to calculate area and perimeter to display them

In C++ Program you can easily write a code to read the radius of a circle to calculate the area of the circle and the perimeter of the circle. Let's have a look at the C ++ Program to read radius of a circle to calculate area and perimeter to display them  #include <iostream.h> #include <stdlib.h> int main () { system ("cls") double radius, area, perimeter ; cout<<"Enter Radius of the circle : "; cin>>radius ; perimeter = 2 * 3.14159 * radius ; area = 3.14159 * radius * radius ; cout <<"The area of the circle is" ; cout<< area ; cout<<"\n The perimeter of the circle is : " ; cout<< perimeter ; return 0 ; } Out Put of the Above C++ Code  C++ Code for Circle area and Perimeter Output

Program to print odd numbers from 100 to 1 in C++

In a C++ program, you can write code to print odd numbers from 100 to 1. Here is how to do it.  C++ Program Code #include <iostream.h> int main () { for (int i=99 ; i > 0 ; i-- ) if (i % 2) std::cout << i << ' ' ; return 0 ;  } The output of the Program

Program to write even and odd integers into different files

#include<stdio.h> #include<math.h> void main() { FILE *all,*even,*odd; int number,i,records; printf("INPUT THE TOTAL NUMBER OF RECORDS THAT U WANT TO ENTER "); scanf("%d",& records); all=fopen("ANYNUMBER","w"); for(i=1;i<=records;i++) { scanf("%d",&number); if(number==-1)break; putw(number,all); } fclose(all); all=fopen("ANYNUMBER","r"); even=fopen("EVENNUMBER","w"); odd=fopen("ODDNUMBER","w"); while((number=getw(all))!=EOF) { if(number%2==0) putw(number,even); else putw(number,odd); } fclose(all); fclose(even); fclose(odd); even=fopen("EVENNUMBER","r"); odd=fopen("ODDNUMBER","r"); printf("  THE EVEN NUMBERS ARE"); while((number=getw(even))!=EOF) printf(" %4d",number); printf("  THE ODD NUMBERS ARE"); while((number=getw(odd))!=EOF) printf(...