Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- void main() {
- char str[256]="I love to eat apples all day\0";
- int num=0, k=0, counter=0;
- scanf("%d", &num);
- while (str[k] != '\0') {
- k++;
- }
- if (num <= k) {
- if (str[num] == ' ') {
- printf("This is not the word");
- system("pause");
- return;
- }
- for (int i = 0; i < num; i++) {
- if (str[i] == ' ')
- counter++;
- }
- }
- else {
- printf("Write number under %d\n", k);
- main();
- }
- switch (counter) {
- case 0:
- printf("It's 1st word");
- break;
- case 1:
- printf("It's 2nd word");
- break;
- case 2:
- printf("It's 3rd word");
- break;
- default:
- counter++;
- printf("It's %dth word\n", counter);
- break;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement