Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include<iostream>
  2. #include <stdio.h>
  3. #include<string>
  4. using namespace std;
  5.  
  6. void main()
  7. {
  8.     char names[10][30];
  9.     cout<<"plz enter ten names each of names to most 30 charcter"<<endl;
  10.     for(int i=0;i<10;i++)
  11.     {
  12.    
  13.     cin>>names[i];
  14.  
  15.     }
  16.     char appe[1000] ={};
  17.     for(int i=0;i<10;i++)
  18.     {
  19.     strcat(appe,names[i]);
  20.         strcat(appe," ");
  21.    
  22.     }
  23.     cout<<appe<<endl;
  24.  
  25.     int sum=0;
  26.   for(int i=0;i<10;i++)    
  27.     sum+=strlen(names[i]);
  28.   cout<<"the averge length for these name is : "<<sum/10.0<<endl;
  29.   cout << "the alphabetical sort of these name is :  " ;
  30.  char temp[30];
  31.    
  32.     int i,t;
  33.     for( i=0;i<10;i++)    
  34.     {
  35.        
  36.     for( t=i+1;t<10;t++)    
  37.     if (strcmp(names[i],names[t])>0)
  38.     {  
  39.     strcpy(temp,names[i]);
  40.     strcpy(names[i],names[t]);
  41.     strcpy(names[t],temp);}
  42.     }
  43.     cout<<"The alphabetical order of the words is :"<<endl;
  44.     for(int i=0;i<10;i++)
  45.         cout<<names[i]<<endl;
  46.  
  47.     //
  48.  
  49.     //
  50.         for( i=0;i<10;i++)    
  51.     {
  52.        
  53.     for( t=i+1;t<10;t++)    
  54.     if (strlen(names[i])>strlen(names[t]))
  55.     {  
  56.     strcpy(temp,names[i]);
  57.     strcpy(names[i],names[t]);
  58.     strcpy(names[t],temp);}
  59.     }
  60.     cout<<"The words order accodring to length is :"<<endl;
  61.     for(int i=0;i<10;i++)
  62.         cout<<names[i]<<endl;
  63.  
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement