W.A.P. C++

WAP | CPP | Programs in C++ | C++ Solutions

Snehil Khanor's Binary Log

Write a program to store Name, Age and address of student


Name age and address of students are stored in a string..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. void main()
  5. {
  6. clrscr();
  7. char name[100],age[100],address[100];
  8. cout<<"Please enter a name: ";
  9. gets(name);
  10. cout<<"Please enter age: ";
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. gets(age);
  14. cout<<"Please eneter address: ";
  15. gets(address);
  16. cout<<endl<<endl<<"Name is: "<<name<<endl<<"Age is: "<<age<<endl<<"Address is:
  17. "<<address;
  18. getch();
  19. }

Write a program to count number of words in a line


A line is taken from user and number of words is calculated..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. void main()
  5. {
  6. clrscr();
  7. char str[100];
  8. int w=1;
  9. cout<<"Please enter a String: ";
  10. gets(str);
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. for (int i=0;str[i]!='\0';i++)
  14. {
  15. if(str[i]==' ')
  16. w++;
  17. }
  18. cout<<"There are "<<w<<" words.";
  19. getch();
  20. }

Write a program to count the number of vowels in a word


A word is taken from the user and number of vowels is determined..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. char str[10];
  7. int v=0;
  8. cout<<"Please enter a string: ";
  9. cin>>str;
  10. //Coding by: Snehil Khanor
  11. //http://WapCPP.blogspot.com
  12. for(int i=0;str[i]!='\0';i++)
  13. {
  14. if(str[i]=='a'||str[i]=='A'||str[i]=='e'||str[i]=='E'||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O'||str[i]=='u'||str[i]=='U')
  15. v++;
  16. }
  17. cout<<v<<" Number of Vowels are there.";
  18. getch();
  19. }

Write a program to check a character is in upper case or lower case


A character is taken from user and is checked if it is in UPPER CASE or lower case..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. char x;
  7. cout<<"Please enter a character: ";
  8. cin>>x;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. if(x>='A'&&x<='Z')
  12. cout<<x<<" is in UPPER CASE:)";
  13. else
  14. cout<<x<<" is in lower case :)";
  15. getch();
  16. }

Write a program to store a character and check it is vowel or consonant


A character is taken from user.. and is checked if it is a vowel or a consonant..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. //Coding by: Snehil Khanor
  7. //http://WapCPP.blogspot.com
  8. char x;
  9. cout<<"Please enter a character: ";
  10. cin>>x;
  11. if(x=='a'||x=='A'||x=='e'||x=='E'||x=='i'||x=='I'||x=='o'||x=='O'||x=='u'||x=='U')
  12. cout<<x<<" is a Vowel :)";
  13. else
  14. cout<<x<<" is a consonant :)";
  15. getch();
  16. }

Write a program to find transpose of a matrix


A matrix is taken from user.. and its Transpose is displayed as output..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[10][10],m,n,i,j;
  7. cout<<"Enter number of rows: ";
  8. cin>>m;
  9. cout<<"Enter number of coloumns: ";
  10. cin>>n;
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. if(m!=n)
  14. {
  15. cout<<"Matrix not square so Transpose not possible :(";
  16. }
  17. else
  18. {
  19. cout<<endl<<"Enter elements of matrix: "<<endl;
  20. for(i=0;i<m;i++)
  21. {
  22. for(j=0;j<n;j++)
  23. {
  24. cout<<"Enter element a"<<i+1<<j+1<<": ";
  25. cin>>a[i][j];
  26. }
  27. }
  28. cout<<endl<<"Displaying Matrix: "<<endl<<endl;
  29. for(i=0;i<m;i++)
  30. {
  31. for(j=0;j<n;j++)
  32. {
  33. cout<<a[i][j]<<" ";
  34. }
  35. cout<<endl<<endl;
  36. }
  37. cout<<endl<<"Displaying Matrix Transpose: "<<endl<<endl;
  38. for(i=0;i<m;i++)
  39. {
  40. for(j=0;j<n;j++)
  41. {
  42. cout<<a[j][i]<<" ";
  43. }
  44. cout<<endl<<endl;
  45. }
  46. }
  47. getch();
  48. }

Write a program for multiplication of two matrices


