Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3.  
  4. void main() {  
  5.     char str[256]="I love to eat apples all day\0";
  6.     int num=0, k=0, counter=0;
  7.     scanf("%d", &num);
  8.     while (str[k] != '\0') {
  9.         k++;
  10.     }
  11.     if (num <= k) {
  12.         if (str[num] == ' ') {
  13.             printf("This is not the word");
  14.             system("pause");
  15.             return;
  16.         }
  17.         for (int i = 0; i < num; i++) {
  18.             if (str[i] == ' ')
  19.                 counter++;
  20.         }
  21.     }
  22.     else {
  23.         printf("Write number under %d\n", k);
  24.         main();
  25.     }
  26.     switch (counter) {
  27.     case 0:
  28.         printf("It's 1st word");
  29.         break;
  30.     case 1:
  31.         printf("It's 2nd word");
  32.         break;
  33.     case 2:
  34.         printf("It's 3rd word");
  35.         break;
  36.     default:
  37.         counter++;
  38.         printf("It's %dth word\n", counter);
  39.         break;
  40.     }
  41.     system("pause");
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement