0% found this document useful (0 votes)
22 views3 pages

Write A C Program To Convert Decimal To Octal Number System

The document contains C program code snippets to convert decimal numbers to octal and hexadecimal number systems. It also contains code to print out different patterns, including triangles with numbers or asterisks where the number of elements increases each row. The programs take a decimal number as input, convert it to the specified number system, and print out the result.

Uploaded by

F J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Write A C Program To Convert Decimal To Octal Number System

The document contains C program code snippets to convert decimal numbers to octal and hexadecimal number systems. It also contains code to print out different patterns, including triangles with numbers or asterisks where the number of elements increases each row. The programs take a decimal number as input, convert it to the specified number system, and print out the result.

Uploaded by

F J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

5. Write a C program to convert Decimal to octal number system.

#include <stdio.h>
int fun(int n){
int a[20]; int i;
i=0;
while(n>0){
a[++i]=n%8;
n=n/8;
}
int j;
for(j=i; j>=1; j--){
printf("%d", a[j]);
}
return 0;
}
int main(){
int x;
printf("Enter number of N:");
scanf("%d",&x);
fun(x);
return 0;
}

6. Write a C program to convert Decimal to hexadecimal number system.

#include <stdlib.h>

int fun(int n){


int a[20]; int i;
i=0;
while(n>0){
a[++i]=n%16;
n=n/16;
}
int j;
for(j=i; j>=1; j--){
printf("%d", a[j]);
}
return 0;
}
int main(){
int x;
printf("Enter number of N:");
scanf("%d",&x);
fun(x);
return 0;
}
7.1. Write a C program to print the given patterns.
Shape 01:
#include <stdlib.h>

int fun(int n){


int a[20]; int j; int i;
i=0;
for(i=1; i<=n; i++){
for (j=1; j<=i; j++){
printf("%d", i);
}
printf("\n");
}
return 0;
}
int main(){
int x;
printf("Enter the number of N:");
scanf("%d",&x);
fun(x);
return 0;
}

7.2 Shape 02:

#include <stdlib.h>

int fun(int n){


int j; int i;
for(i=1; i<=n; i++){
for (j=1; j<=i; j++){
printf(" * ", i);
}
printf("\n");
}
return 0;
}
int main(){
int x;
printf("Enter the number of N:");
scanf("%d",&x);
fun(x);
return 0;
}
7.3 Shape -3

#include <stdio.h>
#include <stdlib.h>

int fun(int n){


int j; int i;
for(i=1; i<=n; i++){
for (j=i; j<=n; j++){
printf(" * ", j/2);
}
printf("\n");
}
return 0;
}
int main(){
int x;
printf("Enter the number of N:");
scanf("%d",&x);
fun(x);
return 0;
}

You might also like