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
How will you declare an array of three function pointers where each function receives two ints and returns a float?
What is calloc malloc realloc in c?
What is putchar() function?
What does the c preprocessor do?
What are actual arguments?
What is the difference between declaring a variable and defining a variable?
What is substring in c?
What is break statement?
What do you mean by recursion in c?
what do u mean by Direct access files? then can u explain about Direct Access Files?
What do you mean by keywords in c?
In a switch statement, what will happen if a break statement is omitted?
what is the different bitween abap and abap-hr?
How do I convert a string to all upper or lower case?
What is the explanation for cyclic nature of data types in c?