Wednesday, 23 July 2014
Monday, 21 July 2014
Write a program to generate a following numbers triangle.
(Where user entered number through keyboard, for example if num=5)
54321
4321
321
21
1
Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(; num>=1; num--)
{
for(c=num; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
getch();
return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5
************************************/
/*************OUTPUT****************
Enter loop repeat number(rows): 5
54321
4321
321
21
1
************************************/
Write a program to generate a following numbers triangle:
(Where user entered number through keyboard, for example if num=5).
1 | ||||
1 | 2 | |||
1 | 2 | 3 | ||
1 | 2 | 3 | 4 | |
1 | 2 | 3 | 4 | 5 |
Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c,sp;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("%d",c);
printf("\n");
}
getch();
getch();
return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5
************************************/
/*************OUTPUT****************
Enter loop repeat number(rows): 5
1 | ||||
1 | 2 | |||
1 | 2 | 3 | ||
1 | 2 | 3 | 4 | |
1 | 2 | 3 | 4 | 5 |
************************************/
Write a program to generate a following numbers triangle:
Where user entered number through keyboard, for example if num=5)
12345
1234
123
12
1
Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<stdio.h>
#include<conio.h>
int main()
{
int num,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(; num>=1; num--)
{
for(c=1; c<=num; c++)
printf("%d",c);
printf("\n");
}
return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5
*********************************/
/*************OUTPUT****************
Enter loop repeat number(rows): 5
12345
1234
123
12
1
*********************************/
Write a program to generate a following numbers triangle:
(Where user entered number through keyboard, for example if num=5)
1
12
123
1234
12345
Ans.
/* c program for number triangle*/
#include<stdio.h>
//#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; r<=num; r++)
for(r=1; r<=num; r++)
{
for(c=1; c<=r; c++)
printf("%d",c);
printf("\n");
}
//getch();
return 0;
//getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
1
12
123
1234
12345
***********************************/
Write a program to generate a following numbers structure:
(Where user entered number through keyboard, for example if num=5)
11111
22222
33333
44444
55555
Ans.
#include<stdio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(c=num; c>=1; c--)
printf("%d",r);
printf("\n");
}
return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5
************************************/
/*************OUTPUT****************
Enter loop repeat number(rows): 5
11111
22222
33333
44444
55555
************************************/
Write a program to generate a following numbers structure:
(Where user entered number through keyboard, for example if num=5)
55555
44444
33333
22222
11111
Ans.
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=num; r>=1; r--)
for(r=num; r>=1; r--)
{
for(c=num; c>=1; c--)
printf("%d",r);
printf("\n");
}
getch();
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
55555
44444
33333
22222
11111
***********************************/
Write a program to generate a following numbers structure:
(Where user entered number through keyboard, for example if num=5)
54321
54321
54321
54321
54321
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(c=5; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
54321
54321
54321
54321
54321
***********************************/
Write a program to generate a following numbers structure:
Where user entered number through keyboard, for example if num=5)
12345
12345
12345
12345
12345
Ans.
/* c program for number rectangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(c=1; c<=num; c++)
printf("%d",c);
printf("\n");
}
getch();
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
12345
12345
12345
12345
12345
***********************************/
Write a program to generate a following @'s triangle?
@ | ||||
@ | @ | |||
@ | @ | @ | ||
@ | @ | @ | @ | |
@ | @ | @ | @ | @ |
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c,sp;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
for(c=1; c<=r; c++)
printf("@");
printf("\n");
}
getch();
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
@ | ||||
@ | @ | |||
@ | @ | @ | ||
@ | @ | @ | @ | |
@ | @ | @ | @ | @ |
***********************************/
Write a program to generate a following #'s triangle?
# | ||||
# | # | |||
# | # | # | ||
# | # | # | # | |
# | # | # | # | # |
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(c=1; c<=r; c++)
printf("#");
printf("\n");
}
getch();
}
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
# | ||||
# | # | |||
# | # | # | ||
# | # | # | # | |
# | # | # | # | # |
***********************************/
Write a program to generate a following @'s triangle?
@ | @ | @ | @ | @ |
@ | @ | @ | @ | |
@ | @ | @ | ||
@ | @ | |||
@ |
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,c;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(; num>=1; num--)
for(; num>=1; num--)
{
for(c=1; c<=num; c++)
printf("@");
printf("\n");
}
getch();
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
@ | @ | @ | @ | @ |
@ | @ | @ | @ | |
@ | @ | @ | ||
@ | @ | |||
@ |
***********************************/
Write a program to generate a following #'s triangle?
# | # | # | # | # |
# | # | # | # | |
# | # | # | ||
# | # | |||
# |
Ans.
/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r=1,c,sp;
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(; num>=1; num--,r++)
for(; num>=1; num--,r++)
{
for(sp=r; sp>1; sp--)
for(sp=r; sp>1; sp--)
printf(" ");
for(c=1; c<=num; c++)
printf("#");
printf("\n");
}
getch();
getch();
return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5
#####
####
###
##
#
***********************************/
/*************OUTPUT**************
Enter loop repeat number(rows): 5
#####
####
###
##
#
***********************************/
Write a program to generate a following structure?
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
Ans.
/* c program for symbol structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num,r,c;
printf("Enter loop repeat number(rows): ");
printf("Enter loop repeat number(rows): ");
scanf("%d",&num);
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(c=1; c<=num; c++)
printf("@");
printf("\n");
}
getch();
getch();
return 0;
}
/************* OUTPUT **************
Enter loop repeat number(rows): 5
/************* OUTPUT **************
Enter loop repeat number(rows): 5
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
***********************************/
***********************************/
Write a C program that convert any digital number value in worlds.
as:
User entered value: 895484
then output in words as:
Eight Lakh Ninety Five Thousand Four Hundred Eighty Four
Ans.
/*c program that convert any digital number to words*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void checkNumber(int num);
void checkNumber1(int num);
void checkNumber2(int num);
void checkNumber3(int num);
void checkNumber4(int num);
void value1(int num);
void value2(int num);
void value3(int num1,int num2);
int main()
{
int num;
printf("Enter any Number : ");
scanf("%d",&num);
printf("Entered Number is : ");
if(num<=100)
checkNumber1(num);
else if(num>100 && num<1000)
checkNumber2(num);
else if(num>=1000 && num<=100000)
checkNumber3(num);
else if(num>100000 && num<=10000000)
checkNumber4(num);
else
checkNumber(num);
getch();
return 0;
}
void checkNumber(num)
{
printf("Kindly enter the number between 0 to 10000000");
}
void checkNumber1(num)
{
int x,y,z;
if(num>=0 && num<=10)
value1(num);
else if(num>10 && num<20)
{
x=num%10;
value2(x);
}
else if(num>=20 && num<=100)
{
y=num/10;
z=num%10;
value3(y,z);
}
}
void checkNumber2(int num)
{
int x,y,z;
y=num/100;
value1(y);
printf(" Hundred ");
x=num%100;
checkNumber1(x);
}
void checkNumber3(int num)
{
int x,y,z;
if(num==1000)
{
printf(" Thousand ");
exit(0);
}
else if(num==100000)
{
printf("Lakh");
exit(0);
}
else
{
x=num/1000;
checkNumber1(x);
printf(" Thousand ");
z=num%1000;
if(z<=99)
checkNumber1(z);
else
checkNumber2(z);
}
}
void checkNumber4(int num)
{
int x,y;
if(num==10000000)
{
printf("One Crore");
exit(0);
}
x=num/100000;
checkNumber1(x);
printf(" Lakhs ");
y=num%100000;
if(y==0)
exit(0);
else if(y<=99)
checkNumber1(y);
else if(y>99 && y<=999)
checkNumber2(y);
else
checkNumber3(y);
}
void value1(int num)
{
switch(num)
{
case 0: printf("Zero"); break;
case 1: printf("One"); break;
case 2: printf("Two"); break;
case 3: printf("Three"); break;
case 4: printf("Four"); break;
case 5: printf("Five"); break;
case 6: printf("Six"); break;
case 7: printf("Seven"); break;
case 8: printf("Eight"); break;
case 9: printf("Nine"); break;
case 10: printf("Ten"); break;
default: printf("");
}
}
void value2(int num)
{
switch(num)
{
case 1: printf("Eleven"); break;
case 2: printf("Twelve"); break;
case 3: printf("Thirteen"); break;
case 4: printf("Fourteen"); break;
case 5: printf("Fifteen"); break;
case 6: printf("Sixteen"); break;
case 7: printf("Seventeen"); break;
case 8: printf("Eighteen"); break;
case 9: printf("Nineteen"); break;
default: printf("");
}
}
void value3(int num1,int num2)
{
switch(num1)
{
case 2: printf("Twenty "); break;
case 3: printf("Thirty "); break;
case 4: printf("Forty "); break;
case 5: printf("Fifty "); break;
case 6: printf("Sixty "); break;
case 7: printf("Seventy "); break;
case 8: printf("Eighty "); break;
case 9: printf("Ninety "); break;
case 10: printf("Hundred"); break;
default: printf("");
}
value1(num2);
}
User entered value: 895484
then output in words as:
Eight Lakh Ninety Five Thousand Four Hundred Eighty Four
Ans.
/*c program that convert any digital number to words*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void checkNumber(int num);
void checkNumber1(int num);
void checkNumber2(int num);
void checkNumber3(int num);
void checkNumber4(int num);
void value1(int num);
void value2(int num);
void value3(int num1,int num2);
int main()
{
int num;
printf("Enter any Number : ");
scanf("%d",&num);
printf("Entered Number is : ");
if(num<=100)
checkNumber1(num);
else if(num>100 && num<1000)
checkNumber2(num);
else if(num>=1000 && num<=100000)
checkNumber3(num);
else if(num>100000 && num<=10000000)
checkNumber4(num);
else
checkNumber(num);
getch();
return 0;
}
void checkNumber(num)
{
printf("Kindly enter the number between 0 to 10000000");
}
void checkNumber1(num)
{
int x,y,z;
if(num>=0 && num<=10)
value1(num);
else if(num>10 && num<20)
{
x=num%10;
value2(x);
}
else if(num>=20 && num<=100)
{
y=num/10;
z=num%10;
value3(y,z);
}
}
void checkNumber2(int num)
{
int x,y,z;
y=num/100;
value1(y);
printf(" Hundred ");
x=num%100;
checkNumber1(x);
}
void checkNumber3(int num)
{
int x,y,z;
if(num==1000)
{
printf(" Thousand ");
exit(0);
}
else if(num==100000)
{
printf("Lakh");
exit(0);
}
else
{
x=num/1000;
checkNumber1(x);
printf(" Thousand ");
z=num%1000;
if(z<=99)
checkNumber1(z);
else
checkNumber2(z);
}
}
void checkNumber4(int num)
{
int x,y;
if(num==10000000)
{
printf("One Crore");
exit(0);
}
x=num/100000;
checkNumber1(x);
printf(" Lakhs ");
y=num%100000;
if(y==0)
exit(0);
else if(y<=99)
checkNumber1(y);
else if(y>99 && y<=999)
checkNumber2(y);
else
checkNumber3(y);
}
void value1(int num)
{
switch(num)
{
case 0: printf("Zero"); break;
case 1: printf("One"); break;
case 2: printf("Two"); break;
case 3: printf("Three"); break;
case 4: printf("Four"); break;
case 5: printf("Five"); break;
case 6: printf("Six"); break;
case 7: printf("Seven"); break;
case 8: printf("Eight"); break;
case 9: printf("Nine"); break;
case 10: printf("Ten"); break;
default: printf("");
}
}
void value2(int num)
{
switch(num)
{
case 1: printf("Eleven"); break;
case 2: printf("Twelve"); break;
case 3: printf("Thirteen"); break;
case 4: printf("Fourteen"); break;
case 5: printf("Fifteen"); break;
case 6: printf("Sixteen"); break;
case 7: printf("Seventeen"); break;
case 8: printf("Eighteen"); break;
case 9: printf("Nineteen"); break;
default: printf("");
}
}
void value3(int num1,int num2)
{
switch(num1)
{
case 2: printf("Twenty "); break;
case 3: printf("Thirty "); break;
case 4: printf("Forty "); break;
case 5: printf("Fifty "); break;
case 6: printf("Sixty "); break;
case 7: printf("Seventy "); break;
case 8: printf("Eighty "); break;
case 9: printf("Ninety "); break;
case 10: printf("Hundred"); break;
default: printf("");
}
value1(num2);
}
Subscribe to:
Posts (Atom)