C++

Program to compute the fibonacci series

#include <iostream.h> #include <conio.h> void main() { clrscr(); int a,b,x,y,num1,ct; a=0; b=1; cout << "Enter the number of terms (less than 25) : " << endl; cin>>num1; cout << a << endl; cout << b << endl; for(ct=1;ct<=num1-2;ct++) { x=a+b; cout...
>>

Program to find the total days in the year till date

#include <iostream.h> #include <conio.h> void main() { clrscr(); int day,month,total; int days_per_month[12]={31,28,31,30,31,30,31,31,30,31,30,31}; cout << "Enter the month : " << endl; cin>>month; cout << "Enter the day : " << endl; cin>>day; total=day; for(int...
>>

Program to convert days into years and weeks

#include <iostream.h> #include <conio.h> void main() { clrscr(); int days,years,weeks,num1; cout << "Enter the number of days : " << endl; cin>>days; years=days/365; num1=days-(years*365); weeks=days/7; num1=days-(weeks*7); cout << days << " days = " <<...
>>

Program to convert 2-digit octal number into binary number and print it

#include <iostream.h> #include <conio.h> void octobin(int); void main() { clrscr(); int a; cout << "Enter a 2-digit octal number : "; cin>>a; octobin(a); getch(); } void octobin(int oct) { long bnum=0; int A[6]; //Each octal digit is converted into 3 bits, 2 octal digits = 6 bits. int...
>>

Program to find the sum of each row & column of a matrix of size n x m and if matrix is square, find the sum of the diagonals also.

 #include <iostream.h> #include <conio.h> int main() { clrscr(); int A[10][10],m,n,x,y,sum=0; //Create a Matrix A cout << "Enter number of rows and columns in Matrix A : \n"; cin>>n>>m; cout << "Enter elements of Matrix A :...
>>

Program to enter an integer and print its total value based on the formula 'x - 1/3!x^3 + 1/5!x^5 - 1/7!x^7 + 1/9!x^9'

#include <iostream.h> #include <conio.h> #include <math.h> int main() { clrscr(); float factorial=1; float num,tot,term,total; int i,n=20,index,j=1; cout << "Enter a single-digit integer :...
>>

Program to enter an integer and output it in the reversed form

#include <iostream.h> #include <conio.h> void main() { clrscr(); long int num1,num2,rnum=0; cout << "Enter an integer : " << endl; cin>>num1; num2=num1; do { rnum=rnum*10; int digit=num1%10; rnum+=digit; num1/=10; } while(num1); cout << "The integer you typed is " <<...
>>

Program to find the roots of a quadratic equation

#include <iostream.h> #include <conio.h> #include <math.h> int main() { clrscr(); float a,b,c,d,root1,root2; cout << "Enter the 3 coefficients a, b, c : " << endl; cin>>a>>b>>c; if(!a){ if(!b) cout << "Both a and b cannot be 0 in ax^2 + bx + c = 0" <<...
>>

Program to enter salary and output income tax and net salary

#include <iostream.h> #include <conio.h> void main() { clrscr(); int itrate; float salary,itax,nsalary=0; cout << "Enter the salary : "; cin>>salary; if(salary>15000) { itax=salary*30/100; itrate=30; } else...
>>

Program to count the number of words and characters in a sentence

#include <iostream.h> #include <conio.h> void main() { clrscr(); int countch=0; int countwd=1; cout << "Enter your sentence in lowercase: " << endl; char ch='a'; while(ch!='\r') { ch=getche(); if(ch==' ') countwd++; else countch++; } cout << "\n Words = " << countwd...
>>
<< 1 | 2 | 3 | 4 | 5 >>

Search site

Copyright © 2012 Dadaso Zanzane. All rights reserved.