//Program to print multiplication table using while loop.
#include<stdio.h>
int main()
{ int i=1,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(i<=10)
{
printf("%d x %d = %d\n",n,i,n*i);
i++;
}
return 0;
}
//#while_loop
#include<stdio.h>
int main()
{ int i=1,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(i<=10)
{
printf("%d x %d = %d\n",n,i,n*i);
i++;
}
return 0;
}
//#while_loop
👍1
//Program to print multiplication table in reverse order using while loop.
#include<stdio.h>
int main()
{ int i=10,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(i)
{
printf("%d x %d = %d\n",n,i,n*i);
i--;
}
return 0;
}
//#while_loop
#include<stdio.h>
int main()
{ int i=10,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(i)
{
printf("%d x %d = %d\n",n,i,n*i);
i--;
}
return 0;
}
//#while_loop
👍1
//Program to find factorial of a number using while loop.
#include<stdio.h>
int main()
{ int i=1,fact=1,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf("The factorial of %d is : %d",n,fact);
return 0;
}
//#while_loop
#include<stdio.h>
int main()
{ int i=1,fact=1,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf("The factorial of %d is : %d",n,fact);
return 0;
}
//#while_loop
👍2
//Program to generate fibonacci series using while loop.
#include<stdio.h>
int main()
{ int i=1,n,n1=0,n2=1,nextTerm;
printf("Enter the limit of fibonacci series:");
scanf("%d",&n);
while(i<=n)
{
printf("%d\n",n1);
nextTerm=n1+n2;
n1=n2;
n2=nextTerm;
i++;
}
return 0;
}
//#while_loop
#include<stdio.h>
int main()
{ int i=1,n,n1=0,n2=1,nextTerm;
printf("Enter the limit of fibonacci series:");
scanf("%d",&n);
while(i<=n)
{
printf("%d\n",n1);
nextTerm=n1+n2;
n1=n2;
n2=nextTerm;
i++;
}
return 0;
}
//#while_loop
👍2
// Program to check weather a number is prime or not using while loop.
#include <stdio.h>
int main()
{
int num, i = 2, isPrime = 1;
printf("Enter the number:");
scanf("%d", &num);
if (num <= 1)
{
isPrime = 0;
}
else
{
while (i <= num / 2)
{
if (num % i == 0)
{
isPrime = 0;
break;
}
i++;
}
}
if(isPrime==1)
{
printf("%d is a prime number.",num);
}
else{
printf("%d is not a prime number.",num);
}
return 0;
}
//#while_loop
#include <stdio.h>
int main()
{
int num, i = 2, isPrime = 1;
printf("Enter the number:");
scanf("%d", &num);
if (num <= 1)
{
isPrime = 0;
}
else
{
while (i <= num / 2)
{
if (num % i == 0)
{
isPrime = 0;
break;
}
i++;
}
}
if(isPrime==1)
{
printf("%d is a prime number.",num);
}
else{
printf("%d is not a prime number.",num);
}
return 0;
}
//#while_loop
❤1👍1
//function to calculate factorial
#include <stdio.h>
int factorial(int);
int main()
{ int n;
printf("Enter the number you want to factoriate:");
scanf("%d",&n);
printf("Factorial of %d is %d",n,factorial(n));
return 0;
}
int factorial(int n){
if(n==1 || n==0){
return 1;
}
return n*factorial(n-1);
}
//#recursive_function
#include <stdio.h>
int factorial(int);
int main()
{ int n;
printf("Enter the number you want to factoriate:");
scanf("%d",&n);
printf("Factorial of %d is %d",n,factorial(n));
return 0;
}
int factorial(int n){
if(n==1 || n==0){
return 1;
}
return n*factorial(n-1);
}
//#recursive_function
🥰1
//Guessing a number game in c
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{ int number,guess,numguesses=1;
srand(time(0));
number=rand()%100+1;
do
{ printf("Guess a number between 1 to 100:");
scanf("%d",&guess);
if(guess>number){
printf("Your guess is wrong \nPlease enter lower number\n");
}
else if(guess<number){
printf("Your guess is wrong \nPlease enter a greater number\n");
}
else{
printf("Congrats! You have guessed it correct\n");
printf("The number of attempts you've taken to guess the correct number is %d times ",numguesses);
}
numguesses++;
} while (guess!=number);
return 0;
}
#num_guessing_game
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{ int number,guess,numguesses=1;
srand(time(0));
number=rand()%100+1;
do
{ printf("Guess a number between 1 to 100:");
scanf("%d",&guess);
if(guess>number){
printf("Your guess is wrong \nPlease enter lower number\n");
}
else if(guess<number){
printf("Your guess is wrong \nPlease enter a greater number\n");
}
else{
printf("Congrats! You have guessed it correct\n");
printf("The number of attempts you've taken to guess the correct number is %d times ",numguesses);
}
numguesses++;
} while (guess!=number);
return 0;
}
#num_guessing_game
👍2🤯1
//Program for understanding arithmetic operators.
#include<stdio.h>
int main(){
int a=10,b=5;
printf("Addition of a and b:%d\n",a+b);
printf("Subraction of a and b:%d\n",a-b);
printf("Multiplication of a and b:%d\n",a*b);
printf("Division of a and b:%d\n",a/b);
printf("Modulo of a and b:%d",a%b);
return 0;
}
#operators
#include<stdio.h>
int main(){
int a=10,b=5;
printf("Addition of a and b:%d\n",a+b);
printf("Subraction of a and b:%d\n",a-b);
printf("Multiplication of a and b:%d\n",a*b);
printf("Division of a and b:%d\n",a/b);
printf("Modulo of a and b:%d",a%b);
return 0;
}
#operators
👍3
//Program for understanding increment and decrement operators.
//post increment.
#include<stdio.h>
int main(){
int a=10;
int b=a++; //post increment:the actual value of a is first assigned to b and next the value of a will be incremented by 1.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//post increment.
#include<stdio.h>
int main(){
int a=10;
int b=a++; //post increment:the actual value of a is first assigned to b and next the value of a will be incremented by 1.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
👍1
//Program for understanding increment and decrement operators.
//pre increment.
#include<stdio.h>
int main(){
int a=10;
int b=++a; //pre increment:the actual value of a is first incremented by 1 and assigned to b.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//pre increment.
#include<stdio.h>
int main(){
int a=10;
int b=++a; //pre increment:the actual value of a is first incremented by 1 and assigned to b.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//Program for understanding increment and decrement operators.
//post decrement.
#include<stdio.h>
int main(){
int a=10;
int b=a--; //post decrement:the actual value of a is first assigned to b and then the value of a is decremented by 1.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//post decrement.
#include<stdio.h>
int main(){
int a=10;
int b=a--; //post decrement:the actual value of a is first assigned to b and then the value of a is decremented by 1.
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//Program for understanding increment and decrement operators.
//pre decrement.
#include<stdio.h>
int main(){
int a=10;
int b=--a; //pre decrement:the actual value of a is first decremented by 1 and assigned to b .
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
//pre decrement.
#include<stdio.h>
int main(){
int a=10;
int b=--a; //pre decrement:the actual value of a is first decremented by 1 and assigned to b .
printf("The value of a:%d and b: %d",a,b);
return 0;
}
#operators
❤3
//Program for understanding assignment operators.
#include<stdio.h>
int main(){
int a=10; //a is assigned with a value 10
printf("a:%d\n",a);
a+=4; // a=a+6
printf("a:%d\n",a);
a-=3; //a=a-3
printf("a:%d\n",a);
a*=2; //a=a*2
printf("a:%d\n",a);
a/=11; //a=a/11
printf("a:%d\n",a);
a%=2; //a=a%2
printf("a:%d\n",a);
return 0;
}
#operators
#include<stdio.h>
int main(){
int a=10; //a is assigned with a value 10
printf("a:%d\n",a);
a+=4; // a=a+6
printf("a:%d\n",a);
a-=3; //a=a-3
printf("a:%d\n",a);
a*=2; //a=a*2
printf("a:%d\n",a);
a/=11; //a=a/11
printf("a:%d\n",a);
a%=2; //a=a%2
printf("a:%d\n",a);
return 0;
}
#operators
👍1
//Program for understanding relational operators.
#include<stdio.h>
int main(){
int a=10,b=9;
printf("a==b:%d\n",a==b); // 0:False
printf("a!=b:%d\n",a!=b); // 1:True
printf("a>b:%d\n",a>b); // 1:True
printf("a<b:%d\n",a<b); //0:False
printf("a>=b:%d\n",a>=b); //1:True
printf("a<=b:%d",a<=b); //0:False
return 0;
}
#operators
#include<stdio.h>
int main(){
int a=10,b=9;
printf("a==b:%d\n",a==b); // 0:False
printf("a!=b:%d\n",a!=b); // 1:True
printf("a>b:%d\n",a>b); // 1:True
printf("a<b:%d\n",a<b); //0:False
printf("a>=b:%d\n",a>=b); //1:True
printf("a<=b:%d",a<=b); //0:False
return 0;
}
#operators
👍2
//Program for understanding logical operators.
#include<stdio.h>
int main(){
int a=6,b=3;
printf("a==6 && a>b :%d\n",a==6 && a>b); //In case of and(&&) the result is True(1),if and only if both conditions gets evaluated to True(1).
printf("a>b b>a:%d\n",a>b b>a); //In case of or||( ) The result is True,if any one condition is True(1) no matter about second condition.
printf("!a:%d",!a); //If the value of a is True(1) then the not(!) operator evaluate the value to False(0) and vice versa.
return 0;
} //give or operator(||) in program its not getting printed in telegram message
#operators
#include<stdio.h>
int main(){
int a=6,b=3;
printf("a==6 && a>b :%d\n",a==6 && a>b); //In case of and(&&) the result is True(1),if and only if both conditions gets evaluated to True(1).
printf("a>b
printf("!a:%d",!a); //If the value of a is True(1) then the not(!) operator evaluate the value to False(0) and vice versa.
return 0;
} //give or operator(||) in program its not getting printed in telegram message
#operators
👍2
//Program for understanding bitwise operators.
#include<stdio.h>
int main(){
int a=3,b=1;
printf("a&b=%d\n",a&b); //Bitwise and(&) //0011 :3
//0001 :1
//-------if we perforn and on above two values
//0001 :1 ,Result will be 1.
printf("a|b :%d\n",a|b); //Bitwise or(|) //0011:3
//0001:1
//-------if we perform or on above two values
//0011:3 ,Result will be 3.
printf("a>>b:%d\n",a>>b); //right shift(>>) // 3>>1
// 0011:3
// 0001:1(after shifting to right)
printf("a<<b:%d",a<<b); //left shift(<<) //3<<1
//0011:3
//0110:6(after shifting to left)
return 0;
}
//#operators
#include<stdio.h>
int main(){
int a=3,b=1;
printf("a&b=%d\n",a&b); //Bitwise and(&) //0011 :3
//0001 :1
//-------if we perforn and on above two values
//0001 :1 ,Result will be 1.
printf("a|b :%d\n",a|b); //Bitwise or(|) //0011:3
//0001:1
//-------if we perform or on above two values
//0011:3 ,Result will be 3.
printf("a>>b:%d\n",a>>b); //right shift(>>) // 3>>1
// 0011:3
// 0001:1(after shifting to right)
printf("a<<b:%d",a<<b); //left shift(<<) //3<<1
//0011:3
//0110:6(after shifting to left)
return 0;
}
//#operators
//Program for size of operator.
#include<stdio.h>
int main(){
int a=6;
printf("size of a:%d",sizeof(a));
return 0;
}
//#operators
#include<stdio.h>
int main(){
int a=6;
printf("size of a:%d",sizeof(a));
return 0;
}
//#operators
//Program to read elements of array and print them.
#include <stdio.h>
int main() {
int a[5],i;
for(i=0;i<5;i++) //for loop for reading elements of array
{
printf("Enter the element at %d index:",i);
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
printf("\nThe element at %d index is :%d",i,a[i]); //for loop for printing elements of array
}
return 0;
}
//#array
#include <stdio.h>
int main() {
int a[5],i;
for(i=0;i<5;i++) //for loop for reading elements of array
{
printf("Enter the element at %d index:",i);
scanf("%d",&a[i]);
}
for(i=0;i<5;i++)
{
printf("\nThe element at %d index is :%d",i,a[i]); //for loop for printing elements of array
}
return 0;
}
//#array
👍7
//Program to read marks of 5 subjects and calculate total marks and average.
#include <stdio.h>
int main() {
float marks[5],sum=0.0;
float avg;
for(int i=0;i<5;i++)
{ printf("Enter marks in Subject %d:",i+1);
scanf("%f",&marks[i]);
sum=sum+marks[i];
}
avg=sum/5;
printf("Total marks obtained:%.2f\n",sum);
printf("Average:%f",avg);
return 0;
}
//#array
#include <stdio.h>
int main() {
float marks[5],sum=0.0;
float avg;
for(int i=0;i<5;i++)
{ printf("Enter marks in Subject %d:",i+1);
scanf("%f",&marks[i]);
sum=sum+marks[i];
}
avg=sum/5;
printf("Total marks obtained:%.2f\n",sum);
printf("Average:%f",avg);
return 0;
}
//#array
👍3