Categories

## C programming code to list all factors of n

Course Details

Field of Study: Computer Science and Engineering
Course Name: C Programming
Course Description: C programming code to list all factors of n

Code
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf(“Enter the number\n”);
scanf(“%d”,&n);
for(int i=1;i<=n;i++)
{
if(n%i==0)
printf(“%d “,i);
}
getch();
}

Categories

## C programming code to add all numbers divisible by 3 from 1 to 1000

Course Details

Field of Study: Computer Science and Engineering
Course Name: C Programming
Course Description: C programming code to add all numbers divisible by 3 from 1 to 1000

Code
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float sum=0;
for(int i=1;i<=1000;i++)
{
if(i%3==0)
sum=sum+i;
}
printf(“The sum of all numbers divisible by 3 from 1 to 1000 is %.2f.”,sum);
getch();
}

Categories

## C programming code to display the first n even numbers

Course Details

Field of Study: Computer Science and Engineering
Course Name: C Programming
Course Description: C programming code to display the first n even numbers

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf(“Enter the number.\n”);
scanf(“%d”,&n);
for(int i=1;i<=n;i++){
printf(“%d “,2*i);
}
getch();
}

Categories

## C programming code to display the first n odd numbers

Course Details

Field of Study: Computer Science and Engineering
Course Name: C Programming
Course Description: C programming code to display the first n odd numbers

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf(“Enter the number.\n”);
scanf(“%d”,&n);
for(int i=1;i<=n;i++){
printf(“%d “,(2*i)-1);
}
getch();
}

Categories

## C programming code to sum numbers from 1 to n

Course Details

Field of Study: Computer Science and Engineering
Course Name: C Programming
Course Description: C programming code to sum numbers from 1 to n

Algorithm

1. Accept the last number, n
2. Add numbers from 1 to n using for loop

Code
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,sum=0;
printf(“Enter a number.\n”);
scanf(“%d”,&n);
for(int i=1;i<=n;i++){
sum=sum+i;
}
printf(“Sum=%d”,sum);
getch();
}

Categories

## C Programming to display number patterns in right angle

Course Details

Field of Study: Computer Science and Engineering
Course Name: C Programming
Course Description: C Programming to display number patterns in right angle triangle

Code
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf(“Enter the number\n”);
scanf(“%d”,&n);
for(int i=n;i>=1;i–)
{
for(int j=1;j<=i;j++)
{
printf(“%d”,j);
}
printf(“\n”);
}
getch();
}