C Programming | Professor Porua https://www.professorporua.squaryum.com Squaryum's Educational Guide Sun, 19 Jan 2025 11:06:28 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.1 https://www.professorporua.squaryum.com/wp-content/uploads/2024/01/cropped-Logo-500-32x32.png C Programming | Professor Porua https://www.professorporua.squaryum.com 32 32 Nested Loop https://www.professorporua.squaryum.com/c-programming/nested-loop/ Thu, 25 Jan 2024 12:20:31 +0000 https://www.professorporua.squaryum.com/?p=419

Design 1:

#
##
###

#

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf(“#”);
}
printf(“\n”);
}
getch();
}

Design 3:

1
00
111
0000
11111

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i,j,a;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
a=i%2;
printf(“%d”,a);
}
printf(“\n”);
}
getch();
}

Design 2:

*****
****
***
**
*

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i,j,a;
for(i=5;i>=1;i–)
{
for(j=1;j<=i;j++)
{
printf(“*”);
}
printf(“\n”);
}
getch();
}

Design 4:

1
10
101
1010
10101

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i,j,a;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
a=j%2;
printf(“%d”,a);
}
printf(“\n”);
}
getch();
}

]]>
For Loop https://www.professorporua.squaryum.com/c-programming/for-loop/ Thu, 25 Jan 2024 12:14:09 +0000 https://www.professorporua.squaryum.com/?p=414

Print “I love dogs” n times.

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

Print even numbers from 1 to n.

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

]]>
While / Do While Loop https://www.professorporua.squaryum.com/c-programming/while-loop/ Thu, 25 Jan 2024 11:38:24 +0000 https://www.professorporua.squaryum.com/?p=402

While Loop

Main concept

while(condition)
{
statement;
}

Do While Loop

Main concept

do
{
statement;
}
while(condition);

AS LONG AS THE CONDITION IS VALID, THE STATEMENT, INSIDE THE WHILE (OR DO WHILE) LOOP, WILL KEEP ON RUNNING, NO MATTER WHAT THE STATEMENT IS

Print even numbers from 1 to 100.

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a=2;
while(a<=100)
{
printf(“%d\t”,a);
a=a+2;
}
getch();
}

Print “THIS IS A TEXT” n times using do while.

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a=1,n;
scanf(“%d”,&n);
do
{
printf(“THIS IS A TEXT\n”);
}
while(a<=n);
getch();
}

\t IS USED FOR 1 TAB

\n IS USED FOR NEW LINE

]]>
If Else https://www.professorporua.squaryum.com/c-programming/if-else/ Thu, 25 Jan 2024 11:32:08 +0000 https://www.professorporua.squaryum.com/?p=398

 Expression

Meaning

a==b

a is equal to b

a!=b

a is not equal to b

a<=b

a is less than equal to b

a>=b

a is greater than equal to b

a<b

a is less than b

a>b

a is greater than b

a%b

remainder of a÷b

a/b

quotient of a÷b

||

or

&&

and

Print wheather a number is even or odd.

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a;
scanf(“%d”,&a);
if (a%2==0)
{
printf(“%d is even”,a);
}
else
{
printf(“%d is odd”,a);
}
getch();
}

Print the greatest number among 3 given numbers.

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a,b,c;
scanf(“%d %d %d”,&a,&b,&c);
if(a>b && a>c)
{
printf(“%d is the greatest”,a);
}
else if(b>a && b>c)
{
printf(“%d is the greatest”,b);
}
else if(c>a && c>b)
{
printf(“%d is the greatest”,c);
}
getch();
}

SCANF IS USED FOR USER INPUT

]]>
Introduction https://www.professorporua.squaryum.com/c-programming/introduction/ Thu, 25 Jan 2024 10:48:27 +0000 https://www.professorporua.squaryum.com/?p=381

Header Files

  • conio.h: CONsole Input Output (getch, clrscr)
  • stdio.h: STanDard Input Output (scanf, printf)
  • math.h: Mathematical functions (pow, sqrt, sin, cos, exp)
  • string.h: Character & string functions (char, strlen, String)

THERE ARE MANY OTHER HEADER FILES IN C
ALL ARE USABLE ACCORDING TO REQUIREMENTS

Print this line: “This is a test.”

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
printf(“This is a test.”);
getch();
}

Print the addition result of 3 & 5.

#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a=3,b=5,c=0;
c=a+b;
printf(c);
getch();
}

PRINTF IS USED FOR SHOWING THE OUTPUT

]]>