在2017年TCS校园安置中,第一轮引入了新模式。从今年起,测试将由四个部分组成,而不是前两个部分。然而,持续时间应保持不变,即90分钟。详情如下:
1. 口试(10分钟): 这应类似于上一年的章节。
2. 定量性的 测试(40分钟): 本节现在只有20个问题。
3. 测试 程序设计语言 熟练程度(20分钟): 本节应包含与基本编程概念(C语言)相关的基于MCQ的问题。
4. 编码 测试(20分钟): 本节要求学生使用内置编译器(在C语言上)实时解决编码问题。
要解决第四部分的问题,你不能使用 “scanf、getc、getch、getchar” 所以要解决这种类型的编码问题。你必须使用来自 命令行参数 .
打印所有命令行参数整数的示例程序
// Program to print all value of // command line argument // once we get the value from command // line we can use them to solve our problem. #include <stdio.h> // this is used to print the result using printf #include <stdlib.h> // this is used for function atoi() for converting string into int // argc tells the number of arguments provided+1 +1 for file.exe // char *argv[] is used to store the command line arguments in the pointer to char array i.e string format int main( int argc, char *argv[]) { // means only one argument exist that is file.exe if (argc == 1) { printf ( "No command line argument exist Please provide them first " ); return 0; } else { int i; // actual arguments starts from index 1 to (argc-1) for (i = 1; i < argc; i++) { int value = atoi (argv[i]); // print value using stdio.h library's printf() function printf ( "%d" , value); } return 0; } } |
输出:
24 50
如果命令行参数为24 50。 下面是这类问题的另一个示例问题。 问题陈述: 编写一个C程序来计算非负整数N的阶乘。数字N的阶乘定义为从1到N的所有整数的乘积。0的阶乘定义为1。N是一个非负整数,将作为第一个命令行参数传递给程序。将输出写入格式化为整数的标准输出,不需要任何其他文本。您可以假设输入整数的输出不会超过可以存储在int类型变量中的最大整数。 例子:
If the argument is 4, the value of N is 4. So, 4 factorial is 1*2*3*4 = 24. Output : 24
#include <stdio.h> // for printf #include <stdlib.h> // for function atoi() for converting string into int // Function to return fact value of n int fact( int n) { if (n == 0) return 1; else { int ans = 1; int i; for (i = 1; i <= n; i++) { ans = ans * i; } return ans; } } // argc tells the number of arguments // provided+1 +1 for file.exe // char *argv[] is used to store the // command line arguments in the string format int main( int argc, char * argv[]) { // means only one argument exist that is file.exe if (argc == 1) { printf ( "No command line argument exist Please provide them first " ); return 0; } else { int i, n, ans; // actual arguments starts from index 1 to (argc-1) for (i = 1; i < argc; i++) { // function of stdlib.h to convert string // into int using atoi() function n = atoi (argv[i]); // since we got the value of n as usual of // input now perform operations // on number which you have required // get ans from function ans = fact(n); // print answer using stdio.h library's printf() function printf ( "%d" , ans); } return 0; } } |
输出:
24 if command line argument is 4.
在这种情况下,考试中要求的课程难度适中,如果你练习大学第一年的C课程大纲,你应该会得到高分。像“圆的面积”、“字符串反转”和“回文”这样的程序都会被询问。
本文由 阿洛克·沙基亚 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。