Your SlideShare is downloading. ×
Cs project
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Cs project

313

Published on

Contains some of the basic programs of C++ Programming Language.

Contains some of the basic programs of C++ Programming Language.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
313
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 1. Write a program to accept three integers and print the largest of them?#include<iostream.h>#include<conio.h>void main(){clrscr();int a,b,c;cout<<“Enter three numbers ”;cin>>a>>b>>c;if(a>b && a>c)cout<<a;else if(b>a && b>c)cout<<b;else if(c>a && c>b)cout<<c;getch();}
  • 2. 2. Write a program to input a character and check whether a given character is in alphabet or adigit or any other special character.#include<iostream.h>#include<conio.h>void main(){clrscr();char a;cout<<“Enter a character ”;cin>>a;if(a>= && a<=)cout<<“You have entered a lowercase alphabet”;else if(a>= && a<= )cout<<“You have entered an uppercase alphabet”;else if(a>= && a<=)cout<<“You have entered a digit”;elsecout<<“You have entered a special character”;getch();}
  • 3. 3. Write a program to print first ten natural numbers and their sum.#include<iostream.h>#include<conio.h>void main(){clrscr();int a,b=0;for(a=1;a<=10;a++){cout<<a<<endl;b+=a;}cout<<“Summation ”<<b;getch();}
  • 4. 4. Write a program to print the following series.0 1 1 2 3 5 8 13#include<iostream.h>#include<conio.h>void main(){clrscr();unsigned long first, second, third, n;first=0;second=1;cout<<“How many elements you want to enter ”<<endl;cin>>n;cout<<first<<endl;for(int i=2; i<n; i++){third=first+second;cout<<third;first=second;second=third;}getch();}
  • 5. 5. Write a program to check whether a given number is palindrome or not.#include<iostream.h>#include<conio.h>void main(){int n, num, digit, rev=0;cout<<“Enter any number ”;cin>>num;n=num;do{digit=num%10;rev=(rev*10)+digit;num=num/10;}while(num!=10)cout<<“The reverse of the number is ”<<rev;if(n==rev)cout<<“The number is a Palindrome”;elsecout<<“The number is not a Palindrome”;getch();}
  • 6. 6. Write a program to accept the marks of ten students and store them in an array. Also display thetotal marks.#include<iostream.h>#include<conio.h>void main(){int n, a[10], t=0;for(n=1;n<=10;n++){cout<<“Enter the marks of student ”<<n<<endl;cin>>a[n];t=t+a[n];}cout<<“The total of the marks is ”<<t;getch();}
  • 7. 7. Write a program to search for a specific element in a 1-D array through linear search.#include<iostream.h>#include<conio.h>void main(){clrscr();int a[5], size, i, flag=0, num, pos;cout<<“Enter the number of elements in an array ”;cin>>size;cout<<“Enter the elements of the array ”;for(i=0;i<size;i++){cin>>a[i];}cout<<“Enter the element to be searched ”;cin>>num;for(i=0;i<size;i++)if(a[i]==num){flag=1;pos=i;break;}if(flag==0){cout<<“Element not found!”;}else{cout<<“Element found at position ”<<pos+1;}getch();}
  • 8. 8. Write a program to find the number of vowels in a given line of text using an array.#include<iostream.h>#include<conio.h>#include<stdio.h>void main(){clrscr();char line[100];int vow=0;cout<<“Enter a sentence ”<<endl;gets(line) ;for(int i=0 ; line[i] !=‘0’;i++){switch(line[i]){case ‘a’;case ‘A’;case ‘e’;case ‘E’;case ‘I’;case ‘I’;case ‘o’;case ‘O’;case ‘u’;case ‘U’;vow++;}}cout<<“Total number of vowels in the given line is ”<<vow;getch();}
  • 9. 9. An array emp[20] contains the number of employees joined in different years. Write aprogram to find out the number of year in which no employee joined.#include<iostream.h>#include<conio.h>void main(){clrscr();int emp[20], number_of_year=0;cout<<“Enter the number of employees who joined in ”;for(i=0;i<20;i++){cout<<“Year is ”<<i+1<<endl;cin>>emp[20];if(emp[i]==0)number_of_year=number_of_year+1;}cout<<“In ”<<number_of_year<<“ year number of employees joined”;getch();}
  • 10. 10. Write a program to calculate the length of string without using a library function.#include<iostream.h>#include<conio.h>void main(){clrscr();char str[20];int a;for(a=1; a<=20;a++){cin>>str[a];}cout<<“Length of string is ”<<a;getch();}
  • 11. 11. Write a program that checks whether the given character is alphanumeric or a digit by usingstandard library function.#include<iostream.h>#include<conio.h>#include<string.h>#include<stdlib.h>void main(){char ch;int a;cout<<“Enter a character ”;cin>>ch;a=ch;if(isalnum(a)){cout<<“Alphanumeric Character”;}else if(isalpha(a)){cout<<“Alphabetic Character”;}else if(isdigit(a)){cout<<“Numeric Character”;}elsecout<<“Other Character”;getch();}
  • 12. 12. Write a program to swap two values and make a new program.#include<iostream.h>#include<conio.h>void main(){clrscr();void swap(int &, int &)int a, b;cout<<“Enter the first number ”;cin>>a;cout<<“Enter the second number ”;cin>>b;swap(a, b);cout<<“After swapping the values are ”<<a<<b;getch();}void swap(int &x, int &y){int z;z=x;x=y;y=z;cout<<“The swapped values are ”<<x<<y;}
  • 13. 13. Write a program to generate the following output:#include<iostream.h>#include<conio.h>void main(){int a, b;for(a=1;a<=5;a++){for(b=1;b<=a;b++){cout<<“* ”;}cout<<endl;}getch();}** ** * ** * * ** * * * *
  • 14. 14. Write a function that finds a sub-string from a given string and returns the string to its callerfunction.#include<iostream.h>#include<conio.h>void main(){
  • 15. 15. Write a program that generates the following output:#include<iostream.h>#include<conio.h>void main(){int a, b, c, d;for(a=1;a<=4;a++){for(b=1;b<=a;b++){cout<<“* ”;}cout<<endl;}for(c=1;c<=3;c++){for(d=3;d>=c;d‒‒){cout<<“* ”;}cout<<endl;}getch();}** ** * ** * * ** * ** **

×