Two matrices are taken from user..multiplication matrix is displayed as output.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[10][10],b[10][10],c[10][10],m,n,o,p,i,j;
  7. cout<<"Enter number of rows of A: ";
  8. cin>>m;
  9. cout<<"Enter number of coloumns of A: ";
  10. cin>>n;
  11. cout<<endl<<"Enter elements of matrix A: "<<endl;
  12. //Coding by: Snehil Khanor
  13. //http://WapCPP.blogspot.com
  14. for(i=0;i<m;i++)
  15. {
  16. for(j=0;j<n;j++)
  17. {
  18. cout<<"Enter element a"<<i+1<<j+1<<": ";
  19. cin>>a[i][j];
  20. }
  21. }
  22. cout<<endl<<"Enter number of rows of B: ";
  23. cin>>o;
  24. cout<<"Enter number of coloumns of B: ";
  25. cin>>p;
  26. cout<<endl<<"Enter elements of matrix B: "<<endl;
  27. for(i=0;i<o;i++)
  28. {
  29. for(j=0;j<p;j++)
  30. {
  31. cout<<"Enter element b"<<i+1<<j+1<<": ";
  32. cin>>b[i][j];
  33. }
  34. }
  35. cout<<endl<<"Displaying Matrix A: "<<endl<<endl;
  36. for(i=0;i<m;i++)
  37. {
  38. for(j=0;j<n;j++)
  39. {
  40. cout<<a[i][j]<<" ";
  41. }
  42. cout<<endl<<endl;
  43. }
  44. cout<<endl<<"Displaying Matrix B: "<<endl<<endl;
  45. for(i=0;i<o;i++)
  46. {
  47. for(j=0;j<p;j++)
  48. {
  49. cout<<b[i][j]<<" ";
  50. }
  51. cout<<endl<<endl;
  52. }
  53. if(n==o)
  54. {
  55. for(i=0;i<m;i++)
  56. {
  57. for(j=0;j<p;j++)
  58. {
  59. c[i][j]=0;
  60. for(int k=0;k<n;k++)
  61. {
  62. c[i][j]=c[i][j]+a[i][k]*b[k][j];
  63. }
  64. }
  65. }
  66. cout<<endl<<"Matrix A * Matrix B = Matrix C: "<<endl<<endl;
  67. for(i=0;i<m;i++)
  68. {
  69. for(j=0;j<p;j++)
  70. {
  71. cout<<c[i][j]<<" ";
  72. }
  73. cout<<endl<<endl;
  74. }
  75. }
  76. else
  77. cout<<"Multiplication not possible :(";
  78. getch();
  79. }

Write a program to find Difference of two matrix


Two matrix are taken from user.. Substraction matrix is displayed as output..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[10][10],b[10][10],c[10][10],m,n,i,j;
  7. cout<<"Enter number of rows: ";
  8. cin>>m;
  9. cout<<"Enter number of coloumns: ";
  10. cin>>n;
  11. cout<<endl<<"Enter elements of matrix A: "<<endl;
  12. //Coding by: Snehil Khanor
  13. //http://WapCPP.blogspot.com
  14. for(i=0;i<m;i++)
  15. {
  16. for(j=0;j<n;j++)
  17. {
  18. cout<<"Enter element a"<<i+1<<j+1<<": ";
  19. cin>>a[i][j];
  20. }
  21. }
  22. cout<<endl<<"Enter elements of matrix B: "<<endl;
  23. for(i=0;i<m;i++)
  24. {
  25. for(j=0;j<n;j++)
  26. {
  27. cout<<"Enter element b"<<i+1<<j+1<<": ";
  28. cin>>b[i][j];
  29. }
  30. }
  31. //Coding by: Snehil Khanor
  32. //http://WapCPP.blogspot.com
  33. cout<<endl<<"Displaying Matrix A: "<<endl<<endl;
  34. for(i=0;i<m;i++)
  35. {
  36. for(j=0;j<n;j++)
  37. {
  38. cout<<a[i][j]<<" ";
  39. }
  40. cout<<endl<<endl;
  41. }
  42. cout<<endl<<"Displaying Matrix B: "<<endl<<endl;
  43. for(i=0;i<m;i++)
  44. {
  45. for(j=0;j<n;j++)
  46. {
  47. cout<<b[i][j]<<" ";
  48. }
  49. cout<<endl<<endl;
  50. }
  51. cout<<endl<<"Matrix A - Matrix B = Matrix C: "<<endl<<endl;
  52. for(i=0;i<m;i++)
  53. {
  54. for(j=0;j<n;j++)
  55. {
  56. cout<<a[i][j]-b[i][j]<<" ";
  57. }
  58. cout<<endl<<endl;
  59. }
  60. getch();
  61. }

Write a program to find sum matrix of two matrix


Two matrix are taken from user.. Sum matrix is displayed as output..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[10][10],b[10][10],c[10][10],m,n,i,j;
  7. cout<<"Enter number of rows: ";
  8. cin>>m;
  9. cout<<"Enter number of coloumns: ";
  10. cin>>n;
  11. cout<<endl<<"Enter elements of matrix A: "<<endl;
  12. for(i=0;i<m;i++)
  13. {
  14. for(j=0;j<n;j++)
  15. {
  16. cout<<"Enter element a"<<i+1<<j+1<<": ";
  17. cin>>a[i][j];
  18. }
  19. }
  20. cout<<endl<<"Enter elements of matrix B: "<<endl;
  21. //Coding by: Snehil Khanor
  22. //http://WapCPP.blogspot.com
  23. for(i=0;i<m;i++)
  24. {
  25. for(j=0;j<n;j++)
  26. {
  27. cout<<"Enter element b"<<i+1<<j+1<<": ";
  28. cin>>b[i][j];
  29. }
  30. }
  31. cout<<endl<<"Displaying Matrix A: "<<endl<<endl;
  32. for(i=0;i<m;i++)
  33. {
  34. for(j=0;j<n;j++)
  35. {
  36. cout<<a[i][j]<<" ";
  37. }
  38. cout<<endl<<endl;
  39. }
  40. cout<<endl<<"Displaying Matrix B: "<<endl<<endl;
  41. for(i=0;i<m;i++)
  42. {
  43. for(j=0;j<n;j++)
  44. {
  45. cout<<b[i][j]<<" ";
  46. }
  47. cout<<endl<<endl;
  48. }
  49. cout<<endl<<"Matrix A + Matrix B = Matrix C: "<<endl<<endl;
  50. for(i=0;i<m;i++)
  51. {
  52. for(j=0;j<n;j++)
  53. {
  54. cout<<a[i][j]+b[i][j]<<" ";
  55. }
  56. cout<<endl<<endl;
  57. }
  58. getch();
  59. }

