#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char ch[200];
void print() {
printf("\nEnter the message: ");
gets(ch);
}
void ntime() {
int n, i;
n = strlen(ch);
printf("The above message is printed %d times below:", n);
for (i = 0; i < n; i++)
printf("\n%s", ch);
printf("\n");
}
void revo() {
printf("The message in reverse order is: ");
printf("%s\n", strrev(ch));
}
void change() {
int i, j;
i = strlen(ch);
for (j = 0; j < i; j++) {
if (ch[j] >= 'a' && ch[j] <= 'z')
ch[j] -= 32;
else if (ch[j] >= 'A' && ch[j] <= 'Z')
ch[j] += 32;
else
continue;
}
puts(ch);
}
void block() {
int i, j, n;
n = strlen(ch);
printf("The given message in block staircase pattern is: \n");
for (i = 0; i < n; i++) {
for (j = 0; j <= i; j++)
printf("%c", ch[j]);
printf("\n");
}
printf("\n");
}
void main() {
int a;
while (1) {
printf("\nMENU");
printf("\n1.Print message no. of time as per its length");
printf("\n2.Print the message in reverse order");
printf("\n3.Print the message in block staircase pattern");
printf("n4.Print the message in capital letters and vice versa");
printf("\n5.Exit from program");
printf("\n\nEnter your choice: ");
scanf("%d", &a);
switch (a) {
case 1:
ntime();
break;
case 2:
revo();
break;
case 3:
block();
break;
case 4:
change();
break;
case 5:
exit(1);
default:
printf("Invalid choice\n");
}
}
}
WHAT'S NEW?
Loading...
Showing posts with label C Menu Program. Show all posts
Showing posts with label C Menu Program. Show all posts
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void lucky();
float ctof();
float sqr();
long int fact();
int a;
void main() {
int ch;
while (1) {
printf("\nMENU");
printf("\n1.%cC to %cF conversion\n2.Square root of a number");
printf("\n3.10 Lucky numbers between two numbers");
printf("\n4.Factorial of given number");
printf("\n9.Abandon the program",248,248);
printf("\n\nEnter your choice: ");
scanf("%d", &ch);
switch (ch) {
case 1:
printf("Temp in %cF is: %.2f\n", 248, ctof());
break;
case 2:
printf("Square root of the number is: %.2f\n", sqr());
break;
case 3:
lucky();
break;
case 4:
printf("Factorial of %d! is: %ld\n", a, fact());
break;
case 9:
exit(1);
default:
printf("Invalid choice\n");
}
}
}
float ctof() {
float fah;
float cel;
printf("Enter temp in %cC: ", 248);
scanf("%f", &cel);
fah = (9 * cel + 160) / 5;
return (fah);
}
float sqr() {
float sqr, no;
printf("Enter the number: ");
scanf("%f", &no);
sqr = sqrt(no);
return (sqr);
}
long int fact() {
int i;
long int pro = 1;
printf("Enter the number: ");
scanf("%d", &a);
for (i = 0; (a - i) > 0; i++)
pro = pro * (a - i);
return (pro);
}
void lucky() {
int b, c, i;
printf("Enter the two numbers: \n");
scanf("%d%d", &a, &b);
printf("\n10 Lucky numbers between %d and %d are: \n", a, b);
for (i = 0; i < 10;) {
c = rand();
if ((c > a && c < b) || (c > b && c < a)) {
printf("%-5d", c);
i++;
}
}
printf("\n");
}
#include<stdio.h>
#include<stdlib.h>
void threeno();
int sumno(int);
int sumos(int);
int pro(int);
int a, b, c;
void main() {
int ch, x;
while (1) {
printf("\nMENU");
printf("\n1.Input three numbers");
printf("\n2.Summation of the numbers\n3.Sum of squares");
printf("\n4.Product of the three numbers");
printf("\n5.Exit from program");
printf("\n\nEnter your choice: ");
scanf("%d", &ch);
switch (ch) {
case 1:
threeno();
break;
case 2:
printf("Summation of the numbers is: %d\n", sumno(x));
break;
case 3:
printf("Sum of squares is: %d\n", sumos(x));
break;
case 4:
printf("Product of the numbers is: %d\n", pro(x));
break;
case 5:
exit(1);
default:
printf("Invalid choice\n");
}
}
}
void threeno() {
printf("Enter the three numbers: \n");
scanf("%d%d%d", &a, &b, &c);
}
int sumno(int sum) {
threeno();
sum = a + b + c;
return (sum);
}
int sumos(int sum) {
threeno();
sum = a * a + b * b + c * c;
return (sum);
}
int pro(int pro) {
threeno();
pro = a * b * c;
return (pro);
}
/*A menu program to check if the given number is odd or even, to find the sum of N natural numbers and to find the sum of squares of two numbers*/
#include<stdio.h>
#include<stdlib.h>
void main() {
int ch;
char y;
int n, a, sum = 0;
while (1) {
printf("\nMENU");
printf("\n1.To check if the given no is odd or even");
printf("\n2.To find the sum of N numbers");
printf("\n3.To find the sum of squares of two numbers");
printf("\n4.Exit from Program");
printf("\nEnter the choice: ");
scanf("%d", &ch);
switch (ch) {
case 1:
printf("\nEnter the no. ");
scanf("%d", &n);
if ((n % 2) == 0)
printf("\nIt is even");
else
printf("\nIt is odd");
break;
case 2:
printf("\nEnter the value of N: ");
scanf("%d", &n);
for (a = 1; a <= n; a++)
sum = sum + a;
printf("\nSum= %d", sum);
break;
case 3:
printf("\nEnter the two numbers: ");
scanf("%d,%d", &a, &n);
sum = a * a + n * n;
printf("\nSum of squares is: %d", sum);
break;
case 4:
exit(1);
default:
printf("\nInvalid choice");
}
}
}