Language using with: C
- Datatype resource
- BASIC OF VARIABLE & CONSTANT resource
- OPERATOR resource
- TYPECASTING resource
- LIBRARY-FUNCTION resource
- RELATIONAL AND- LOGICAL OPERATORS resource
- IF-ELSE STATEMENT resource
- TYPE-CASTING resource
- POST & PRE-INCREMENT resource
- TERNARY-OPERATOR resource
- PATTERN PRINTING resource Youtube
- BASIC DATATYPES{*char} class
- SWITCH-CONTINUE- GOTO-DO.WHILE class
- ARRAY class:1D class:2D Youtube
- STRING Youtube class:2D
- FUNCTION resource
- RECURSSION class:1 class:2
Try to solve this problem using with Loop:
Code#include<stdio.h>
int main()
{
int a=0, b=1, c, i, n;
scanf("%d", &n);
if(n == 1)
printf("%d", a);
else
printf("%d %d", a, b);
for(i=1; i<=n-2; i++)
{
c = a + b;
printf(" %d", c);
a = b;
b = c;
}
printf("\n");
return 0;
}
Code#include<stdio.h>
int main()
{
int i, n, x, f, j;
scanf("%d", &n);
i = 1;
while(i <= n)
{
f = 0;
x = i;
for(j=2; j<x; j++)
{
if(x%j == 0)
{
f++;
}
}
if(f == 0 && x != 1)
{
printf("%d ", x);
}
i++;
}
return 0;
}
Code#include<stdio.h>
int main()
{
long long int n, i, j, x, fact;
scanf("%lld", &n);
i=1;
while(i<=n)
{
scanf("%lld", &x);
fact = 1;
for(j=1; j<=x; j++)
{
fact *= j;
}
printf("%lld\n", fact);
i++;
}
return 0;
}
Code#include<stdio.h>
int main()
{
int n, r, s=0, x;
scanf("%d", &n);
x = n;
while(x>0)
{
r = x % 10;
s = s*10+r;
x /= 10;
}
if(n == s)
{
printf("%d\n", s);
printf("YES");
}
else
{
printf("%d\n", s);
printf("NO");
}
return 0;
}
Code#include<stdio.h>
int main()
{
int i, n, x, a, b, c=0;
scanf("%d%d", &a, &b);
i=1;
while(i<=a && i<=b)
{
if(a%i==0 && b%i==0)
{
c = i;
}
i++;
}
printf("%d", c);
return 0;
}
---------------------------------------------------------------
Try to solve this proble using with Array:
Code#include<stdio.h>
int main()
{
int n, i, x, r, f, m, j, pos;
int arr[100010];
scanf("%d", &n);
for(i=0; i<=n-1; i++)
{
scanf("%d", &arr[i]);
}
pos=0;
for(i=0; i<=n-1; i++)
{
while(arr[i] <= 10)
{
pos=arr[i];
printf("A[%d] = %d\n", i, arr[i]);
break;
}
}
return 0;
}
Code#include<stdio.h>
int main()
{
int n, i, x, min, pos=0;
int arr[100010];
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%d", &arr[i]);
}
for(i=1; i<=n; i++)
{
if(arr[i] < min)
{
min = arr[i];
pos=i;
}
}
printf("%d %d", min, pos);
return 0;
}
Code#include<stdio.h>
int main()
{
int n, i, x;
int arr[100010];
scanf("%d", &n);
i=1;
while(i<=n)
{
scanf("%d", &arr[i]);
i++;
}
for(i=n; i>=1; i--)
{
printf("%d ", arr[i]);
}
return 0;
}
Code#include<stdio.h>
int main()
{
int n, i, x;
int arr[100010];
scanf("%d", &n);
i=1;
while(i<=n)
{
scanf("%d", &arr[i]);
i++;
}
for(i=n; i>=1; i--)
{
printf("%d ", arr[i]);
}
return 0;
}
Code#include<stdio.h>
int main()
{
int n, i, x, j, a[10001], t, mx;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
for(i=0; i<n; i++)
{
mx=-100001;
for(j=i; j<n; j++)
{
if(a[j] > mx)
{
mx=a[j];
}
printf("%d ", mx);
}
}
printf("\n");
}
return 0;
}
Code#include<stdio.h>
int main()
{
int n, i, j, min, max, temp;
scanf("%d", &n);
int arr[100010];
for(i=1; i<=n; i++)
{
scanf("%d", &arr[i]);
}
min=arr[1], max=arr[1];
for(i=1; i<=n; i++)
{
if(arr[i] < min)
{
min = arr[i];
}
if(arr[i] > max)
{
max = arr[i];
}
}
for(i=1; i<=n; i++)
{
if(arr[i]==min){
printf("%d ", max);
}else if(arr[i]==max){
printf("%d ", min);
}else{
printf("%d ", arr[i]);}
}
return 0;
}
Code#include<stdio.h>
int main()
{
int n, i, j, a[101][101], b[101][101], p, r, c, f;
scanf("%d%d", &r, &c);
for(i=1; i<=r; i++)
for(j=1; j<=c; j++)
scanf("%d", &a[i][j]);
f=0;
scanf("%d", &p);
for(i=1; i<=r; i++)
{
for(j=1; j<=c; j++)
{
if(a[i][j] == p)
{
f=1;
//break;
}
}
}
if(f==1)
{
printf("will not take number");
}
else
{
printf("will take number");
}
return 0;
}
Code#include<stdio.h>
int main()
{
int arr[100001], i,j,x, m, n, cnt, freq[100001]={0}, val;
scanf("%d%d", &n, &m);
for(i=0; i<n; i++)
{
scanf("%d", &arr[i]);
}
for(i=0; i<n; i++)
{
//arr[i]=10
val=arr[i];
freq[val]++;
}
for(i=1; i<=m; i++)
{
printf("%d\n", freq[i]);
}
return 0;
}
--------------------------------------------------------------------
Try to solve this proble using with String:
Code#include<bits/stdc++.h>
using namespace std;
int main()
{
int i, j, mn;
string x, y;
cin>>x>>y;
if(x < y)
cout<<x;
else
cout<<y;
return 0;
}
Code#include<stdio.h>
#include<string.h>
int main()
{
int i, n, len, x;
scanf("%d", &n);
char a[1000001];
for(i=0; i<n; i++)
{
scanf("%s", a);
x=strlen(a);
if(x <= 10)
{
printf("%s\n", a);
}
else
{
printf("%c%d%c\n", a[0],x-2,a[x-1]);
}
}
return 0;
}
Code#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j,x,t,f;
scanf("%d", &n);
char str[100001];
for(i=0; i<n; i++)
{
scanf("%s",str);
f=0;
for(j=0; j<strlen(str)-2; j++)
{
if(str[j]=='0' && str[j+1]=='1' && str[j+2]=='0' || str[j]=='1' && str[j+1]=='0' && str[j+2]=='1')
{
f=1;
break;
}
}
if(f==1)
printf("Good\n");
else
printf("Bad\n");
}
return 0;
}
Code#include<stdio.h>
#include<string.h>
int main()
{
char str[10000001];
int i, hi[2000]={0};
scanf("%s", str);
for(i=0; str[i]!='\0'; i++)
{
hi[ str[i]]++;
}
for(i = 'a'; i <= 'z'; i++)
{
if(hi[i] > 0)
{
printf("%c : %d\n", i, hi[i]);
}
}
return 0;
}
Code#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
void call()
{
int i,j,k;
char s[100];
char s1[100];
scanf("%s%s", s, s1);
if(strlen(s) < strlen(s1))
{
j = strlen(s);
k = strlen(s1);
}
else
{
j = strlen(s1);
k = strlen(s);
}
for(i=0; i < j; i++)
{
printf("%c", s[i]);
printf("%c", s1[i]);
}
for(i = j; i < k; i++)
{
if(strlen(s) < strlen(s1))
{
printf("%c", s1[i]);
}
else printf("%c", s[i]);
}
}
int main()
{
int t, k;
scanf("%d", &t);
for(k=1; k<=t; k++)
{
call();
printf("\n");;
}
return 0;
}
Code#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j,k,a[10001]={0};
scanf("%d ", &n);
char x;
for(i=0; i<n; i++)
{
scanf("%c", &x);
a[x]+=1;
}
for(i='a'; i<='z'; i++)
{
if(a[i]>0)
{
for(j=1; j<=a[i]; j++)
{
printf("%c", i);
}
}
}
return 0;
}
--------------------------------------------------------------------
Try to solve this proble using with Function:
Code#include<stdio.h>
#include<math.h>
int isprime(int n)
{
int i,f=0,x;
if(n==1)
return 1;
x=sqrt(n);
for(i=2; i<=x; i++)
{
if(n%i==0)
{
f=1;
break;
}
}
return f;
}
int main()
{
int a, x;
scanf("%d", &a);
while(a--)
{
scanf("%d", &x);
if(isprime(x)==1)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
Code#include<stdio.h>
void reverse(int a, int b)
{
int temp=0;
temp=a;
a=b;
b=temp;
printf("%d %d\n", a, b);
}
int main()
{
int a, b, p;
scanf("%d%d", &a, &b);
reverse(a, b);
return 0;
}
Code#include<stdio.h>
int mn(int arr[], int n)
{
int i, y, mn=100001;
for(i=1; i<=n; i++)
{
if(arr[i] < mn)
{
mn=arr[i];
}
}
return mn;
}
int mx(int arr[], int n)
{
int i, x, mx=-1;
for(i=1; i<=n; i++)
{
if(arr[i] > mx)
{
mx=arr[i];
}
}
return mx;
}
int main()
{
int arr[100001], i, MIN, MAX, n, m, j;
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%d", &arr[i]);
}
MIN=mn(arr,n);
MAX=mx(arr,n);
printf("%d %d\n",MIN, MAX);
return 0;
}
Code#include <iostream>
using namespace std;
void change(int arr[], int n, int k, int ans[])
{
for(int i=0; i<n; i++)
{
int tmp = (i+k)%n;
ans[tmp]=arr[i];
}
return;
}
int main()
{
int n, k, i;
cin >> n >> k;
int arr[n], ans[n];
for(i=0; i<n; i++)
cin >> arr[i];
change(arr, n, k, ans);
for(i=0; i<n; i++)
cout << ans[i] << " ";
}
---------------------------------------------------------------
Try to solve this proble using with Recurssion:
Code#include<stdio.h>
int print(int i, int n)
{
if(i>n)
return 0;
print(i+1, n);
if(i==1)
printf("%d", i);
else
printf("%d ", i);
}
int main()
{
int n, i, x;
scanf("%d", &n);
print(1, n);
}
Code#include<stdio.h>
void digit(int x)
{
if(x==0)
return;
digit(x/10);
printf("%d ", x%10);
}
int main()
{
int n, i, x;
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d", &x);
if(x==0)
{
printf("0\n");
}
else
{
digit(x);
printf("\n");
}
}
return 0;
}
Code#include<stdio.h>
void binary(int n)
{
if(n==0)
return;
binary(n/2);
printf("%d", n%2);
}
int main()
{
int n, i, x;
scanf("%d", &n);
while(n--)
{
scanf("%d", &x);
binary(x);
printf("\n");
}
return 0;
}
Code#include<stdio.h>
long long int fact(int n);
int main()
{
int result, n;
scanf("%d", &n);
printf("%lld\n", fact(n));
return 0;
}
long long int fact(int n)
{
if(n==1)
return 1;
else
return n*fact(n-1);
}
Try to solve this proble using with File,Structure:
FILEHANDLING
Part1: https://drive.google.com/file/d/1CruWbmNeGhlfzkotfXkc7q_9ALrOPhkK/view
Part2: https://drive.google.com/file/d/1ctQXf2IVzYLHxy9eD_ICwR_P--EFaAu-/view
Part3: https://drive.google.com/file/d/1NJ-r6u-hQ_5mdfgOvVPNDmgaPo3EEoOY/view
Suppose, you are a software engineer at Google and responsible for creating a basic version of Google Classroom. There could be information of thousands of courses. Each course may contain several students and only one instructor/teacher. For each course, you have to keep a record of its Course Code, Course Name, Section, Instructor’s Name, Number of Enrolled Students and a list of the IDs of the enrolled students. You have to save the information of all the courses in a file named “classDB.txt”. Here is a sample for the “classDB.txt” file. We will refer to this in question 1, 2.
CSE-1121
Computer Programming 1
B
JAA
4
C213050 C213052 C213055 C213063
MATH-1107
Mathematics 1
C
MRI
3
C213091 C213092 C213099
CSE-2311
Data Structure
A
MSA
5
C211001 C211010 C211015 C211021 C211030
CSE-4875
Pattern Recognition and Fuzzy System
A
JAA
0
CSE-1121
Computer Programming 1
C
JAA
3
C213091 C213092 C213099
Following is an explanation for a particular course information. Consider the first one:
CSE-1121
Computer Programming 1
B
JAA
4
C213050 C213052 C213055 C213063
Here the first string “CSE-1121” represents the Course Code of the course.
The second, third and fourth lines represent the Course Name, Section and
Instructor’s Name of the course respectively.
The fifth line contains an integer representing the number of enrolled students that
this particular course has (in this case 4 students have enrolled for CSE-1121,
Section-B). And next line is a list containing the student IDs of the enrolled
students.
If there are no enrolled students then the fifth line should contain 0 and the nextline will be the beginning of another record [See the record of “CSE-4875”, forexample].
Now build a system where you will be given information of several courses. You have tosave information of all the courses in a file named “classDB.txt”.
1. a) Create a structure called Course which will contain necessary fields to hold theinformation of a particular Course. Use an array of type of this structure to solve theproblems in questions 1-b and 1-c.
b) Show Course Code, Course Name, Section and Number of Enrolled Students of all courses taken by a particular teacher.
Suppose you are given “JAA” as input. Considering the file “classDB.txt”, the following should be the output:
Code: CSE-1121
Name: Computer Programming 1
Section: B
Number of Students: 4
Code: CSE-4875
Name: Pattern Recognition and Fuzzy System
Section: A
Number of Students: 0
Code: CSE-1121
Name: Computer Programming
Section: C
Number of Students: 3
c) Add information of a new course to the “classDB.txt” file. Make a function named
addInfo() to do so. If the “classDB.txt” file doesn’t exist on the machine, create
a new file with this name.
This function should take all the necessary inputs i.e. Course Code, Course Name,
Section, Instructor’s Name from the keyboard. Initially the Number of Enrolled
Students should be 0.
2. a) Suppose you are given the matric ID of a student, a particular Course Code and
Section as input. Now add this student to this particular course i.e. the matric ID
should now appear on the enrolled student ID list of this course and the total
number of enrolled students should increase by 1.
For the following input “C213070 CSE-1121 B”, the first course info in the
“classDB.txt” file should change into:
CSE-1121
Computer Programming 1
B
JAA
5
C213050 C213052 C213055 C213063 C213070
b) Delete information of all the courses that has no students enrolled yet.
Considering the “classDB.txt” file only the information of the course CSE-4875
will be deleted in this case.
**POINTER**
Agenda: 1.Pointer and its basics 2. Benefits of pointer — swap function and using & in scanf function 3. Pointer Arithmetic 4. Arrays are pointers!! (But less powerful.
*pointer with address check:
Explaination: •(int *p) is a pointer, where (&c) is located it. •(*p /*p==p[0] /p[0]) both of them denote is simillar. •[+]symbol denoted backward address; [-]>>frontward. •int pointer allocated -4 byte of memory, char=1 byte,double=8byte.
*Array is one of pointer.
*String is one kind of char Array. So, its deserves a address hold. So that, we write: (“%s”, str) …no necessary write: &str! *We know, str cnt in [0]-index. If we need [1] index to it starting than write this approach: (str+1)=[1-index]. *(&str[1])..hcce atr alternative notation! *Normal array has less power as a pointer! If array we don’t directly exchange one var it for others. But, pointer is it plus point!
**BITWISE OPERATOR**
https://www.tutorialspoint.com/cprogramming/c_bitwise_operators.htm
*Binary Operator work with around of two-operand:
AND(&)---If both of them Var is 1, than write=’1’ else =’0’
OR(||) ---If both of them Var has One value is 1, than write=’1’ else =’0’
XOR(^) ---If both of them is similar than write=’0’ else =’1’
*Unary operator work with 1 var. Ex: (~a,2022-01-15)
NOT(~) ---If both of them is similar than write=’0’ else =’1’