This site works best with JavaScript enabled
Sign In
Discussions
Activity
Sign In
All
001 C Programming, Data Structures
Issues, queries and suggestions related to C, C programming, data structures using C and C based projects.
001 C Programming, Data Structures
08.Control Structures. Loops and Iterations
spatlou
January 2021
.
deepak4u106
January 2021
How to find factors of a number.
#include<stdio.h>
int main(){
int num, i;
printf("Enter the number to find its factors\n");
scanf("%d", &num);
for(i = 1; i < num; ++i){
if(num % i == 0)
printf("%d, ",i);
}
printf("%d", num);
printf("\n");
}
Take base and power from user and calculate the power of that number.
#include<stdio.h>
#include<math.h>
int main(){
int base,power;
int res;
printf("Enter the base\n");
scanf("%d", & base);
printf("Enter the power\n");
scanf("%d", & power);
res = pow(base,power);
printf("%d^%d = %d\n", base,power,res);
}
Find reverse of a number
#include<stdio.h>
int main(){
long long num;
int temp;
int sum = 0;
printf("Enter the number to reverse it\n");
scanf("%lld", &num);
while(num > 0){
temp = num % 10;
sum = (sum * 10) + temp;
num = num / 10;
}
printf("%d\n", sum);
return 0;
}
deepak4u106
January 2021
Calculate Armstrong number.
#include<stdio.h>
#include<math.h>
int main(){
int num,arm,tnum,i,temp,p,temp1;
int sCube = 0;
printf("Insert the number\n");
scanf("%d", &num);
printf("Insert the power\n");
scanf("%d", &p);
temp1 = num;
while(num > 0){
temp = num % 10;
sCube = sCube + pow(temp,p);
num = num / 10;
}
if(sCube == temp1){
printf("This is Armstrong number\n");
}
else {
printf("This is not arm strong number\n");
}
}
Find Fibonacci number.
#include<stdio.h>
int main(){
int n,i;
int n1 = 0;
int n2 = 1;
int nt;
int fib = 0;
printf("Enter the number to get Fibonacci numbers\n");
scanf("%d", &n);
printf("The Fibonacci number of %d are:\n", n);
for(i = 0; i <= n; ++i){
printf("%d\n",n1);
nt = n1 + n2;
n1 = n2;
n2 = nt;
}
return 0;
}
Right side triangle.
#include<stdio.h>
int main(){
int i, nrows,rows,col;
printf("Enter the number of rows\n");
scanf("%d", &nrows);
for(i = 1; i <= (nrows); ++i){
for(rows = (nrows-i); rows >= 0 ;--rows){
printf(" ");
}
for(col = 1; col < i+1; ++col){
printf("*");
}
printf("\n");
}
}
deepak4u106
January 2021
Count the number in digit.
#include<stdio.h>
int main(){
long long n;
int i, lastD;
int count = 1;
printf("Enter the digit to find the count\n");
scanf("%lld", &n);
while(n > 10){
n = n / 10;
count++;
}
printf("The total number in digits is: %d\n", count);
return 0;
}
Calculate HCF (HIghest common factor)
#include<stdio.h>
int main(){
int hcf,n1,n2,temp;
int count = 0;
printf("Enter first number\n");
scanf("%d",&n1);
printf("Enter second number\n");
scanf("%d",&n2);
temp = n1>n2?n1:n2;
for(hcf = temp; hcf >= 1; --hcf ){
if(n1 % hcf == 0 && n2 % hcf == 0)
break;
}
printf("%d\n", hcf);
}
Calculate LCM (LEAST COMMON MULTIPLE)
#include<stdio.h>
int main(){
int n1,n2,lcm;
int count = 0;
printf("Enter the first number\n");
scanf("%d", &n1);
printf("Enter the second number\n");
scanf("%d", &n2);
for(lcm = 1; lcm <= (n1 * n2); ++lcm){
if(lcm % n1 == 0 && lcm % n2 ==0){
count++;
if(count == 1){
printf("%d\n", lcm);
}
}
}
}
deepak4u106
January 2021
Check if the given number is prime or not.
#include<stdio.h>
int main(){
int num,i;
int count = 0;
printf("Enter the number to check prime or not\n");
scanf("%d", &num);
for(i = 1; i <= num; ++i){
if(num % i == 0){
count++;
}
}
if(count == 2){
printf("Prime number\n");
}
else{
printf("Not a prime number\n");
}
}
Side ways triangle.
#include<stdio.h>
int main(){
int nrows,rows,col,i;
printf("Enter the number of rows\n");
scanf("%d", &nrows);
for(i = 1; i <= (nrows/2); ++i){
for(rows = 1; rows <= i;++rows){
printf("*");
}
for(col = (i+1); col <= nrows; ++col){
printf(" ");
}
printf("\n");
}
for(i = ((nrows/2) +1); i >= 1; --i){
for(rows = i; rows >= 1;--rows){
printf("*");
}
printf("\n");
}
}
Display A-Z.
#include<stdio.h>
int main(){
int i;
for(i = 65; i <90; ++i){
printf("%c : ", i);
}
printf("%c\n", i);
return 0;
}
deepak4u106
January 2021
Print all the number in digits.
#include<stdio.h>
int main(){
long long num;
int temp;
printf("Enter the number to find the digits\n");
scanf("%lldd", &num);
while(num > 0){
temp = num % 10;
num = num / 10;
printf("%d\n",temp);
}
}
Sum all the number present in the array.
#include<stdio.h>
#define
SIZE 4
int main(){
int arr[SIZE], n , i, sum;
printf("Enter the values in array\n");
for(i = 0; i < SIZE; ++i){
scanf("%d", &arr[i]);
}
for(i = 0;i < SIZE;++i){
sum = sum + arr[i];
}
printf("The sum of the array is : %d\n",sum );
return 0;
}
Find out factorial of a number.
#include<stdio.h>
int main(){
int n,i;
int fact = 1;
printf("Enter the number to find the factorial\n");
scanf("%d", &n);
for(i = 1; i <=n; ++i){
fact = fact * i;
}
printf("The factorial of %d is %d\n", n,fact);
return 0;
}
deepak4u106
January 2021
Check weather the number is palindrome or not.
#include<stdio.h>
int main(){
long long num;
int temp;
int rev = 0;
printf("Enter the number to check weather it is palindrome or not\n");
scanf("%lld", &num);
while(num > 0){
temp = num % 10;
rev = (rev *10) + temp;
num = num / 10;
}
printf("%d\n", rev);
if(num == rev){
printf("The number is palindrome\n");
}
else{
printf("The number is not palindrome\n");
}
}
Pyramid triangle.
#include<stdio.h>
int main(){
int nrows,spaces,star,i;
printf("Enter the number of rows\n");
scanf("%d", &nrows);
for(i = 1; i <= nrows; ++i){
for(spaces = (nrows-i); spaces >=0; --spaces){
printf(" ");
}
for(star = 1;star <=(2 * i)-1; ++star){
printf("*");
}
for(spaces = (nrows-1); spaces >=0; --spaces){
printf(" ");
}
printf("\n");
}
}
Write a programme to find table of a number.
#include<stdio.h>
int main(){
int n,i;
int table;
int temp = 1;
printf("Enter the base of the table\n");
scanf("%d", &table);
printf("Enter the multiple of table\n");
scanf("%d", &n);
for(i = 1; i <= n; ++i){
temp = table * i;
printf("%d x %d = %d\n", table,i,temp);
}
return 0;
}
deepak4u106
January 2021
Write a programme to find prime number in a range.
#include<stdio.h>
int main(){
int num1,num2,i,j;
printf("Enter intervals\n");
scanf("%d", &num1);
printf("-\n");
scanf("%d", &num2);
for(i = (num1+1); i <= (num2-1); ++i){
for(j = 2; j < i; ++j){
if(i % j == 0){
break;
}
}
if(i == j)
printf("%d\n", i);
}
}
swatiupendra1999
January 2021
#include<stdio.h>
int main()
{
int i,n,sum;
sum=0;
/*sum of natural no.*/
printf("Enter the no\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf("%s:sum of %d natural no is :%d",__func__,n,sum);
return 0;
}
//factorial of a no:
#include<stdio.h>
#include<math.h>
int main()
{
float i;
//factorial of a no
printf("Enter the no\n ");
scanf("%f",&i);
printf("%s:factorial of %f,%d",__func__,floor(i)),i;
return 0;
}
swatiupendra1999
January 2021
#include<stdio.h>
int main()
{
int n,i,terms;
/*multiplication table*/
printf("%s:Enter the value of no and how many terms",__func__);
scanf("%d%d",&n,&terms);
for(i=1;i<=terms;i++)
{
printf("%d*%d=%d\n",n,i,n*i);
}
return 0;
}
#include<stdio.h>
int main()
{
int n,i,terms,sum,f1,f2;
/*fibonacci sequence*/
f1=0;f2=1;
sum=f1+f2;
printf("%s:Enter the value of no terms",__func__);
scanf("%d",&terms);
printf("%s:\n%d\t\n%d\t\n",__func__,f1,f2);
for(i=1;i<terms-1;i++)
{
sum=sum+f1;
printf("%d\t\n",sum);
f1=f2;
f2=sum;
}
return 0;
}
#include<stdio.h>
int main()
{
/*gcd of a no*/
int gcd,n1,n2,i;
printf("Enter the two n1 and n2");
scanf("%d%d",&n1,&n2);
for(i=1;i<=n1&&i<=n2;i++)
{
if(n1%i==0&&n2%i==0)
gcd=i;
}
printf("GCD=%d",gcd);
return 0;}
#include<stdio.h>
int main()
{
char i;
/*Display Characters*/
for(i='A';i<='Z';i++)
{
printf("%c ",i);
}
return 0;
}
#include<stdio.h>
int main()
{
int n,flag;
/*No of digits in integer*/
printf("%s:Enter the value of no ",__func__);
scanf("%d",&n);
while(n%10!=0)
{
flag++;
n=n/10;
}
printf("%d\n",flag);
return 0;
}
swatiupendra1999
January 2021
//rev of a no:
#include<stdio.h>
int main()
{
int n,rev,r;
rev=0;
printf("Enter a no.\n");
scanf("%d",&n);
while(n%10!=0)
{
r=n%10;
rev=rev*10+r;
n=n/10;
}
printf("The reversed no is:%d\n",rev);
return 0;
}
Power of no:
#include<stdio.h>
int main()
{
int n,p,i,j,pro;
pro=1;
printf("Enter a no. and power\n");
scanf("%d%d",&n,&p);
for(i=p;i>0;i--)
{
pro=pro*n;
}
printf("%d",pro);
return 0;
}
Pyramid(height defined )
#include<stdio.h>
int main()
{
int r,c,n,sp;
printf("Enter the no of rows\n ");
scanf("%d",&n);
//n :gives no of rows
//r :tells on which row we r present
//c :denotes coloumn
//sp denotes space
for(r=1;r<=2*n-1;r++)
{
for(sp=1;sp<=2*n-r;sp++)
{
printf(" ");
}
for(c=1;c<=2*r-1;c++)
{
printf(" * ");
}
printf("\n");
}
return 0;
}
swatiupendra1999
January 2021
//factors of a no
int i,n;
printf("Enter the no ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
printf("%d ",i);
}
return 0;
}
#include<stdio.h>
#include<math.h>
int main()
{
/*armstrong*/
long int i,n,sum,temp,temp1;
double r,flag;
long int i1,i2;
printf("Enter the value of interval i1 i2\n");
scanf("%ld%ld",&i1,&i2);
for(i=i1;i<=i2;i++)
{n=i;
sum=0;
flag=0;
temp=n;
temp1=n;
while(temp!=0)
{
flag++;
temp=temp/10;
}
while(temp1!=0)
{
r=temp1%10;
sum=sum+pow(r,flag);
temp1=temp1/10;
}
if(sum==n)
printf("%ld ",n);
}
return 0;
}
//palindrome
#include<stdio.h>
int main()
{
/*palindrome*/
int r;
long int n,temp,rev;
rev=0;
printf("Enter a no.\n");
scanf("%ld",&n);
temp=n;
while(temp!=0)
{
r=temp%10;
rev=rev*10+r;
temp=temp/10;
}
if(n==rev)
{
printf("Entered no is palindrome");
}
else
printf("Entered no is not palindrome");
return 0;
}
#
include<stdio.h>
int main()
{
/*prime no*/
int n,i,j,flag,i1,i2;
printf("Enter the value of interval i1 i2\n");
scanf("%d%d",&i1,&i2);
for(i=i1;i<=i2;i++)
{flag=0;
n=i;
for (j=1;j<=n;j++)
{
if(n%j==0)
flag ++;
}
if(flag==2)
{
printf("%d ",n);
}
}
return 0;
}
swatiupendra1999
January 2021
//20.loop
Pattern.Q 20
#include<stdio.h>
int main()
{
int r,c,n,temp;
printf("Enter the no of rows\n ");
scanf("%d",&n);
temp=n;
for(r=1;r<=2*n-1;r++)
{
printf("%d",r);
if(r<=n)
{
for(c=1;c<=r;c++)
{
printf("* ");
}
printf("\n");
}
else
{
for(c=1;c<temp;c++)
{
printf("* ");
}
temp--;
printf("\n");
}
}
return 0;
}
pattern Q.21.
#include<stdio.h>
int main()
{
int r,c,n,temp;
printf("Enter the no of rows\n ");
scanf("%d",&n);
temp=n;
for(r=1;r<=n;r++)
{
for(c=1;c<=2*temp-1;c++)
{
printf(" ");
}
temp--;
for(c=1;c<=(2*r-1);c++)
{
printf("*");
}
printf("\n");
}
return 0;
}
swatiupendra1999
January 2021
#include<stdio.h>
int main()
{
int n1,n2,i,gcd,lcm;
printf("Enter the n1 and n2 ");
scanf("%d%d",&n1,&n2);
for(i=1;i<=n1&&i<=n2;i++)
{
if(n1%i==0 && n2%i==0)
gcd=i;
}
lcm=(n1*n2)/gcd;
printf("lcm of %d and %d is:%d",n1,n2,gcd);
return 0;
}
//histogram
#include<stdio.h>
#include<ctype.h>
int main()
{
//histogram
int i,j;
char x,f;
for(i=0;i<=255;i++)
{x=i;
printf("%c: %d",x,x);
f=i;
if(isalnum(i)||ispunct(i))
{
for(j=1;j<=f;j++)
{
printf("*");
}
}
printf("\n");
}
return 0;
}
mdaliakbar
August 8
Q digit sum
#include
int main()
{
int remainder=0;
int n=123456;
int sum=0;
while(n! =0)
{
remainder=n%10;
sum=sum+remainder;
n=n/10;
}
printf(" Sum of digit=%d\n", sum) ;
return 0;
}
Add a Comment
Powered by
Vanilla
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
0
000 Linux System Administration
25
001 C Programming, Data Structures
101
» 001.01.Introduction to C
1
» 001.16.Structures
21
002 OOPs using C++ with Eclipse on Linux
23
» 002.06.Streams and File Processing
1
003 Linux System Programming
375
» 003.01.Processes-and-Resources-Utilization
26
» 003.01.91.Interview-Questions-Introductory-Concepts
20
» 003.01.92.Interview-Questions-Introductory-Concepts
5
» 003.02.Process-Management. Introduction
21
» 003.02.91.Interview Questions. Intro-to-Processes
20
» 003.03.Process-Management - Process Duplication
91
» 003.03.92.Interview-Questions-Process-Duplication
20
» 003.03.93.Interview-Questions-Process-Duplication
20
» 003.03.94.Interview-Questions-Process-Duplication
20
» 003.03.95.Interview-Questions-Process-Duplication
20
» 003.03.96.Interview-Questions-Process-Duplication
10
» 003.04.Process-Management - Process Replacement
67
» 003.04.81.Assignment. Process Replacement
24
» 003.04.91.Interview-Questions-Process-Replacement
20
» 003.04.92.Interview-Questions-Process-Replacement
22
» 003.05.01.Inter-Process-Communication. Pipes
22
» 003.06.Inter Process Communication. FIFOs
21
» 003.07.Signals and Handlers
43
» 003.07.91.Assignment. Signals and Handlers
20
» 003.07.92.Assignment. Signals and Handlers
22
» 003.08.Inter Process Communication Message Queues
1
» 003.09.Inter Process Communication. Shared Memory
1
» 003.10.Synchronization Techniques. Semaphore
21
» 003.11.POSIX-Threads
21
004 Linux Network Programming
34
» 004.01.Introduction to Networks and Configurations
1
» 004.02.Networking Basics
1
» 004.03.Introduction-to-Sockets
21
» 004.04.Linux Network stack
1
» 004.05.Transmission Control Protocol
1
005 Character Device Drivers Development
32
» 005.01.Introduction To Device Drivers
11
006.Project Evolution with GitLab
2
» 01.Introduction To GitLab
1
008 Block Device Driver Development
4
» 008.01.Introduction to Block Device Drivers
1
009 Embedded Linux-ARM. Storage
91
» 009.01.Linux Boot Process
28
» 009.01.14.Linux-Boot-Process
5
» 009.01.15.Introduction to BIOS
0
» 009.01.16.Introduction-to-BIOS-IQs
5
» 009.01.18.Introduction-to-BIOS-IQs
5
» 009.01.20.BIOS CMOS UEFI. IQs
5
» 009.02.Introduction To Embedded Linux
1
» 009.03.01.ARM Processor Architecture
1
» 009.03.02.Programmers Model
1
» 009.04.Boot Loaders
50
» 009.05.Understanding-ARM-Board-Bringup
1
» 009.06-Board Bringup Raspberry Pi
1
» 009.06.Board Bringup. Raspberry Pi4
1
010 Embedded Linux ARM, Configuring and Porting using Storage
0
011 Shell Scripting using Bash
90
» 011.01.Introduction to Shells and Shell Scripts
1
» 011.02.Basics of Shell Scripting - Bash
1
» 011.03.Conditions and Branching
23
» 011.04.Loops and Iterations/
31
» 011.04.81.Assignment. Branching and Looping
10
» 011.05.Reserved-Words-Bullitin-Commands-Command-Line-Parsing
1
» 011.06.Parameters and Variables
1
» 011.07.Structured Scripting. Functions
11
» 011.08.Arrays-Strings-in-bash
11
» 011.09.File Operations and Commands
1
» 011.10.Writing-Manual-Pages
1
» 011.11.Makefile
1
» 011.12.sed-awk
1
012 Linux Kernel Architecture and Internals
3
014. Linux Network Administration
296
» 014.01.Intro to NW and Configurations
220
» 014.01.12.Introduction to Networking
10
» 014.01.14.Packets-IQs
10
» 014.01.16.NetworkLayers
10
» 014.01.18.The Internet Layer
20
» 014.01.20.routes and the kernel routing table
10
» 014.01.22.The Default Gateway
5
» 014.01.24.IPv6 Addresses And Networks
20
» 014.01.26.Basic ICMP And DNS Tools
10
» 014.01.28.The Physical Layer And Ethernet
5
» 014.01.30.Understanding Linux Network Interface
5
» 014.01.32.Intro To Network Interface Configuration
5
» 014.01.34.Boot Activated Network Configuration
5
» 014.01.36.Manual and Boot Activated Nw Config
5
» 014.01.38.Network Configuration Managers
10
» 014.01.40.Resolving Hostnames
19
» 014.01.42.The Transport Layer TCP UDP Services.
10
» 014.01.44.Understanding DHCP
5
» 014.01.46.Automatic IPv6 Network Configuration. IQs
5
» 014.01.48.Configuring Linux as Router
5
» 014.01.50.Private Networks IPv4
5
» 014.01.52.Network Address Translation. IP Masquerading
5
» 014.01.54.Routers And Linux
5
» 014.01.56.Linux Firewall Basics
5
» 014.01.58.Setting Firewall Rules
5
» 014.01.60.Firewall Strategies
10
» 014.01.62.Ethernet-IP-ARP-NDP-IQs
5
» 014.01.64.Wireless Ethernet
5
» 014.02.Network Applications and Services
11
» 014.02.12.Basics of Services
3
» 014.02.14.Introduction to Network Servers
2
» 014.02.16.Network Servers. Secure Shell
5
» 014.06.Network Protocol Telnet
38
» 014.06.12.Introduction-To-Telnet
3
» 014.06.14.General Working. Telnet
5
» 014.06.16.General-Working-Telnet
5
» 014.06.18.Network Virtual Terminal
3
» 014.06.20.More About Telnet
3
» 014.06.22.Installing Telnet on Fedora
5
» 014.06.24.Telnet Commands-Fedora
3
» 014.06.26.Using Telnet in Linux
5
» 014.06.28.Secure telnet with FirewallD. Fedora.
3
» 014.06.30.Using Telnet in Linux
2
» 014.06.DHCP. A network management protocol
26
015 Python with Eclipse on Linux
27
025.Rust Programming
1
101 Advanced Data Structures using C
18
104.Mastering Linux Network Stack
1
» 104.01.Linux Network Stack User-Space
1
105 Parallel Port Device Drivers Development
5
205 Serial Port Device Drivers Development
3
303 Linux System Programming
32
Project 22. Ethernet Network Device Driver Development
0
Query
557
Project.203 Linux System Programming. MySQL
0
Pravjot Sir Classes
161
Events at EmbLogic
2
Project 16: SPI Device Driver Development
2
Project 17: I2C Device Driver Development
0
Project 18: PCI Device Driver Development
0
Project 19: Embedded Linux on ARM Using Network TFTP
0
Project 20: CAN Bus Protocol and Driver Development
0
Project 21: USB Device Drivers Development
0
Embedded Linux
0
ARM Embedded Processor
0
Training
2
Members Area
1
Word From Admin
1