Recursion is used on large problems that can be broken down into smaller, repetitive problems. It is especially implement on branches and large or complex iterative approach.
Write a Code for C Program to Convert lower case to upper case: Code: #include<stdio.h> #include<string.h> void main() { int i; char s[100]; printf("Enter a string:\n"); gets(s); for(i=0;s[i];i++) { if(s[i]>='a' && s[i]<='z') s[i]=s[i]-32; } printf("%s\n",s); } Output:
WHAT IS LOOP : Loops are used to execute a piece of code several time according to the condition give to the loop. It means it execute same code multiple times so it saves code and also helps to traverse the elements of array. There are three types of loops in C language. They are : FOR loop. WHILE loop. DO WHILE loop. 1. FOR loop : Syntax : for(initialization;condition;increment/decrement) { ..... ...... ...... ...... // CODES ..... ..... ..... } Here is an example how FOR loop works : #include<stdio.h> void main() { for(int i=1;i<=10;i++) { printf("\n %d",i); } } Output : 2. WHILE loop : Syntax : while(condition) { ...... ...... ...... //code ...... ..... } Here is an example how WHILE loop works : #include<stdio.h> void main() { int i=1; while(i<=10) { printf...
Recursion is used on large problems that can be broken down into smaller, repetitive problems. It is especially implement on branches and large or complex iterative approach.
ReplyDelete