Write a program to store elements in m x n 2D array (Matrix)


m(row) and n(coloumns) are taken from user.. Elements are taken from user.. matrix is displayed in tabular form..
This should be your first program for Matrix.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[10][10],m,n,i,j;
  7. cout<<"Enter number of rows: ";
  8. cin>>m;
  9. cout<<"Enter number of coloumns: ";
  10. cin>>n;
  11. cout<<endl<<"Enter elements of matrix: "<<endl;
  12. //Coding by: Snehil Khanor
  13. //http://WapCPP.blogspot.com
  14. for(i=0;i<m;i++)
  15. {
  16. for(j=0;j<n;j++)
  17. {
  18. cout<<"Enter element a"<<i+1<<j+1<<": ";
  19. cin>>a[i][j];
  20. }
  21. }
  22. cout<<endl<<"Displaying Matrix: "<<endl<<endl;
  23. for(i=0;i<m;i++)
  24. {
  25. for(j=0;j<n;j++)
  26. {
  27. cout<<a[i][j]<<" ";
  28. }
  29. cout<<endl<<endl;
  30. }
  31. getch();
  32. }

Write a program to Insert and Delete elemnt of an array


Size of array is taken from user.. Elements are Entered.. Array is shown.. user is prompted for adding another element.. new element is added at desired position.. user is prompted to delete an element.. Element is deleted from entered position..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<conio.h>
  2. #include<iostream.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[100],i,pos,num,item,size;
  7. cout<<"How many element: ";
  8. cin>>size;
  9. cout<<"Enter the elements of array: "<<endl;
  10. for(i=0;i<size;i++)
  11. cin>>a[i];
  12. cout<<endl;
  13. cout<<"Now Array is: "<<endl;
  14. for(i=0;i<size;i++)
  15. cout<<"Element at position "<<i+1<<" is "<<a[i]<<endl;
  16. cout<<endl<<"Press any key to add another element"<<endl<<endl;
  17. getch();
  18. //Coding by: Snehil Khanor
  19. //http://WapCPP.blogspot.com
  20. cout<<"Enter another element: ";
  21. cin>>num;
  22. cout<<"Enter position number: ";
  23. cin>>pos;
  24. cout<<endl;
  25. --pos;
  26. for(i=size;i>=pos;i--)
  27. a[i+1]=a[i];
  28. a[pos]=num;
  29. size++;
  30. cout<<"New Array: "<<endl;
  31. for(i=0;i<size;i++)
  32. cout<<"Element at position "<<i+1<<" is "<<a[i]<<endl;
  33. cout<<endl<<"Press any key to delete any element"<<endl<<endl;
  34. getch();
  35. //Coding by: Snehil Khanor
  36. //http://WapCPP.blogspot.com
  37. cout<<"Enter position number to delete: ";
  38. cin>>pos;
  39. --pos;
  40. item=a[pos];
  41. for(i=pos;i<size;i++)
  42. a[i]=a[i+1];
  43. size--;
  44. cout<<"Deleted element: "<<item<<endl;
  45. cout<<endl<<"New array: "<<endl;
  46. for(i=0;i<size;i++)
  47. cout<<"Element at position "<<i+1<<" is "<<a[i]<<endl;
  48. getch();
  49. }

Write a program to sort elements of array (bubble Sorting)


Size of array is taken from user.. Elemnts are entered by user.. Elements are sorted in ascending order..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<conio.h>
  2. #include<iostream.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[100],i,n,j,temp;
  7. cout<<"How many element: ";
  8. cin>>n;
  9. cout<<"Enter the elements of array: "<<endl;
  10. for(i=0;i<n;i++)
  11. cin>>a[i];
  12. cout<<"The elements of array Before Sorting: "<<endl;
  13. //Coding by: Snehil Khanor
  14. //http://WapCPP.blogspot.com
  15. for(i=0;i<n;i++)
  16. cout<<a[i]<<" ";
  17. cout<<endl;
  18. for(i=0;i<n;i++)
  19. {
  20. for(j=0;j<n-1-i;j++)
  21. {
  22. if(a[j]>a[j+1])
  23. {
  24. temp=a[j];
  25. a[j]=a[j+1];
  26. a[j+1]=temp;
  27. }
  28. }
  29. }
  30. cout<<"Elements of array After Sorting: "<<endl;
  31. for(i=0;i<n;i++)
  32. cout<<a[i]<<" ";
  33. getch();
  34. }

Write a program to search an element in an array (Binary searching)


Size of array is taken from user.. Elements are entered by user in order (ascending or descending).. user is asked for the element to be searched... Search is performed..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<conio.h>
  2. #include<iostream.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[100],i,loc,mid,beg,end,n,flag=0,item;
  7. cout<<"How many element: ";
  8. cin>>n;
  9. cout<<"Enter (IN ORDER) the elements of array: "<<endl;
  10. //Coding by: Snehil Khanor
  11. //http://WapCPP.blogspot.com
  12. for(i=0;i<n;i++)
  13. cin>>a[i];
  14. cout<<"Enter the element to be searched: ";
  15. cin>>item;
  16. loc=0;
  17. beg=0;
  18. end=n-1;
  19. while((beg<=end)&&(item!=a[mid]))
  20. {
  21. mid=(beg+end)/2;
  22. if(item==a[mid])
  23. {
  24. cout<<"Search successful :)";
  25. loc=mid;
  26. cout<<"Position of the Item: "<<loc+1;
  27. flag=flag+1;
  28. }
  29. else if(item<a[mid])
  30. end=mid-1;
  31. else
  32. beg=mid+1;
  33. }
  34. if(flag==0)
  35. {
  36. cout<<"Search NOT sucessfull :( ";
  37. }
  38. getch();
  39. }

Write a program to search an element in an array (Linear searching)


Size of array is taken from user.. Elements are entered.. Then user is asked to enter element to be searched.. Search is performed..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int ar[10],n,num,no;
  7. cout<<"Enter size of the array: ";
  8. cin>>n;
  9. cout<<"Enter array element: "<<endl;
  10. for(int i=0;i<n;i++)
  11. {
  12. cout<<"Enter element "<<i<<": ";
  13. cin>>ar[i];
  14. }
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. cout<<"Elements of array: "<<endl;
  18. for(i=0;i<n;i++)
  19. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  20. //////To search////
  21. cout<<"Enter number to search: ";
  22. cin>>num;
  23. for(i=0;i<n;i++)
  24. {
  25. if(num==ar[i])
  26. {
  27. cout<<"Found at index number: "<<i;
  28. no=0;
  29. break;
  30. }
  31. else
  32. {
  33. no=1;
  34. continue;
  35. }
  36. }
  37. if(no==1)
  38. cout<<"Sorry your search returned NO results. :(";
  39. getch();
  40. }

Write a program to find minimum in array


Size of array is taken from user..Elements are entered by user..Minimum of the elements is displayed..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int ar[10],n,min;
  7. cout<<"Enter size of the array: ";
  8. cin>>n;
  9. cout<<"Enter array element: "<<endl;
  10. for(int i=0;i<n;i++)
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. {
  14. cout<<"Enter element "<<i<<": ";
  15. cin>>ar[i];
  16. }
  17. cout<<"Elements of array: "<<endl;
  18. for(i=0;i<n;i++)
  19. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  20. ////To find MIN////
  21. min=ar[0];
  22. for(i=0;i<n;i++)
  23. {
  24. if(min>ar[i])
  25. min=ar[i];
  26. }
  27. cout<<"Minimum in the array is "<<min;
  28. getch();
  29. }

Write a program to find maximum in array


Size of array is taken from user..elements are entered by user..biggest ellement is displayed.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int ar[10],n,max;
  7. cout<<"Enter size of the array: ";
  8. cin>>n;
  9. cout<<"Enter array element: "<<endl;
  10. for(int i=0;i<n;i++)
  11. {
  12. cout<<"Enter element "<<i<<": ";
  13. cin>>ar[i];
  14. }
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. cout<<"Elements of array: "<<endl;
  18. for(i=0;i<n;i++)
  19. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  20. ////To find MAX////
  21. max=ar[0];
  22. for(i=0;i<n;i++)
  23. {
  24. if(max<ar[i])
  25. max=ar[i];
  26. }
  27. cout<<"Maximum in the array is "<<max;
  28. getch();
  29. }

Write a program to reverse elements of array


Size of array is taken from user..Elements are stored by user..Then reverse of array is displayed..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int ar[10],n,s=0;
  7. cout<<"Enter size of the array: ";
  8. cin>>n;
  9. cout<<"Enter array element: "<<endl;
  10. for(int i=0;i<n;i++)
  11. {
  12. cout<<"Enter element "<<i<<": ";
  13. cin>>ar[i];
  14. }
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. cout<<"Elements of array in original order: "<<endl;
  18. for(i=0;i<n;i++)
  19. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  20. cout<<"Elements of array in reverse order: "<<endl;
  21. for(i=n-1;i>=0;i--)
  22. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  23. getch();
  24. }

Write a program to find sum of array elements


Size of array is taken from user..Numbers are stored in the array.. and sum is determined of the elements of array..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int ar[10],n,s=0;
  7. cout<<"Enter size of the array: ";
  8. cin>>n;
  9. cout<<"Enter array element: "<<endl;
  10. for(int i=0;i<n;i++)
  11. {
  12. cout<<"Enter element "<<i<<": ";
  13. cin>>ar[i];
  14. }
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. cout<<"Elements of array: "<<endl;
  18. for(i=0;i<n;i++)
  19. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  20. ///For adding all elements///
  21. for(i=0;i<n;i++)
  22. s=s+ar[i];
  23. cout<<"Sum of elements: "<<s;
  24. getch();
  25. }

write a program to store n numbers to an array and display them


Size of array is taken from user as n. then n numbers are stored in array..Array is displayed as output.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int ar[10],n;
  7. cout<<"Enter size of the array: ";
  8. cin>>n;
  9. cout<<"Enter array element: "<<endl;
  10. for(int i=0;i<n;i++)
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. {
  14. cout<<"Enter element "<<i<<": ";
  15. cin>>ar[i];
  16. }
  17. cout<<"Elements of array: "<<endl;
  18. for(i=0;i<n;i++)
  19. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  20. getch();
  21. }

write a program to store and display 10 numbers in an array


10 numbers are first stored in array and then the array is displayed.
This should be your first array program.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int ar[10];
  7. cout<<"Enter array element: "<<endl;
  8. for(int i=0;i<10;i++)
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. {
  12. cout<<"Enter element "<<i<<": ";
  13. cin>>ar[i];
  14. }
  15. cout<<"Elements of array: "<<endl;
  16. for(i=0;i<10;i++)
  17. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  18. getch();
  19. }

