Write a c program using for loop in switch case?

Answer Posted / mmm

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
int code;
clrscr();
printf("menu\n");
printf("\npress 1 for positive numbers");
printf("\npress 2 for negitive numbers");
printf("enter code(1or2)");
scanf("%d",&code);
switch(code)
{
case 1: printf("\nfirst 10 positive numbers:");
for(i=0;i<10;i++)
printf("%d\n",i);
break;
case 2: printf("\nfirst 10 negative numbers:");
for(i=0;i<10;i++)
printf("-%d\n",i);
break;
default:printf("invalid code");
}
// printf("do you want to continue:yes or no");

getch();
}

Is This Answer Correct ?    41 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how do you list a file’s date and time?

615


What are the features of c languages?

624


Write a program to print ASCII code for a given digit.

681


Write a program to print fibonacci series using recursion?

581


What is the use of getch ()?

629






why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1514


What is void main ()?

605


What is a double c?

586


What is the difference between a string and an array?

703


What is storage class?

654


Explain what is the advantage of a random access file?

659


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

613


What does %c mean in c?

643


What are the rules for the identifier?

667


What happens if header file is included twice?

650