Answer:
- Use the one that reads most clearly.
- If you can’t decide, just pick one.
- If you can’t then use for()
- If at any point later in time you change your mind, refactor your code.
This is how professionals work. Decide, and for all things with low impact to change, don’t sweat it.
Save that for architectural and API design choices.
Answer#2:
- Well if you are looking for a simple technique to choose which loop to use you can use these rules.
- Use for loops when there's a sequence of elements that you want to iterate.
- Use while loops when you want to repeat an action until a condition changes.
And if whatever you are trying to do can be done with either for or while loops then just choose your favourite :)
Answer:
#include <stdio.h>
#include <ctype.h>
int main(void) {
char data[50];
int i;
printf("Enter data: ");
scanf("%s", data);
for (i = 0; data[i] != '\0'; ++i){
if(isdigit(data[i]) == 0){
printf("\nno");
return 0;
}
}
printf("\nyes");
return 0;
}
Explanation:
Step 1 : Define variables and libraries
char data[50];
int i;
#include <stdio.h>
#include <ctype.h>
Step 2: Read the data and asign to variable:
printf("Enter data: ");
scanf("%s", data);
Step 3: Loop over the data :
for (i = 0; data[i] != '\0'; ++i)
Step 4: Validate if the element is digit:
if(isdigit(data[i]) == 0)
Step 5: If the element is not digit print no and finish the program:
if(isdigit(data[i]) == 0){
printf("\nno");
return 0;
}
Step 6: If all elements are digits print yes and finish the program:
printf("\nyes");
return 0;
Answer:Virtual memory
Explanation: Virtual memory is the essential part of the operating system as it provides the space for the execution of the other application. It is not a actual memory and is rather considered as the simulated memory.It works on the hard drive parts and can replicate the RAM in the hard drive space by the operating system. Virtual memory indirectly helps the RAM to increase the memory size.