write a program to calculate sum of all even numbers upto n


A number is taken from user and sum of all even numbers upto that number is calculated.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,sum=0;
  7. cout<<"Please enter a number: ";
  8. cin>>n;
  9. for (int i=1;i<=n;i++)
  10. //Coding by: Snehil Khanor
  11. //http://WapCPP.blogspot.com
  12. {
  13. if(i%2==0)
  14. sum=sum+i;
  15. else
  16. continue;
  17. }
  18. cout<<sum;
  19. getch();
  20. }

write a program to calculate sum of all odd numbers upto n


A number n is taken from user and sum of all odd numbers upto n is calculated.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,sum=0;
  7. cout<<"Please enter a number: ";
  8. cin>>n;
  9. for (int i=1;i<=n;i++)
  10. //Coding by: Snehil Khanor
  11. //http://WapCPP.blogspot.com
  12. {
  13. if(i%2!=0)
  14. sum=sum+i;
  15. else
  16. continue;
  17. }
  18. cout<<sum;
  19. getch();
  20. }

write a program to displat table of a number


A number is taken from user and its table upto n is displayed.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,m;
  7. cout<<"Please enter n: ";
  8. cin>>n;
  9. for (int i=1;i<=10;i++)
  10. //Coding by: Snehil Khanor
  11. //http://WapCPP.blogspot.com
  12. {
  13. m=n*i;
  14. cout<<n<<"*"<<i<<"="<<m<<endl;
  15. }
  16. getch();
  17. }

write a profram to calculate power of a number


A number and power to be calculated is taken from user.Power is calculated.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,x,y=1;
  7. cout<<"Please enter x: ";
  8. cin>>x;
  9. cout<<"Please enter n: ";
  10. cin>>n;
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. for (int i=1;i<=n;i++)
  14. y=y*x;
  15. cout<<y;
  16. getch();
  17. }

write a program to determine factorial of a number


A number is taken from user and its factorial is given.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,fac=1;
  7. cout<<"Please enter a number: ";
  8. cin>>n;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. for (int i=1;i<=n;i++)
  12. fac=fac*i;
  13. cout<<fac;
  14. getch();
  15. }

write a program to find sum of n numbers


A number n is taken from user.
Sum of all natural numbers upto n is displayed.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,sum=0;
  7. cout<<"Please enter a number: ";
  8. cin>>n;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. for (int i=1;i<=n;i++)
  12. sum=sum+i;
  13. cout<<sum;
  14. getch();
  15. }

write a program to check whether entered number is prime or not


Prime number: A natural number which has exactly two distinct natural number divisors: 1 and itself.

A number is taken from user and is checked whether prime number or not.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,m;
  7. cout<<"Please enter a number: ";
  8. cin>>n;
  9. for (int i=2;i<=(n-1);i++)
  10. {
  11. if(n%i==0)
  12. //Coding by: Snehil Khanor
  13. //http://WapCPP.blogspot.com
  14. {
  15. cout<<"Not a prime";
  16. break;
  17. }
  18. else
  19. {
  20. cout<<"Prime";
  21. break;
  22. }
  23. }
  24. getch();
  25. }

write a program to display fibonacci series upto n terms


Fibonacci series:The first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two
e.g.: 0 1 1 2 3 5 8 13 21 ....
A number n is taken from user and the series is displayed upto nth term.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a=0,b=1,c=0,n;
  7. cout<<"Enter the number of terms you wanna see: ";
  8. cin>>n;
  9. cout<<a<<" "<<b<<" ";
  10. for(int i=1;i<=n-2;i++)
  11. {
  12. c=a+b;
  13. a=b;
  14. b=c;
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. cout<<c<<" ";
  18. }
  19. getch();
  20. }

write a program to check whether entered number is palindrome or not


Palindrome :A word or phrase that reads the same backward as forward.

A number is taken from user and then checks if the entered number is palindrome or not.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. long int n,rev=0,m,num;
  7. cout<<"please enter a five digit no.: ";
  8. cin>>n;
  9. num=n;
  10. while(n>0)
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. {
  14. m=n%10;
  15. rev=rev*10+m;
  16. n=n/10;
  17. }
  18. cout<<rev<<endl;
  19. if (num==rev)
  20. cout<<"Number is a palindrome";
  21. else
  22. cout<<"Not a palindrome";
  23. getch();
  24. }

write a program to reverse digits of a number


A number is taken from the user number with reverse digits is displayed
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. long int n,rev=0,m;
  7. cout<<"please enter a five digit no.: ";
  8. cin>>n;
  9. while(n>0)
  10. //Coding by: Snehil Khanor
  11. //http://WapCPP.blogspot.com
  12. {
  13. m=n%10;
  14. rev=rev*10+m;
  15. n=n/10;
  16. }
  17. cout<<rev;
  18. getch();
  19. }

write a program to find sum of digits of a number


A number is taken from user and the sum of the digits is displayed.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,sum=0,m;
  7. cout<<"please enter a five digit no.: ";
  8. cin>>n;
  9. while(n>0)
  10. //Coding by: Snehil Khanor
  11. //http://WapCPP.blogspot.com
  12. {
  13. m=n%10;
  14. sum=sum+m;
  15. n=n/10;
  16. }
  17. cout<<sum;
  18. getch();
  19. }

write a program to diaplay a pyramid as shown:


The following output is obtained:
    1
   212
  32123
 4321234
543212345
543212345
 4321234
  32123
   212
    1
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. for (int i=1;i<=5;i++)
  7. {
  8. for(int j=4;j>=i;j--)
  9. cout<<" ";
  10. for(int k=1;k<=i;k++)
  11. cout<<k;
  12. for(k=i-1;k>=1;k--)
  13. cout<<k;
  14. cout<<"\n";
  15. }
  16. for (i=5;i>=1;i--)
  17. {
  18. for(int j=4;j>=i;j--)
  19. //Coding by: Snehil Khanor
  20. //http://WapCPP.blogspot.com
  21. cout<<" ";
  22. for(int k=1;k<=i;k++)
  23. cout<<k;
  24. for(k=i-1;k>=1;k--)
  25. cout<<k;
  26. cout<<"\n";
  27. }
  28. getch();
  29. }

write a program to diaplay a pyramid as shown:


Following output is displayed:
    1
   212
  32123
 4321234
543212345
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. for (int i=1;i<=5;i++)
  7. //Coding by: Snehil Khanor
  8. //http://WapCPP.blogspot.com
  9. {
  10. for(int j=4;j>=i;j--)
  11. cout<<" ";
  12. for(int k=1;k<=i;k++)
  13. cout<<k;
  14. for(k=i-1;k>=1;k--)
  15. cout<<k;
  16. cout<<"\n";
  17. }
  18. getch();
  19. }

write a program to diaplay a pyramid as shown:


The output is displayed as follows:
1
22
333
4444
55555
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. for (int i=1;i<=5;i++)
  7. {
  8. for(int j=1;j<=i;j++)
  9. cout<<i;
  10. cout<<"\n";
  11. }
  12. getch();
  13. }

write a program to diaplay a pyramid as shown:


The following output is displayed:
1
12
123
1234
12345
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. for (int i=1;i<=5;i++)
  7. {
  8. for(int j=1;j<=i;j++)
  9. cout<<j;
  10. cout<<"\n";
  11. }
  12. getch();
  13. }

write a program to diaplay a pyramid as shown:


Following output is obtained:
****
***
**
*
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. for(int i=1;i<=4;i++)
  7. { for(int j=4;j>=i;j--)
  8. cout<<"*";
  9. cout<<"\n";
  10. }
  11. getch();
  12. }

write a program to diaplay a pyramid as shown:


Following output is obtained:
*
**
***
****
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. for(int i=1;i<=4;i++)
  7. { for(int j=1;j<=i;j++)
  8. cout<<"*";
  9. cout<<"\n";
  10. }
  11. getch();
  12. }

write a program to display numbers from 10 to 1


numbers from 10 to 1 are displayed...
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. for(int i=10;i>0;i--)
  7. //Coding by: Snehil Khanor
  8. //http://WapCPP.blogspot.com
  9. { cout<<i;
  10. cout<<"\n";
  11. }
  12. getch();
  13. }

write a program to display numbers upto even numbers upto 50


Even numbers upto 50 are displayed.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. for(int i=1;i<=50;i++)
  7. //Coding by: Snehil Khanor
  8. //http://WapCPP.blogspot.com
  9. {if(i%2==0)
  10. cout<<i;
  11. cout<<"\n";
  12. }
  13. getch();
  14. }

write a program to display numbers upto n


A number n is taken from the user and then numbers from 1 to n is displayed.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int lim;
  7. cout<<"Please enter Limit: ";
  8. cin>>lim;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. for(int i=1;i<=lim;i++)
  12. { cout<<i;
  13. cout<<"\n";
  14. }
  15. getch();
  16. }

Write a program to make a simple calculator


Two numbers are entered and operation (sum,differnce,multiply,divide) to be performed is asked by the user. result is given according to the operation entered by user. (+,-,*,/)
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int s;
  7. float a,b,r;
  8. char op;
  9. cout<<"Please Enter a no.: ";
  10. cin>>a;
  11. cout<<"Please Enter operation to be performed.:(+,-,*,/,%) ";
  12. cin>>op;
  13. cout<<"Please Enter another no.: ";
  14. cin>>b;
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. switch (op)
  18. {
  19. case '+':
  20. r=a+b;
  21. break;
  22. case '-':
  23. r=a-b;
  24. break;
  25. case '*':
  26. r=a*b;
  27. break;
  28. case '/':
  29. r=a/b;
  30. break;
  31. default:
  32. cout<<"Please enter Correct operation :)";
  33. s=0;
  34. }
  35. if(s)
  36. cout<<a<<op<<b<<"="<<r;
  37. getch();
  38. }

Write a program to determine whether a number is even or odd


A number is taken from user and determined weather even or odd.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n;
  7. cout<<"Enter no.: ";
  8. cin>>n;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. if(n%2==0)
  12. cout<<"EVEN";
  13. else
  14. cout<<"ODD";
  15. getch();
  16. }

write a program to determine whether a number is positive or negative


A number is taken from user and then determined weather it is positive or negative.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n;
  7. cout<<"Enter no.: ";
  8. cin>>n;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. if(n>0)
  12. cout<<"+ve";
  13. else
  14. cout<<"-ve";
  15. getch();
  16. }

write a program to swap two numbers without using third variable


Two numbers are taken from user and then swapped without using a third variable.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b;
  7. cout<<"Enter a: ";
  8. cin>>a;
  9. cout<<"Enter b: ";
  10. cin>>b;
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. cout<<"Before swapping:"<<endl;
  14. cout<<"a: "<<a<<" b: "<<b<<endl;
  15. a=a+b;
  16. b=a-b;
  17. a=a-b;
  18. cout<<"After swapping:"<<endl;
  19. cout<<"a: "<<a<<" b: "<<b;
  20. getch();
  21. }

write a program to swap two numbers using a third variable


Two numbers are taken from the user and then swapped using a third variable.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b,c;
  7. cout<<"Enter a: ";
  8. cin>>a;
  9. cout<<"Enter b: ";
  10. cin>>b;
  11. cout<<"Before swapping:"<<endl;
  12. cout<<"a: "<<a<<" b: "<<b<<endl;
  13. //Coding by: Snehil Khanor
  14. //http://WapCPP.blogspot.com
  15. c=a;
  16. a=b;
  17. b=c;
  18. cout<<"After swapping:"<<endl;
  19. cout<<"a: "<<a<<" b: "<<b;
  20. getch();
  21. }

write a program to find greatest of two numbers


Two numbers are taken from user and greatest of two is determined.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b;
  7. cout<<"Please enter two nos. ";
  8. cin>>a>>b;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. if (a>b)
  12. cout<<"a is greatest";
  13. else
  14. cout<<"b is greatest";
  15. getch();
  16. }

Write a program to store consumer number and number of calls and calculate telephone bill accordin to condition


Take Customer number and no. of calls from user.
Calculate Bill as follows..
If number of calls <=100 : Free
Number of calls >=200 <=300 : 1.40 per call on over 100
Number of calls >=300 <=400 : 140+1.60 per call on over 200
Number of calls >=300 <=400 : 300+1.80 per call on over 300
Number of calls >=400 : 480+2.10 per call on over 400
And Fixed monthly rental: RS 100
And generate bill.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. float id,qty,tot,amt;
  7. cout<<"Enter Customer No.: ";
  8. cin>>id;
  9. cout<<"Please Enter No. of Calls: ";
  10. cin>>qty;
  11. if(qty<=100)
  12. amt=0;
  13. else if(qty>100&&qty<=200)
  14. amt=1.40*(qty-100);
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. else if(qty>200&&qty<=300)
  18. amt=140+1.60*(qty-200);
  19. else if(qty>300&&qty<=400)
  20. amt=300+1.80*(qty-300);
  21. else
  22. amt=480+2.10*(qty-400);
  23. tot=100+amt;
  24. cout<<"\n\n\nCustomer NO.: "<<id<<"\nNo. of Calls: "<<qty<<"\nMonthly Rental:
  25. INR 100\nTotal amt: INR "<<tot;
  26. getch();
  27. }

Write a program to store product number, price of each item, & quantity and calculate total ammount, then find disocunt at 30% and Generate bill


Product number, price of each item and quantity are taken from the user and dicount and net ammount is calculated.
Bill is Displayed as follows:
Product ID:
Quantity:
Total ammount:
Discount:
Net ammount:
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int id,qty;
  7. float tot,amt,price,dis;
  8. cout<<"Enter Product ID: ";
  9. cin>>id;
  10. cout<<"Please Enter Quantity: ";
  11. cin>>qty;
  12. cout<<"Please Enter Price per ITEM: INR ";
  13. cin>>price;
  14. tot=qty*price;
  15. dis=.3*tot;
  16. amt=tot-dis;
  17. //Coding by: Snehil Khanor
  18. //http://WapCPP.blogspot.com
  19. cout<<"\n\n\nProduct ID: "<<id<<"\nQuantity: "<<qty<<"\nPrice Per ITEM: INR
  20. "<<price<<"\nTotal amt: INR "<<tot<<"\nDiscount @ 30% : INR "<<dis<<"\nNet
  21. Ammount: INR "<<amt;
  22. getch();
  23. }

Write a program to store product ID and sales ammount and calculate discount accordin to condition and calculate net ammount


Take Product ID and Sales ammount from user.
Calculated Discount ammount according to condition:
If amt < 5000 then discount = 20%
If ammount >= 5000 And <= 10000 then discount = 30%
otherwise discount= 40%
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. float id,amt,pd,d,net;
  7. cout<<"Please enter product ID: ";
  8. cin>>id;
  9. cout<<"Please enter Sales ammount: ";
  10. cin>>amt;
  11. if (amt<5000)
  12. d=.2*amt;
  13. else if (amt>=5000 && amt<=10000)
  14. d=.3*amt;
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. else
  18. d=.4*amt;
  19. net=amt-d;
  20. cout<<"Discount= "<<d;
  21. cout<<"\nNet ammount= "<<net;
  22. getch();
  23. }

Write a program to find greatest of three numbers


Three numbers are taken from user and greatest number is displayed.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b,c;
  7. cout<<"Please enter three nos. ";
  8. cin>>a>>b>>c;
  9. if (a>b)
  10. {
  11. if (a>c)
  12. cout<<"a is largest";
  13. else
  14. cout<<"c is largest";
  15. }
  16. //Coding by: Snehil Khanor
  17. //http://WapCPP.blogspot.com
  18. else if (b>c)
  19. cout<<"b is largest";
  20. else
  21. cout<<"c is largest";
  22. getch();
  23. }

Write a program to display seconds as Minutes and Hours and days


write a program that asks the user to enter a number of seconds. obeying the following conditions:
1. there are 60 seconds in a minute. if the number of seconds entered by the is greater than or equal to 60, the program should display the number of minutes in that many seconds.
2. there are 3600 seconds in an hour. if the number of seconds entered by a user is greater than or equal to 3600, the program should display the number of hours in that many seconds.
3. there are 86400 seconds in a day, if the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds,
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. float secs,mins,hours,days;
  7. cout<<"Enter no. of seconds: ";
  8. cin>>secs;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. mins=secs/60;
  12. hours=secs/3600;
  13. days=secs/86400;
  14. if (secs>=60 && secs<3600)
  15. cout<<"No. of Minutes= "<<mins;
  16. else if (secs>=3600 && secs<86400)
  17. cout<<"No. of Hours= "<<hours;
  18. else if (secs>=86400)
  19. cout<<"No. of Days= "<<days;
  20. else
  21. cout<<"No.of seconds= "<<secs;
  22. getch();
  23. }

Write a program to insert number of days from user and calculate number of weeks and remaining days


Number of days is taken from user and number of weeks and remaining days are given as output.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,d,w;
  7. cout<<"enter Number of days u have:. ";
  8. cin>>n;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. w=n/7;
  12. d=n%7;
  13. cout<<"No.of weeks= "<<w;
  14. cout<<"\nno. of days= "<<d;
  15. getch();
  16. }

Write a program to calculate sum of two numbers


Two numbers are taken from the user and sum is calculated.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. float a,b,s;
  7. cout<<"Please enter a no.: ";
  8. cin>>a;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. cout<<"Please enter another no.: ";
  12. cin>>b;
  13. s=a+b;
  14. cout<<"The sum is: "<<s;
  15. getch();
  16. }

Write a program to display the input


This is an ideal first program for learning "cin"
Two numbers are taken from the user and then displayed as output.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b;
  7. cout<<"enter first no. ";
  8. cin>>a;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. cout<<"enter second no. ";
  12. cin>>b;
  13. cout<<"First no. is "<<a;
  14. cout<<"\nSecond no.is "<<b;
  15. getch();
  16. }

Write a program to output a messege (without description)


If the Previous post scares you.. then heres the code without description.. :)
This is an ideal first program.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. //Coding by: Snehil Khanor
  7. //http://WapCPP.blogspot.com
  8. cout<<"Hello India";
  9. cout<<"\nThis is my first C++ programme";
  10. getch();
  11. }

Write a program to output a messege


This is an ideal First C++ (CPP) program.
All necessary things are described with in the program in comments.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h> //These are the Header files and are essential..
  2. #include <conio.h> // They varies program to program.
  3. void main() //This is a special type of function.Program starts and ends in MAIN.
  4. {
  5. //Coding by: Snehil Khanor
  6. //http://WapCPP.blogspot.com
  7. clrscr(); //This clears previous outputs from the output screen
  8. cout<<"Hello India"; //This is responsible for diplaying a messege
  9. cout<<"\nThis is my first C++ programme";
  10. getch(); //This helps to sustain the output on Screen.
  11. }

Write a program to find Simple interest


Principal ammount, rate of Interest and time period is Taken from user and Simple Interest is calculated.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. float p,r,t,f,s=0;
  7. cout<<"Please enter Principle ammount ";
  8. cin>>p;
  9. //Coding by: Snehil Khanor
  10. //http://WapCPP.blogspot.com
  11. cout<<"Please enter rate of Interest. ";
  12. cin>>r;
  13. cout<<"Please enter Time Period ";
  14. cin>>t;
  15. f=p*r*t;
  16. s=f/100;
  17. cout<<"The Simple iterest is "<<s;
  18. getch();
  19. }

Write a program to find average of three numbers


Three numbers are taken(Input) from the user and avg of these three nos. is calculated(Output).
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b,c,d,avg;
  7. cout<<"enter a no. ";
  8. cin>>a;
  9. cout<<"enter another no. ";
  10. cin>>b;
  11. cout<<"enter another nos ";
  12. cin>>c;
  13. //Coding by: Snehil Khanor
  14. //http://WapCPP.blogspot.com
  15. d=a+b;
  16. avg=d/3;
  17. cout<<"The average is "<<s;
  18. getch();
  19. }

Write a program to find area of a circle


Radius of circle is taken from user and Area is calculated
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. float r,a;
  7. cout<<"enter radius ";
  8. //Coding by: Snehil Khanor
  9. //http://WapCPP.blogspot.com
  10. cin>>r;
  11. a=3.14*r*r;
  12. cout<<"The area is "<<a;
  13. getch();
  14. }

Write a program to convert temperature in Celcius to temperature in Fahrenheit


Temperature is taken as input in celcius by user and then converted into Fahrenheit and displayed as output
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. //Coding by: Snehil Khanor
  7. //http://WapCPP.blogspot.com
  8. int c,f;
  9. cout<<"enter temperature in celcius:. ";
  10. cin>>c;
  11. f=1.8*c+32;
  12. cout<<"Temperatur in Farenheit= "<<f;
  13. getch();
  14. }

Search

About WAP C++

Here you'll find a wide range of programs' solution ranging from beginer level to advanced level.
All programs here are made, compiled and tested by me..and are running absolutely fine.. still if you find any bug in any program do let me know :)

Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner

my Binary Log

Blog Archive



eXTReMe Tracker